| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
- namespace app\admin\controller\store;
- use app\common\controller\AdminController;
- use app\http\IResponse;
- class Seller extends AdminController
- {
- /**
- * 用户列表
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/3/16 14:39
- *
- * @return \think\response\Json
- * @throws \think\exception\DbException
- */
- public function index()
- {
- $where = [];
- //组合搜索
- !empty(input('name')) && $where[]
- = ['seller_name', 'like', '%' . input('name') . '%'];
- !empty(input('mobile')) && $where[]
- = ['mobile', 'eq', input('mobile')];
- (!empty(input('allow')) || input('allow') == '0') &&
- $where[] = ['is_allow', 'eq', input('allow')];
- // 区域处理
- !empty(input('area')) && $where[]
- = ['area', 'eq', input('area')];
- $seller = model('common/Seller');
- if (input('status') == 'trashed'){
- $seller = $seller->onlyTrashed();
- }else {
- // $seller = $seller->withTrashed();
- (!empty(input('status')) || input('status') == '0' ) &&
- $where[] = ['status', 'eq', input('status')];
- }
- return IResponse::paginate($seller->where($where)->with(['user'])
- ->paginate(input('limit'),false));
- }
- /**
- * 更新数据
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/3/16 14:24
- *
- * @param $id
- * @return \think\response\Json
- */
- public function update($id)
- {
- // 接收数据
- $params = $this->request->param();
- // 查询用户
- $seller = model('common/Seller')->findBy($id);
- // 是否更改状态操作
- if (isset($params['status']) && $params['status'] != '') {
- $valid = $this->validate($params, [
- 'status|配置状态' => 'require|integer'
- ]);
- }else {
- // 数据校验
- $valid = $this->validate($params, [
- 'seller_name|商家名称' => 'require',
- 'address|商家地址' => 'require',
- 'products|主营产品' => 'require',
- 'fd_img|门头照' => 'require',
- 'bi_license|营业执照' => 'require',
- 'contact|联系人' => 'require',
- 'id_card|身份证号码' => 'require',
- 'mobile|联系手机' => 'require',
- ]);
- }
- // 错误返回
- (true !== $valid) && IResponse::failure($valid);
- // 更新用户信息
- $seller->updateBy($id, $params);
- return IResponse::success('更新商家信息成功');
- }
- /**
- * 删除商家
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/3/16 14:22
- *
- * @param $id
- * @return \think\response\Json
- */
- public function delete($id)
- {
- model('common/Seller')->deleteBy($id);
- return IResponse::success([],'删除用户成功');
- }
- /**
- * 商家批量操作
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/3/23 11:38
- *
- * @return mixed
- */
- public function plectron(){
- // 收参数
- $params = $this->request->param();
- foreach (str2arr($params['ids']) as $id){
- $seller = model('common/Seller')->getBy($id);
- if ($this->request->isDelete()){
- $seller->deleteBy($id);
- return IResponse::success([],'删除商家成功');
- }
- $seller->allowField(true)->updateBy($id, $params);
- }
- return IResponse::success([],'操作成功');
- }
- /**
- * 审核商家
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/6/6 13:05
- *
- * @param $id
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function allow($id)
- {
- // 查询数据
- $seller = model('common/Seller')->findBy($id);
- if (!$seller){
- return IResponse::failure('商家不存在!');
- }
- // 用户修改
- model('common/Users')->updateBy($seller['user_id'], [
- 'is_seller' => $seller['status']
- ]);
- return $seller->updateBy($id, ['is_allow' => 2]) ? IResponse::success('审核商家成功!')
- : IResponse::failure('数据异常,请稍后尝试!');
- }
- /**
- * 审核商家
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/6/6 13:05
- *
- * @param $id
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function refuse($id)
- {
- // 查询数据
- $seller = model('common/Seller')->findBy($id);
- if (!$seller){
- return IResponse::failure('商家不存在!');
- }
- // 恢复
- return $seller->updateBy($id, ['is_allow' => 0]) ? IResponse::success('已驳回商家申请!')
- : IResponse::failure('数据异常,请稍后尝试!');
- }
- /**
- * 恢复删除商家
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/6/6 13:05
- *
- * @param $id
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function restore($id)
- {
- // 查询数据
- $seller = model('common/Seller')->onlyTrashed()->find($id);
- if (!$seller){
- return IResponse::failure('商家不存在!');
- }
- // 恢复
- return $seller->restore() ? IResponse::success('恢复商家成功!')
- : IResponse::failure('恢复商家失败!');
- }
- }
|