StoreController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\Store;
  5. use app\model\StoreCate;
  6. use app\model\Category;
  7. use app\model\RegisterField;
  8. use app\model\Operatingcity;
  9. use app\model\Tuanzhang;
  10. use app\model\Users;
  11. class StoreController extends Base
  12. {
  13. function index()
  14. {
  15. $weid = weid();
  16. $page = input('post.page', 1, 'intval');
  17. $ptype = 'store';
  18. $Fielddata = RegisterField::where(['weid' => $weid, 'ptype' => $ptype])->select()->toArray();
  19. if (empty($Fielddata)) {
  20. RegisterField::datainitial($ptype);
  21. }
  22. $query = $this->setSearch();
  23. $res = $query->order('sort asc,id desc')
  24. ->paginate(getpage())
  25. ->toArray();
  26. if (!empty($res['data'])) {
  27. foreach ($res['data'] as &$vo) {
  28. $vo = Store::conversion($vo);
  29. }
  30. }
  31. $data['data'] = $res;
  32. if ($page == 1) {
  33. $data['field_data']['RegisterField'] = RegisterField::getlistViewField($ptype);
  34. }
  35. return $this->json($data);
  36. }
  37. function setSearch()
  38. {
  39. $keyword = trim(input('post.keyword', '', 'serach_in'));
  40. $status = input('post.status', '', 'serach_in');
  41. $path = input('post.path', '', 'serach_in');
  42. $weid = weid();
  43. if ($path == "/store/audit") {
  44. $status = "0";
  45. }
  46. $query = Store::where(['weid' => $weid, 'tzid' => 0]);
  47. if (!empty($this->ocid)) {
  48. $Operatingcitydata = Operatingcity::find($this->ocid);
  49. if ($Operatingcitydata) {
  50. $Operatingcitydata = $Operatingcitydata->toArray();
  51. if (empty($Operatingcitydata['areatype'])) {
  52. $Operatingcitydata['areatype'] = 3;
  53. }
  54. if ($Operatingcitydata['areatype'] == 3) {
  55. $query->where('district_name', $Operatingcitydata['district_name']);
  56. } elseif ($Operatingcitydata['areatype'] == 2) {
  57. $query->where('city_name', $Operatingcitydata['city_name']);
  58. } elseif ($Operatingcitydata['areatype'] == 1) {
  59. $query->where('province_name', $Operatingcitydata['province_name']);
  60. }
  61. }
  62. }
  63. if (!empty($this->tzid)) {
  64. $Tuanzhangdata = Tuanzhang::find($this->tzid);
  65. if ($Tuanzhangdata) {
  66. $Tuanzhangdata = $Tuanzhangdata->toArray();
  67. $query->where('district_name', $Tuanzhangdata['district_name']);
  68. } else {
  69. $query->where('district_name', '无');
  70. }
  71. }
  72. if (!empty($keyword)) {
  73. $query->where('title|tel', 'like', '%' . $keyword . '%');
  74. }
  75. if (!empty($status) || $status === "0") {
  76. $query->where(['status' => $status]);
  77. }
  78. return $query;
  79. }
  80. function listUpdate()
  81. {
  82. $data = only('id,status');
  83. if (!$data['id']) throw new ValidateException('参数错误');
  84. Store::update($data);
  85. return $this->json(['msg' => '操作成功']);
  86. }
  87. function delete()
  88. {
  89. return $this->del(new Store());
  90. }
  91. //导出
  92. function dumpdata()
  93. {
  94. $page = $this->request->post('page', 1, 'intval');
  95. $ptype = 'store';
  96. $query = $this->setSearch();
  97. $data = RegisterField::dumpdata($query, $ptype, $page);
  98. return $this->json($data);
  99. }
  100. }