OperatingcityController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\Operatingcity;
  5. use app\model\OperatingcityLevel;
  6. use app\model\OperatingcityType;
  7. use app\model\Category;
  8. use app\model\Store;
  9. use app\model\RegisterField;
  10. use app\model\Users;
  11. class OperatingcityController extends Base
  12. {
  13. function index()
  14. {
  15. $weid = weid();
  16. $page = input('post.page', 1, 'intval');
  17. $ptype = 'operatingcity';
  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('id desc')
  24. ->paginate(getpage())
  25. ->toArray();
  26. if (!empty($res['data'])) {
  27. foreach ($res['data'] as &$vo) {
  28. if ($vo['end_time'] == 0) {
  29. $vo['end_time'] = '永久有效';
  30. } else {
  31. $vo['end_time'] = time_format($vo['end_time']);
  32. }
  33. $vo['cate_ids'] = Category::getmultiple($vo['cate_ids']) ?? '无';
  34. $vo['level'] = OperatingcityLevel::getTitle($vo['level']) ?? '初级';
  35. $vo['areatype'] = OperatingcityType::getTitle($vo['areatype']) ?? '未设置';
  36. if (!empty($vo['uuid'])) {
  37. $vo['username'] = Users::getusername($vo['uuid']);
  38. }
  39. $vo['region_name'] = $vo['province_name'] . $vo['city_name'] . $vo['district_name'];
  40. }
  41. }
  42. $data['data'] = $res;
  43. if ($page == 1) {
  44. $data['field_data']['RegisterField'] = RegisterField::getlistViewField($ptype);
  45. }
  46. return $this->json($data);
  47. }
  48. function setSearch()
  49. {
  50. $keyword = trim(input('post.keyword', '', 'serach_in'));
  51. $status = input('post.status', '', 'serach_in');
  52. $path = input('post.path', '', 'serach_in');
  53. $weid = weid();
  54. if ($path == "/operatingcity/audit") {
  55. $status = "0";
  56. }
  57. $query = Operatingcity::where(['weid' => $weid]);
  58. if (!empty($this->ocid)) {
  59. $query->where('id', '<>',$this->ocid);
  60. $Operatingcitydata = Operatingcity::find($this->ocid);
  61. if ($Operatingcitydata) {
  62. $Operatingcitydata = $Operatingcitydata->toArray();
  63. if (empty($Operatingcitydata['areatype'])) {
  64. $Operatingcitydata['areatype'] = 3;
  65. }
  66. if ($Operatingcitydata['areatype'] == 3) {
  67. $query->where('district_name', $Operatingcitydata['district_name']);
  68. } elseif ($Operatingcitydata['areatype'] == 2) {
  69. $query->where('city_name', $Operatingcitydata['city_name']);
  70. } elseif ($Operatingcitydata['areatype'] == 1) {
  71. $query->where('province_name', $Operatingcitydata['province_name']);
  72. }
  73. }
  74. }
  75. if (!empty($keyword)) {
  76. $query->where('title|region_name|province_name|city_name|district_name', 'like', '%' . $keyword . '%');
  77. }
  78. if (!empty($status) || $status === "0") {
  79. $query->where(['status' => $status]);
  80. }
  81. return $query;
  82. }
  83. function listUpdate()
  84. {
  85. $data = only('id,status');
  86. if (!$data['id']) throw new ValidateException('参数错误');
  87. Operatingcity::update($data);
  88. return $this->json(['msg' => '操作成功']);
  89. }
  90. function delete()
  91. {
  92. return $this->del(new Operatingcity());
  93. }
  94. function getcityconfigInfo()
  95. {
  96. if (!empty($this->ocid)) {
  97. $res = Operatingcity::getsettings($this->ocid);
  98. if(empty($res['city_discount_method'])){
  99. $res['city_discount_method'] = 0;
  100. }
  101. return $this->json(['data' => $res]);
  102. }
  103. }
  104. public function cityconfigupdate()
  105. {
  106. if (!empty($this->ocid)) {
  107. $config = $this->request->post();
  108. $configstr = serialize($config);
  109. Operatingcity::update(['settings' => $configstr], ['id' => $this->ocid]);
  110. return $this->json(['msg' => '操作成功']);
  111. }
  112. }
  113. }