Apply.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. namespace app\admin\controller\shopro\store;
  3. use app\common\controller\Backend;
  4. use app\admin\model\shopro\store\Store as StoreModel;
  5. /**
  6. * 门店
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Apply extends Backend
  11. {
  12. /**
  13. * Apply模型对象
  14. * @var \app\admin\model\shopro\store\Apply
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\shopro\store\Apply;
  21. $this->view->assign("openweeksList", $this->model->getOpenweeksList());
  22. $this->view->assign("statusList", $this->model->getStatusList());
  23. }
  24. /**
  25. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  26. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  27. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  28. */
  29. /**
  30. * 查看
  31. */
  32. public function index()
  33. {
  34. //当前是否为关联查询
  35. $this->relationSearch = false;
  36. //设置过滤方法
  37. $this->request->filter(['strip_tags', 'trim']);
  38. if ($this->request->isAjax())
  39. {
  40. //如果发送的来源是Selectpage,则转发到Selectpage
  41. if ($this->request->request('keyField'))
  42. {
  43. return $this->selectpage();
  44. }
  45. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  46. $total = $this->model
  47. ->where($where)
  48. ->order($sort, $order)
  49. ->count();
  50. $list = $this->model
  51. ->with(['user'])
  52. ->where($where)
  53. ->order($sort, $order)
  54. ->limit($offset, $limit)
  55. ->select();
  56. foreach ($list as $row) {
  57. $row->visible(['id','name','user_id','user','images','realname','phone','province_name','city_name','area_name','province_id','city_id','area_id','address','latitude','longitude','openhours','openweeks','apply_num','status','status_msg','createtime','updatetime']);
  58. }
  59. $list = collection($list)->toArray();
  60. $result = array("total" => $total, "rows" => $list);
  61. return $this->success('操作成功', null, $result);
  62. }
  63. return $this->view->fetch();
  64. }
  65. public function detail($ids = null)
  66. {
  67. $row = $this->model->with('user')->where('id', 'in', $ids)->find();
  68. if (!$row) {
  69. $this->error(__('No Results were found'));
  70. }
  71. $adminIds = $this->getDataLimitAdminIds();
  72. if (is_array($adminIds)) {
  73. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  74. $this->error(__('You have no permission'));
  75. }
  76. }
  77. $this->assignconfig("row", $row);
  78. $this->view->assign("row", $row);
  79. return $this->view->fetch();
  80. }
  81. /**
  82. * 审核操作
  83. *
  84. * @param [type] $id
  85. * @return void
  86. */
  87. public function applyOper($id)
  88. {
  89. $status = $this->request->post('status', -1);
  90. $status_msg = $this->request->post('status_msg', '');
  91. $apply = $this->model->get($id);
  92. if ($apply->status != 0) {
  93. $this->error('该申请已处理,不能重复处理');
  94. }
  95. $result = \think\Db::transaction(function () use ($apply, $status, $status_msg) {
  96. $apply->status = $status;
  97. $apply->status_msg = $status_msg;
  98. $apply->save();
  99. if ($status == 1) {
  100. // 把门店申请信息同步到门店
  101. $store = new StoreModel();
  102. $store->name = $apply->name;
  103. $store->images = $apply->images;
  104. $store->realname = $apply->realname;
  105. $store->phone = $apply->phone;
  106. $store->province_name = $apply->province_name;
  107. $store->city_name = $apply->city_name;
  108. $store->area_name = $apply->area_name;
  109. $store->province_id = $apply->province_id;
  110. $store->city_id = $apply->city_id;
  111. $store->area_id = $apply->area_id;
  112. $store->address = $apply->address;
  113. $store->latitude = $apply->latitude;
  114. $store->longitude = $apply->longitude;
  115. $store->service_type = 'radius';
  116. $store->service_radius = 1000;
  117. $store->openhours = $apply->openhours;
  118. $store->openweeks = $apply->openweeks;
  119. $store->status = $apply->status;
  120. $store->save();
  121. // 添加门店管理员
  122. $userStore = \think\Db::name('shopro_user_store')->insert([
  123. 'user_id' => $apply->user_id,
  124. 'store_id' => $store->id
  125. ]);
  126. }
  127. return [
  128. 'apply' => $apply,
  129. 'store' => $store ?? null
  130. ];
  131. });
  132. // 门店审核结果通知
  133. $user = \addons\shopro\model\User::where('id', $result['apply']['user_id'])->find();
  134. $user && $user->notify(
  135. new \addons\shopro\notifications\store\Apply([
  136. 'apply' => $result['apply'],
  137. 'store' => $result['store'],
  138. 'event' => 'store_apply'
  139. ])
  140. );
  141. return $this->success('操作成功', null, $result);
  142. }
  143. }