diff --git a/app/common/model/wholesaler/Apply.php b/app/common/model/wholesaler/Apply.php index 8e00df78..5a0e8582 100644 --- a/app/common/model/wholesaler/Apply.php +++ b/app/common/model/wholesaler/Apply.php @@ -5,6 +5,7 @@ namespace app\common\model\wholesaler; use app\common\enum\WholesalerEnum; use app\common\model\Region as RegionModel; use app\common\model\UploadFile; +use app\common\model\User; use cores\BaseModel; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; @@ -26,6 +27,10 @@ class Apply extends BaseModel return static::get($where, $with); } + public function user(): HasOne + { + return $this->hasOne(User::class, 'user_id', 'user_id'); + } /** * 身份证正面图片 diff --git a/app/store/controller/wholesaler/Apply.php b/app/store/controller/wholesaler/Apply.php new file mode 100644 index 00000000..e0e9d6d1 --- /dev/null +++ b/app/store/controller/wholesaler/Apply.php @@ -0,0 +1,114 @@ +renderSuccess(compact('list')); + } + + /** + * @notes:申请记录 + * @return Json + * @throws DbException + * @author: wanghousheng + */ + public function list(): Json + { + $username = $this->request->post('username'); + $mobile = $this->request->post('mobile'); + $company_name = $this->request->post('company_name'); + $status = intval($this->request->post('status')); + $where = []; + if (!empty($username)) { + $where[] = ['username', 'like', "%$username%"]; + } + if (!empty($company_name)) { + $where[] = ['company_name', 'like', "%$company_name%"]; + } + if (!empty($mobile)) { + $where[] = ['mobile', 'like', "%$mobile%"]; + } + if ($status) { + $where[] = ['status', '=', $status]; + } + $model = new \app\store\model\wholesaler\Apply(); + $list = $model->where($where) + ->with(['user']) + ->order('id', 'desc') + ->paginate(15); + $data['list'] = $list->items(); + $data['total'] = $list->total(); + return $this->renderSuccess($data); + } + + public function detail(): Json + { + $id = intval($this->request->post('id')); + $info = \app\store\model\wholesaler\Apply::detail(['id' => $id], ['cardFrontImg', 'cardBackImg', 'licenseImg', 'doorImg', 'user']); + return $this->renderSuccess(compact('info')); + } + + /** + * @notes:审核 + * @return Json + * @throws Exception + * @author: wanghousheng + */ + public function audit(): Json + { + $id = intval($this->request->post('id')); + if (!$id) { + return $this->renderError('非法请求'); + } + $status = intval($this->request->post('status')); + if (!$status) { + return $this->renderError('非法请求'); + } + $remake = $this->request->post('remake'); + if ($status == WholesalerEnum::REFUSE && !$remake) { + return $this->renderError('驳回原因不能为空'); + } + $info = \app\store\model\wholesaler\Apply::detail(['id' => $id]); + if (empty($info)) { + return $this->renderError('数据异常'); + } + $info = $info->toArray(); + if ($info['status'] != WholesalerEnum::AUDITING) { + return $this->renderError('非法操作'); + } + //更新记录 + $model = new \app\store\model\wholesaler\Apply(); + $model->transaction(function () use ($status, $remake, $info, $model) { + $model->where(['id' => $info['id']])->update(['status' => $status, 'remake' => $remake]); + //通过开通采购商会员 + if ($status == WholesalerEnum::ADOPT) { + $date = new DateTime(date('Y-m-d')); + $date->add(new DateInterval("P{$info['year']}Y")); + $up['effective_time'] = $date->format('Y-m-d'); + $up['user_type'] = UserTypeEnum::MEMBER; + $userModel = new UserModel(); + $userModel->where(['user_id' => $info['user_id']])->save($up); + } + }); + return $this->renderSuccess('操作成功'); + } +} \ No newline at end of file diff --git a/app/store/model/wholesaler/Apply.php b/app/store/model/wholesaler/Apply.php new file mode 100644 index 00000000..58e6c393 --- /dev/null +++ b/app/store/model/wholesaler/Apply.php @@ -0,0 +1,8 @@ +