OperatingcityController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. $vo = Operatingcity::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 == "/operatingcity/audit") {
  44. $status = "0";
  45. }
  46. $query = Operatingcity::where(['weid' => $weid]);
  47. if (!empty($this->ocid)) {
  48. $query->where('id', '<>',$this->ocid);
  49. $Operatingcitydata = Operatingcity::find($this->ocid);
  50. if ($Operatingcitydata) {
  51. $Operatingcitydata = $Operatingcitydata->toArray();
  52. if (empty($Operatingcitydata['areatype'])) {
  53. $Operatingcitydata['areatype'] = 3;
  54. }
  55. if ($Operatingcitydata['areatype'] == 3) {
  56. $query->where('district_name', $Operatingcitydata['district_name']);
  57. } elseif ($Operatingcitydata['areatype'] == 2) {
  58. $query->where('city_name', $Operatingcitydata['city_name']);
  59. } elseif ($Operatingcitydata['areatype'] == 1) {
  60. $query->where('province_name', $Operatingcitydata['province_name']);
  61. }
  62. }
  63. }
  64. if (!empty($keyword)) {
  65. $query->where('title|region_name|province_name|city_name|district_name', 'like', '%' . $keyword . '%');
  66. }
  67. if (!empty($status) || $status === "0") {
  68. $query->where(['status' => $status]);
  69. }
  70. return $query;
  71. }
  72. function listUpdate()
  73. {
  74. $data = only('id,status');
  75. if (!$data['id']) throw new ValidateException('参数错误');
  76. Operatingcity::update($data);
  77. return $this->json(['msg' => '操作成功']);
  78. }
  79. function delete()
  80. {
  81. return $this->del(new Operatingcity());
  82. }
  83. function getcityconfigInfo()
  84. {
  85. if (!empty($this->ocid)) {
  86. $res = Operatingcity::getsettings($this->ocid);
  87. if(empty($res['city_discount_method'])){
  88. $res['city_discount_method'] = 0;
  89. }
  90. return $this->json(['data' => $res]);
  91. }
  92. }
  93. public function cityconfigupdate()
  94. {
  95. if (!empty($this->ocid)) {
  96. $config = $this->request->post();
  97. $configstr = serialize($config);
  98. Operatingcity::update(['settings' => $configstr], ['id' => $this->ocid]);
  99. return $this->json(['msg' => '操作成功']);
  100. }
  101. }
  102. }