Seller.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. namespace app\admin\controller\store;
  3. use app\common\controller\AdminController;
  4. use app\http\IResponse;
  5. class Seller extends AdminController
  6. {
  7. /**
  8. * 用户列表
  9. *
  10. * @author 许祖兴 < zuxing.xu@lettered.cn>
  11. * @date 2020/3/16 14:39
  12. *
  13. * @return \think\response\Json
  14. * @throws \think\exception\DbException
  15. */
  16. public function index()
  17. {
  18. $where = [];
  19. //组合搜索
  20. !empty(input('name')) && $where[]
  21. = ['seller_name', 'like', '%' . input('name') . '%'];
  22. !empty(input('mobile')) && $where[]
  23. = ['mobile', 'eq', input('mobile')];
  24. (!empty(input('allow')) || input('allow') == '0') &&
  25. $where[] = ['is_allow', 'eq', input('allow')];
  26. // 区域处理
  27. !empty(input('area')) && $where[]
  28. = ['area', 'eq', input('area')];
  29. $seller = model('common/Seller');
  30. if (input('status') == 'trashed'){
  31. $seller = $seller->onlyTrashed();
  32. }else {
  33. // $seller = $seller->withTrashed();
  34. (!empty(input('status')) || input('status') == '0' ) &&
  35. $where[] = ['status', 'eq', input('status')];
  36. }
  37. return IResponse::paginate($seller->where($where)->with(['user'])
  38. ->paginate(input('limit'),false));
  39. }
  40. /**
  41. * 更新数据
  42. *
  43. * @author 许祖兴 < zuxing.xu@lettered.cn>
  44. * @date 2020/3/16 14:24
  45. *
  46. * @param $id
  47. * @return \think\response\Json
  48. */
  49. public function update($id)
  50. {
  51. // 接收数据
  52. $params = $this->request->param();
  53. // 查询用户
  54. $seller = model('common/Seller')->findBy($id);
  55. // 是否更改状态操作
  56. if (isset($params['status']) && $params['status'] != '') {
  57. $valid = $this->validate($params, [
  58. 'status|配置状态' => 'require|integer'
  59. ]);
  60. }else {
  61. // 数据校验
  62. $valid = $this->validate($params, [
  63. 'seller_name|商家名称' => 'require',
  64. 'address|商家地址' => 'require',
  65. 'products|主营产品' => 'require',
  66. 'fd_img|门头照' => 'require',
  67. 'bi_license|营业执照' => 'require',
  68. 'contact|联系人' => 'require',
  69. 'id_card|身份证号码' => 'require',
  70. 'mobile|联系手机' => 'require',
  71. ]);
  72. }
  73. // 错误返回
  74. (true !== $valid) && IResponse::failure($valid);
  75. // 更新用户信息
  76. $seller->updateBy($id, $params);
  77. return IResponse::success('更新商家信息成功');
  78. }
  79. /**
  80. * 删除商家
  81. *
  82. * @author 许祖兴 < zuxing.xu@lettered.cn>
  83. * @date 2020/3/16 14:22
  84. *
  85. * @param $id
  86. * @return \think\response\Json
  87. */
  88. public function delete($id)
  89. {
  90. model('common/Seller')->deleteBy($id);
  91. return IResponse::success([],'删除用户成功');
  92. }
  93. /**
  94. * 商家批量操作
  95. *
  96. * @author 许祖兴 < zuxing.xu@lettered.cn>
  97. * @date 2020/3/23 11:38
  98. *
  99. * @return mixed
  100. */
  101. public function plectron(){
  102. // 收参数
  103. $params = $this->request->param();
  104. foreach (str2arr($params['ids']) as $id){
  105. $seller = model('common/Seller')->getBy($id);
  106. if ($this->request->isDelete()){
  107. $seller->deleteBy($id);
  108. return IResponse::success([],'删除商家成功');
  109. }
  110. $seller->allowField(true)->updateBy($id, $params);
  111. }
  112. return IResponse::success([],'操作成功');
  113. }
  114. /**
  115. * 审核商家
  116. *
  117. * @author 许祖兴 < zuxing.xu@lettered.cn>
  118. * @date 2020/6/6 13:05
  119. *
  120. * @param $id
  121. * @return mixed
  122. * @throws \think\db\exception\DataNotFoundException
  123. * @throws \think\db\exception\ModelNotFoundException
  124. * @throws \think\exception\DbException
  125. */
  126. public function allow($id)
  127. {
  128. // 查询数据
  129. $seller = model('common/Seller')->findBy($id);
  130. if (!$seller){
  131. return IResponse::failure('商家不存在!');
  132. }
  133. // 用户修改
  134. model('common/Users')->updateBy($seller['user_id'], [
  135. 'is_seller' => $seller['status']
  136. ]);
  137. return $seller->updateBy($id, ['is_allow' => 2]) ? IResponse::success('审核商家成功!')
  138. : IResponse::failure('数据异常,请稍后尝试!');
  139. }
  140. /**
  141. * 审核商家
  142. *
  143. * @author 许祖兴 < zuxing.xu@lettered.cn>
  144. * @date 2020/6/6 13:05
  145. *
  146. * @param $id
  147. * @return mixed
  148. * @throws \think\db\exception\DataNotFoundException
  149. * @throws \think\db\exception\ModelNotFoundException
  150. * @throws \think\exception\DbException
  151. */
  152. public function refuse($id)
  153. {
  154. // 查询数据
  155. $seller = model('common/Seller')->findBy($id);
  156. if (!$seller){
  157. return IResponse::failure('商家不存在!');
  158. }
  159. // 恢复
  160. return $seller->updateBy($id, ['is_allow' => 0]) ? IResponse::success('已驳回商家申请!')
  161. : IResponse::failure('数据异常,请稍后尝试!');
  162. }
  163. /**
  164. * 恢复删除商家
  165. *
  166. * @author 许祖兴 < zuxing.xu@lettered.cn>
  167. * @date 2020/6/6 13:05
  168. *
  169. * @param $id
  170. * @return mixed
  171. * @throws \think\db\exception\DataNotFoundException
  172. * @throws \think\db\exception\ModelNotFoundException
  173. * @throws \think\exception\DbException
  174. */
  175. public function restore($id)
  176. {
  177. // 查询数据
  178. $seller = model('common/Seller')->onlyTrashed()->find($id);
  179. if (!$seller){
  180. return IResponse::failure('商家不存在!');
  181. }
  182. // 恢复
  183. return $seller->restore() ? IResponse::success('恢复商家成功!')
  184. : IResponse::failure('恢复商家失败!');
  185. }
  186. }