Merchant.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. namespace app\admin\controller\merchant;
  3. use app\admin\controller\AuthController;
  4. use app\admin\model\user\User;
  5. use app\admin\model\merchant\UserEnter;
  6. use app\merchant\model\merchant\MerchantMenus;
  7. use service\HookService;
  8. use service\JsonService;
  9. use service\SystemConfigService;
  10. use service\UploadService;
  11. use think\Request;
  12. use think\Url;
  13. use app\admin\model\merchant\Merchant as MerchantModel;
  14. use app\merchant\model\merchant\MerchantAdmin as MerchantAdminModel;
  15. use app\admin\model\special\Lecturer;
  16. use app\admin\model\special\Special;
  17. use app\admin\model\download\DataDownload as DownloadModel;
  18. use app\admin\model\store\StoreProduct as ProductModel;
  19. use app\admin\model\ump\EventRegistration as EventRegistrationModel;
  20. /**
  21. * Class Merchant
  22. * @package app\admin\controller\merchant
  23. */
  24. class Merchant extends AuthController
  25. {
  26. /**讲师后台列表
  27. * @return mixed
  28. */
  29. public function index()
  30. {
  31. return $this->fetch();
  32. }
  33. /**
  34. * 讲师列表获取
  35. * @return
  36. * */
  37. public function lecturer_merchant_list()
  38. {
  39. $where = parent::getMore([
  40. ['page', 1],
  41. ['limit', 20],
  42. ['title', ''],
  43. ]);
  44. return JsonService::successlayui(MerchantModel::getLecturerMerchantList($where));
  45. }
  46. /**
  47. * 删除讲师后台
  48. * @param int $id 修改的主键
  49. * @return json
  50. * */
  51. public function delete($id = 0)
  52. {
  53. if (!$id) return JsonService::fail('缺少参数');
  54. $merchant = MerchantModel::get($id);
  55. if (!$merchant) return JsonService::fail('讲师后台不存在');
  56. if (MerchantModel::delMerchant($id)) {
  57. Lecturer::where('mer_id', $id)->update(['is_del' => 1]);
  58. User::where('uid', $merchant['uid'])->update(['business' => 0]);
  59. return JsonService::successful('删除成功');
  60. } else
  61. return JsonService::fail(UserEnterModel::getErrorInfo('删除失败'));
  62. }
  63. /**编辑讲师信息
  64. * @param $id
  65. * @return mixed
  66. */
  67. public function edit($id)
  68. {
  69. $role = MerchantModel::get($id);
  70. $this->assign(['title' => '编辑讲师后台', 'roles' => $role->toJson(), 'menus' => json(MerchantMenus::ruleList())->getContent(), 'action' => Url::build('update', array('id' => $id))]);
  71. return $this->fetch('edit');
  72. }
  73. /**
  74. * @param Request $request
  75. * @param $id
  76. * @return \think\response\Json
  77. */
  78. public function update(Request $request, $id)
  79. {
  80. $data = parent::postMore([
  81. 'mer_name',
  82. 'real_name',
  83. 'pwd',
  84. 'mer_phone',
  85. 'mer_address',
  86. 'mer_special_divide',
  87. 'mer_store_divide',
  88. 'mer_event_divide',
  89. 'mer_data_divide',
  90. 'mer_test_divide',
  91. 'gold_divide',
  92. 'mark',
  93. 'is_source',
  94. 'is_audit',
  95. 'status',
  96. ['checked_menus', [], '', 'rules'],
  97. 'uid'
  98. ], $request);
  99. if (!$id) return JsonService::fail('数据错误');
  100. if (!is_array($data['rules']) || !count($data['rules'])) return JsonService::fail('请选择最少一个权限');
  101. foreach ($data['rules'] as &$v) {
  102. $pid = MerchantMenus::where('id', $v)->value('pid');
  103. if (!in_array($pid, $data['rules'])) $data['rules'][] = $pid;
  104. }
  105. $status = $data['status'];
  106. $data['rules'] = implode(',', $data['rules']);
  107. $merchant = MerchantModel::get($id);
  108. if (!$merchant) return JsonService::fail('讲师后台不存在');
  109. if (!$data['mer_name']) return JsonService::fail('请输入讲师后台名称');
  110. MerchantModel::beginTrans();
  111. $res1 = MerchantModel::edit($data, $id);
  112. $update = array();
  113. $update['rules'] = $data['rules'];
  114. $rules = MerchantAdminModel::where('level', 0)->where('mer_id', $id)->value('rules');
  115. if ($update['rules'] == $rules) $res2 = true;
  116. else $res2 = false !== MerchantAdminModel::where('level', 0)->where('mer_id', $id)->update($update);
  117. $res = false;
  118. if ($res1 && $res2) $res = true;
  119. MerchantModel::checkTrans($res);
  120. if ($res) {
  121. if (!$status) {
  122. Special::where(['is_del' => 0, 'mer_id' => $id])->update(['is_show' => 0]);
  123. DownloadModel::where(['is_del' => 0, 'mer_id' => $id])->update(['is_show' => 0]);
  124. ProductModel::where(['is_del' => 0, 'mer_id' => $id])->update(['is_show' => 0]);
  125. EventRegistrationModel::where(['is_del' => 0, 'mer_id' => $id])->update(['is_show' => 0]);
  126. Lecturer::where(['id' => $merchant['lecturer_id']])->update(['is_show' => 0]);
  127. $dat['is_show'] = 0;
  128. Lecturer::edit($dat, $merchant['lecturer_id'], 'id');
  129. } else {
  130. $dat['is_show'] = 1;
  131. Lecturer::edit($dat, $merchant['lecturer_id'], 'id');
  132. }
  133. return JsonService::successful('修改成功!');
  134. } else
  135. return JsonService::fail('修改失败!');
  136. }
  137. /**
  138. * 修改状态
  139. * @param $id
  140. * @return \think\response\Json
  141. */
  142. public function modify($id, $status)
  143. {
  144. if (!$id) return JsonService::fail('数据错误');
  145. $merchantInfo = MerchantModel::where('id', $id)->where('is_del', 0)->find();
  146. if (!$merchantInfo) return JsonService::fail('数据错误');
  147. $data['status'] = $status;
  148. if (!MerchantModel::edit($data, $id)) {
  149. return JsonService::fail(MerchantModel::getErrorInfo('修改失败,请稍候再试!'));
  150. } else {
  151. $dat['is_show'] = $status;
  152. Lecturer::edit($dat, $merchantInfo['lecturer_id'], 'id');
  153. return JsonService::successful('修改成功!');
  154. }
  155. }
  156. /**登录
  157. * @param $id
  158. * @throws \think\Exception
  159. * @throws \think\db\exception\DataNotFoundException
  160. * @throws \think\db\exception\ModelNotFoundException
  161. * @throws \think\exception\DbException
  162. */
  163. public function login($id)
  164. {
  165. $merchantInfo = MerchantModel::where('id', $id)->where('is_del', 0)->find();
  166. if (!$merchantInfo) return $this->failed('登陆的讲师后台不存在!');
  167. $adminInfo = MerchantAdminModel::where('level', 0)->where('mer_id', $merchantInfo->id)->find();
  168. if (!$adminInfo) return $this->failed('登陆的讲师后台不存在!');
  169. MerchantAdminModel::setLoginInfo($adminInfo->toArray());
  170. MerchantAdminModel::setMerchantInfo($merchantInfo->toArray());
  171. return $this->redirect(Url::build('/merchant/index/index'));
  172. }
  173. /**重置密码
  174. * @param $id
  175. */
  176. public function reset_pwd($id)
  177. {
  178. if (!$id) return JsonService::fail('参数错误失败!');
  179. $pwd = md5(1234567);
  180. $adminPwd = MerchantAdminModel::where('mer_id', $id)->where('level', 0)->value('pwd');
  181. if ($pwd == $adminPwd) return JsonService::fail('您的密码无需重置!');
  182. if (MerchantAdminModel::where('mer_id', $id)->where('level', 0)->update(['pwd' => md5(1234567)]))
  183. return JsonService::successful('重置成功!');
  184. else
  185. return JsonService::fail('重置失败!');
  186. }
  187. }