diff --git a/app/common/dao/system/merchant/MerchantIntentionDao.php b/app/common/dao/system/merchant/MerchantIntentionDao.php index 67a4a579..70745666 100644 --- a/app/common/dao/system/merchant/MerchantIntentionDao.php +++ b/app/common/dao/system/merchant/MerchantIntentionDao.php @@ -41,6 +41,8 @@ class MerchantIntentionDao extends BaseDao $query->where('mer_name|phone|mark', 'like', '%' . $where['keyword'] . '%'); })->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) { getModelTime($query, $where['date']); + })->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) { + $query->whereIn('type', $where['type']); })->where('is_del', 0); return $query; diff --git a/app/common/repositories/system/merchant/MerchantIntentionRepository.php b/app/common/repositories/system/merchant/MerchantIntentionRepository.php index f5cfb06f..321e7144 100644 --- a/app/common/repositories/system/merchant/MerchantIntentionRepository.php +++ b/app/common/repositories/system/merchant/MerchantIntentionRepository.php @@ -45,6 +45,18 @@ class MerchantIntentionRepository extends BaseRepository return compact('count', 'list'); } + public function getMoreList(array $where, $page, $limit) + { + $query = $this->dao->search($where); + $count = $query->count(); + $list = $query->page($page, $limit) + ->order('create_time DESC , status ASC')->with(['merchantCategory', 'merchantType']) + ->select(); + return compact('count', 'list'); + } + + + public function detail($id, ?int $uid) { $where = ['mer_intention_id' => $id]; @@ -102,6 +114,40 @@ class MerchantIntentionRepository extends BaseRepository return $form->setTitle('修改审核状态'); } + + + + /** + * 更新身份 + * @param $id + * @param $data + * @return void + * @throws \think\db\exception\DbException + */ + public function updateIdent($id, $data) + { + $wholesale = $data['wholesale']; + $uid = $data['uid']; + unset($data['mer_type_id']); + unset($data['wholesale']); + unset($data['uid']); + + if($wholesale){ + $check = Merchant::getDB()->where('uid', $uid)->value('mer_id');//商户 + if($check){ + Merchant::getDB()->where('mer_id',$check)->update(['wholesale'=>$wholesale]); + }else{ + throw new ValidateException('先成为商户'); + } + + } + + $intention = $this->search(['mer_intention_id' => $id])->find(); + if (!$intention) + throw new ValidateException('信息不存在'); + $intention->save($data); + } + public function updateStatus($id, $data) { $data['create_mer'] = !empty($data['create_mer']) ? $data['create_mer'] : 2; diff --git a/app/controller/admin/system/merchant/MerchantIntention.php b/app/controller/admin/system/merchant/MerchantIntention.php index 9b2109ac..9624f2b8 100644 --- a/app/controller/admin/system/merchant/MerchantIntention.php +++ b/app/controller/admin/system/merchant/MerchantIntention.php @@ -42,6 +42,17 @@ class MerchantIntention extends BaseController return app('json')->success($this->repository->getList($where, $page, $limit)); } + //批发零售列表 + public function list() + { + [$page, $limit] = $this->getPage(); + $where = $this->request->params(['mer_name', 'status', 'date', 'keyword', 'mer_intention_id', 'category_id', 'type_id', 'type']); + $where['type'] = [3,4];//批发零售 + return app('json')->success($this->repository->getMoreList($where, $page, $limit)); + } + + + public function form($id) { if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0])) @@ -75,6 +86,32 @@ class MerchantIntention extends BaseController return app('json')->success('修改成功'); } + + + public function switchIdentity($id) + { + if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0])) + return app('json')->fail('数据不存在'); + $data = $this->request->params(['status','mer_type_id','uid']); + if(empty($data['status']) || empty($data['mer_type_id']) || empty($data['uid']) ) return app('json')->fail('缺失参数'); + $data['wholesale'] = 0; + if($data['status'] == 1){ + if($data['mer_type_id'] == 23){ + //批发 + $data['wholesale'] =1; + }else{ + $data['wholesale'] =2;//零售 + } + } + $this->repository->updateIdent($id, $data); + return app('json')->success('修改身份成功'); + } + + + + + + public function delete($id) { if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0])) diff --git a/app/controller/api/store/merchant/MerchantIntention.php b/app/controller/api/store/merchant/MerchantIntention.php index 3d80d359..244e7b71 100644 --- a/app/controller/api/store/merchant/MerchantIntention.php +++ b/app/controller/api/store/merchant/MerchantIntention.php @@ -308,6 +308,33 @@ class MerchantIntention extends BaseController return app('json')->success($data); } + public function changeIdentity() + { + $data = $this->request->params([ + 'phone', + 'mer_name', + 'mer_type_id', + 'merchant_category_id', + 'type', + 'name' + ]); + + if(empty($data['phone'])||empty($data['mer_name'])||empty($data['mer_type_id'])||empty($data['merchant_category_id'])||empty($data['type'])||empty($data['name'])){ + return app('json')->fail('参数缺失请检查'); + } + + if ($this->userInfo) $data['uid'] = $this->userInfo->uid; + $data['status'] = 0; + $intention = $this->repository->create($data); + if ($intention) { + return app('json')->success('申请更改商户身份成功'); + } else { + return app('json')->fail('申请更改商户身份失败'); + } + } + + + protected function checkParams() { $data = $this->request->params([ diff --git a/route/admin/merchant.php b/route/admin/merchant.php index 5f04e85f..91e9ca35 100644 --- a/route/admin/merchant.php +++ b/route/admin/merchant.php @@ -59,9 +59,19 @@ Route::group(function () { Route::get('lst', '/lst')->name('systemMerchantIntentionLst')->option([ '_alias' => '列表', ]); + Route::get('list', '/list')->name('systemMerchantIntentionList')->option([ + '_alias' => '批发和零售申请列表', + ]); + Route::post('status/:id', '/switchStatus')->name('systemMerchantIntentionStatus')->option([ '_alias' => '审核', ]); + + Route::post('change/:id', '/switchIdentity')->name('systemMerchantIntentionIdent')->option([ + '_alias' => '更改身份', + ]); + + Route::delete('delete/:id', '/delete')->name('systemMerchantIntentionDelete')->option([ '_alias' => '删除', ]); diff --git a/route/api.php b/route/api.php index 786564ec..3c34e37f 100644 --- a/route/api.php +++ b/route/api.php @@ -558,6 +558,8 @@ Route::group('api/', function () { Route::post('intention/create', 'api.store.merchant.MerchantIntention/create'); Route::get('intention/cate', 'api.store.merchant.MerchantIntention/cateLst'); Route::get('intention/type', 'api.store.merchant.MerchantIntention/typeLst'); + + Route::post('intention/change', 'api.store.merchant.MerchantIntention/changeIdentity');//更新身份 //浏览 Route::post('common/visit', 'api.Common/visit'); Route::get('store/product/assist/count', 'api.store.product.StoreProductAssist/userCount');