UserController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020-09-09
  6. * Time: 9:04
  7. */
  8. namespace api\js\controller;
  9. use api\js\model\DistributorLogModel;
  10. use api\js\model\DistributorModel;
  11. use api\js\model\JsModel;
  12. use api\js\model\JsTimeModel;
  13. use api\js\model\UserDiscountModel;
  14. use api\js\model\UserModel;
  15. use api\js\model\UserTxModel;
  16. use cmf\controller\RestUserBaseController;
  17. use think\Db;
  18. use think\Validate;
  19. class UserController extends RestUserBaseController
  20. {
  21. /**
  22. * 注销用户账户
  23. *
  24. * @param [type] $mobile
  25. * @param [type] $product
  26. * @return void
  27. */
  28. public function destroy()
  29. {
  30. $user_id = $this->getUserId();
  31. $info = UserModel::get($user_id);
  32. $res = $info->delete();
  33. $this->success('注销成功', $res);
  34. }
  35. /**
  36. * 用户信息
  37. */
  38. public function getInfo()
  39. {
  40. $user_id = $this->getUserId();
  41. $info = UserModel::get($user_id);
  42. $info->openid = Db::name('third_party_user')->where('user_id', $user_id)->value('openid');
  43. $info->js;
  44. if ($info['user_type'] == 3) {
  45. $info['js']['is_work'] = 0;
  46. if ($info['js']->js_time) {
  47. $week = date('w', time());
  48. if (in_array($week, $info['js']->js_time->weeks)) {
  49. foreach ($info['js']->js_time->times as $vo) {
  50. if (strtotime($vo['js_end_time']) >= strtotime(date('H:i'))) {
  51. //在此处判断一下是否已经接单
  52. $is_work = Db::name('js_order')->where('jiedan_js_id', $info['js']['id'])->where('status', 6)->find();
  53. if (empty($is_work)) {
  54. $info['js']['is_work'] = 1;
  55. } else {
  56. $info['js']['is_work'] = 2;
  57. }
  58. }
  59. }
  60. }
  61. unset($info['js']->js_time);
  62. }
  63. }
  64. $info->is_agency = 0;
  65. if ($info->agency_id) {
  66. $info->is_agency = 1;
  67. $info->agency_id = 1;
  68. } else {
  69. $info->agency_id = 0;
  70. }
  71. $info->distributor_status = DistributorLogModel::where('user_id', $user_id)->value('chuli_status');
  72. $info->fenxiaoshang = DistributorModel::get($info->distributor_id)['name'];
  73. unset($info['user_pass']);
  74. $this->success('ok', $info);
  75. }
  76. /**
  77. * 申请成为技师
  78. */
  79. public function applyJsPost()
  80. {
  81. $user_id = $this->getUserId();
  82. $user_info = UserModel::get($user_id);
  83. $user_type = $user_info['user_type'];
  84. if ($user_type != 3) {
  85. $this->error('请先去师傅端注册!');
  86. }
  87. $data['user_id'] = $user_id;
  88. $data['name'] = $this->request->param('name');
  89. $phone = $this->request->param('phone');
  90. $data['phone'] = $phone ?: $user_info['mobile'];
  91. // if (!$data['phone']) {
  92. // $this->error('请填写联系电话不可为空!');
  93. // }
  94. $data['is_real_time'] = $this->request->param('is_real_time');
  95. $data['is_make'] = $this->request->param('is_make');
  96. $data['jianjie'] = $this->request->param('jianjie');
  97. $data['sex'] = $this->request->param('sex');
  98. $data['apply_num'] = 1;
  99. $data['identity'] = $this->request->param('identity/a');
  100. $data['certificates'] = $this->request->param('certificates/a');
  101. $data['pictures'] = $this->request->param('pictures/a');
  102. $work = $this->request->param('work/a');
  103. if (isset($work)) {
  104. $data['work'] = $work;
  105. }
  106. $JsModel = new JsModel();
  107. // $js_id = $JsModel::where('phone',$data['phone'])->value('id');
  108. // if($js_id){
  109. // $this->error('此号码已认证,请到我的设置中修改信息!');
  110. // }
  111. $info = $JsModel::where('user_id', $user_id)->find();
  112. $JsTimeModel = new JsTimeModel();
  113. if ($info) {
  114. $js_time['js_id'] = $info['id'];
  115. $js_time_info = Db::name('js_time')->where('js_id', $js_time['js_id'])->find();
  116. if (!$js_time_info) {
  117. $js_time['times'] = [0 => ['js_start_time' => '00:00', 'js_end_time' => '23:59']];
  118. $js_time['weeks'] = ['1', '2', '3', '4', '5', '6', '0'];
  119. $JsTimeModel->allowField(true)->isUpdate(false)->save($js_time);
  120. }
  121. $data['js_status'] = 0;
  122. $JsModel->allowField(true)->isUpdate(true)->save($data, ['id' => $info['id']]);
  123. $this->success('修改成功');
  124. } else {
  125. $JsModel->applyJsPost($data);
  126. $js_time['js_id'] = $JsModel->id;
  127. $js_time_info = Db::name('js_time')->where('js_id', $js_time['js_id'])->find();
  128. if (!$js_time_info) {
  129. $js_time['times'] = [0 => ['js_start_time' => '00:00', 'js_end_time' => '23:59']];
  130. $js_time['weeks'] = ['1', '2', '3', '4', '5', '6', '0'];
  131. $JsTimeModel->allowField(true)->isUpdate(false)->save($js_time);
  132. }
  133. $this->success('申请成功');
  134. }
  135. }
  136. /**
  137. * 申请项目
  138. */
  139. public function applyProjectPost()
  140. {
  141. $user_id = $this->getUserId();
  142. $project_id = $this->request->param('project_id');
  143. if (!$project_id) {
  144. $this->error('缺少project_id参数!');
  145. }
  146. $user_type = UserModel::get($user_id)['user_type'];
  147. if ($user_type != 3) {
  148. $this->error('请先去师傅端注册!');
  149. }
  150. $JsModel = new JsModel();
  151. $js_id = $JsModel::where('user_id', $user_id)->value('id');
  152. $res = $JsModel->applyProjectPost($js_id, $project_id);
  153. if ($res) {
  154. $this->success('申请成功');
  155. } else {
  156. $this->error('无需重复申请!');
  157. }
  158. }
  159. public function getDiscount()
  160. {
  161. $where = [];
  162. $status = $this->request->param('status');
  163. if ($status || $status === '0') {
  164. $where['status'] = $status;
  165. }
  166. $where['user_id'] = $this->getUserId();
  167. $UserDiscountModel = new UserDiscountModel();
  168. $list = $UserDiscountModel->getList($where);
  169. $this->success('ok', $list);
  170. }
  171. /**
  172. * 用户修改信息
  173. */
  174. public function editInfo()
  175. {
  176. $user_id = $this->getUserId();
  177. $data['avatar'] = $this->request->param('avatar');
  178. $data['user_nickname'] = $this->request->param('user_nickname');
  179. $UserMolde = new UserModel();
  180. $UserMolde->allowField(true)->isUpdate(true)->save($data, ['id' => $user_id]);
  181. // $JsModel = new JsModel();
  182. // $JsModel->allowField(true)->isUpdate(true)->save($data,['user_id'=>$user_id]);
  183. $this->success('修改成功');
  184. }
  185. public function addIdea()
  186. {
  187. $data['user_id'] = $this->getUserId();
  188. $data['idea'] = $this->request->param('idea');
  189. $data['add_time'] = time();
  190. Db::name('idea')->insert($data);
  191. $this->success('提交成功');
  192. }
  193. public function getxiaji()
  194. {
  195. $page = $this->request->param('page', 1);
  196. $type = $this->request->param('type', 1);
  197. $userModel = new UserModel();
  198. $user_id = $this->getUserId();
  199. $fied = 'parent_id';
  200. if ($type == 2) {
  201. $fied = 'parent_id1';
  202. }
  203. $list = $userModel::where($fied, $user_id)->order('id', 'desc')->page($page, 20)->field('id,mobile,user_nickname,create_time')->select()->each(function ($list) {
  204. $list['mobile'] = preg_replace("/(\d{3})\d{4}(\d{4})/", "\$1****\$2", $list['mobile']);
  205. return $list;
  206. });
  207. $this->success('ok', $list);
  208. }
  209. public function getMoneyLog()
  210. {
  211. $page = $this->request->param('page', 1);
  212. $list = Db::name('user_money_log')->where('user_id', $this->getUserId())->order('id', 'desc')->page($page, 20)->select();
  213. $this->success('ok', $list);
  214. }
  215. /**
  216. * @throws \think\Exception
  217. * @throws \think\exception\PDOException
  218. *获取二维码
  219. */
  220. public function geterweima()
  221. {
  222. $user_id = $this->getUserId();
  223. $erweima = UserModel::get($user_id)['erweima'];
  224. $referral = UserModel::get($user_id)['referral'];
  225. $value = 'http://' . $_SERVER['SERVER_NAME'] . '/h5/#/pages/zhuce/zhuce?yqm=' . $referral;
  226. if (!$erweima) {
  227. $res = qeCode($value, $this->request->controller(), $user_id);
  228. UserModel::where('id', $user_id)->update(['erweima' => $res]);
  229. $this->success('ok', ['erweima' => cmf_get_image_preview_url($res), 'url' => $value, 'referral' => $referral]);
  230. } else {
  231. $this->success('ok', ['erweima' => cmf_get_image_preview_url($erweima), 'url' => $value, 'referral' => $referral]);
  232. }
  233. }
  234. /**
  235. * @throws \think\Exception
  236. * 提现
  237. */
  238. public function addTx()
  239. {
  240. $data['user_id'] = $this->getUserId();
  241. $data['tx_type'] = $this->request->param('tx_type');
  242. $data['money'] = $this->request->param('money');
  243. $data['zfb_name'] = $this->request->param('zfb_name');
  244. $data['zfb_action'] = $this->request->param('zfb_action');
  245. $data['order_sn'] = cmf_get_order_sn();
  246. $user_balance = UserModel::get($this->getUserId())['balance'];
  247. if ($data['tx_type'] == 1) {
  248. $wx_openid = Db::name('third_party_user')->where('user_id', $data['user_id'])->where('union_id', '微信平台')->value('openid');
  249. if (!$wx_openid) {
  250. $this->error('请先绑定wx_openid!');
  251. }
  252. } else {
  253. $validate = new Validate([
  254. 'zfb_name' => 'require',
  255. 'zfb_action' => 'require',
  256. ]);
  257. $validate->message([
  258. 'zfb_name.require' => '支付宝姓名不可为空!',
  259. 'zfb_action.require' => '支付宝账号不可为空!',
  260. ]);
  261. if (!$validate->check($data)) {
  262. $this->error($validate->getError());
  263. }
  264. }
  265. if ($data['money'] > $user_balance) {
  266. $this->error('余额不足!');
  267. }
  268. if ($data['money'] < 0.01) {
  269. $this->error('提现余额不可小于0.01!');
  270. }
  271. UserModel::where('id', $data['user_id'])->setDec('balance', $data['money']);
  272. $UserTxModel = new UserTxModel();
  273. $UserTxModel->allowField(true)->isUpdate(false)->save($data);
  274. $log['user_id'] = $data['user_id'];
  275. $log['money'] = -$data['money'];
  276. $log['yue'] = $user_balance - $data['money'];
  277. $log['type'] = 99;
  278. $log['remark'] = '余额提现';
  279. $log['add_time'] = time();
  280. $log['obj_id'] = $UserTxModel->id;
  281. Db::name('user_money_log')->insert($log);
  282. $this->success('申请成功');
  283. }
  284. /**
  285. * 申请代理
  286. */
  287. public function agencyapply()
  288. {
  289. $data['name'] = $this->request->param('name');
  290. $data['mobile'] = $this->request->param('mobile');
  291. $data['district'] = $this->request->param('district');
  292. $data['add_time'] = time();
  293. $data['user_id'] = $this->getUserId();
  294. Db::name('user_apply_agency')->insert($data);
  295. $this->success('ok', '申请成功');
  296. }
  297. }