User.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  1. <?php
  2. namespace addons\ddrive\controller;
  3. use addons\ddrive\library\Common;
  4. use addons\ddrive\model\Apply;
  5. use addons\ddrive\model\CardVerified;
  6. use addons\ddrive\model\DriverVerified;
  7. use addons\ddrive\model\Hyaddress;
  8. use addons\ddrive\model\RealVerified;
  9. use addons\epay\library\Service;
  10. use app\admin\model\Complaint;
  11. use app\admin\model\ComplaintCategory;
  12. use app\admin\model\Coupon;
  13. use app\admin\model\Details;
  14. use app\common\controller\Api;
  15. use app\common\library\Ems;
  16. use app\common\library\Sms;
  17. use addons\ddrive\model\UserCoupon;
  18. use fast\Random;
  19. use think\Db;
  20. use think\Exception;
  21. use think\Lang;
  22. use think\Log;
  23. use think\Validate;
  24. /**
  25. * 会员接口
  26. */
  27. class User extends Api
  28. {
  29. protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
  30. protected $noNeedRight = '*';
  31. protected $_token = '';
  32. //Token默认有效时长
  33. protected $keeptime = 2592000;
  34. public function _initialize()
  35. {
  36. parent::_initialize();
  37. Lang::load(APP_PATH . 'api/lang/zh-cn/user.php');
  38. }
  39. /**
  40. * 用户资料
  41. */
  42. public function index()
  43. {
  44. $allowFields = ['id', 'username', 'nickname', 'mobile', 'avatar', 'score', 'money', 'group_id', 'bio'];
  45. $user = $this->auth->getUser()->toArray();
  46. $userinfo = array_intersect_key($user, array_flip($allowFields));
  47. $userinfo['token'] = $this->auth->getToken();
  48. // 查询用户司机身份
  49. $userinfo['dirver'] = Apply::where('user_id', $this->auth->id)->where('status', 1)->count();
  50. $this->success('', $userinfo);
  51. }
  52. /**
  53. * 会员登录
  54. *
  55. * @param string $account 账号
  56. * @param string $password 密码
  57. */
  58. public function login()
  59. {
  60. $mobile = $this->request->param('mobile');
  61. $password = $this->request->param('password');
  62. $app_type = $this->request->param('app_type');
  63. $openid = $this->request->param('openid');
  64. if (!$mobile || !$password) {
  65. $this->error(__('Invalid parameters'));
  66. }
  67. if ($app_type != 1 && !$openid) {
  68. $this->error(__('Invalid parameters'));
  69. }
  70. $ret = $this->auth->login($mobile, $password);
  71. if ($ret) {
  72. $data = ['userinfo' => $this->auth->getUserinfo()];
  73. $user = Db::name('user')->alias('U')
  74. ->join('ddrive_user_token DU', 'DU.user_id = U.id', 'LEFT')
  75. ->join('real_verified RV', 'RV.user_id = U.id', 'LEFT')
  76. ->join('card_verified CV', 'CV.user_id = U.id', 'LEFT')
  77. ->join('driver_status DS', 'DS.user_id = U.id', 'LEFT')
  78. ->field('U.mobile,DU.wx_openid,DU.mini_openid,U.avatar,DU.wx_name,RV.truename,RV.idcard,U.emergency_contact,U.contact_tel,CV.card_brand,CV.card_type,DS.status as driver_status')
  79. ->where('U.id', $data['userinfo']['id'])
  80. ->find();
  81. //2021-2-1 by shen 无法登录
  82. // $user = \addons\ddrive\extend\Common::object_array($user);
  83. $data['userinfo']['avatar'] = $user['avatar'] ? cdnurl($user['avatar']) : '';
  84. // 更新openid
  85. // if ($app_type != 1) {
  86. // Db::name('ddrive_user_token')->where('id', $this->auth->id)->update(['openid' => $openid]);
  87. // }
  88. if ($app_type == 1) {
  89. $verified = Db::name('user_verified')->where('user_id', $data['userinfo']['id'])->order('id desc')->find();
  90. $data['userinfo']['real_verified'] = $verified['real_verified'];
  91. $data['userinfo']['driver_verified'] = $verified['driver_verified'];
  92. $data['userinfo']['card_verified'] = $verified['card_verified'];
  93. $data['userinfo']['wx_name'] = $user['wx_name'] ? $user['wx_name'] : '';
  94. $data['userinfo']['openid'] = $user['wx_openid'] ? $user['wx_openid'] : '';
  95. $data['userinfo']['mini_openid'] = $user['mini_openid'] ? $user['mini_openid'] : '';
  96. $data['userinfo']['truename'] = $user['truename'] ? $user['truename'] : '';
  97. $data['userinfo']['idcard'] = $user['idcard'] ? $user['idcard'] : '';
  98. $data['userinfo']['emergency_contact'] = $user['emergency_contact'] ? $user['emergency_contact'] : '';
  99. $data['userinfo']['contact_tel'] = $user['contact_tel'] ? $user['contact_tel'] : '';
  100. $data['userinfo']['card_brand'] = $user['card_brand'] ? $user['card_brand'] : '';
  101. $data['userinfo']['card_type'] = $user['card_type'] ? $user['card_type'] : '';
  102. $data['userinfo']['driver_status'] = $user['driver_status'] === 0 ? $user['driver_status'] : 1;
  103. $data['userinfo']['coupon_count'] = Db::name('user_coupon')->where('user_id', $data['userinfo']['id'])->where('coupon_status', 0)->count();
  104. }
  105. $this->success(__('Logged in successful'), $data);
  106. } else {
  107. $this->error($this->auth->getError());
  108. }
  109. }
  110. /**
  111. * 注册会员
  112. *
  113. * @param string $username 用户名
  114. * @param string $password 密码
  115. * @param string $email 邮箱
  116. * @param string $mobile 手机号
  117. * @param string $captcha 验证码
  118. */
  119. public function register()
  120. {
  121. $mobile = $this->request->request('mobile');
  122. $username = $this->request->request('username', $mobile);
  123. $password = $this->request->request('password');
  124. // 官方数据库中email字段为非空,这里只能给个默认值做兼容
  125. $email = $this->request->request('email', $mobile . '@test.com');
  126. $captcha = $this->request->request('captcha');
  127. $nickname = $this->request->request('nickname');
  128. $avatar = $this->request->request('avatar');
  129. $gender = $this->request->request('gender');
  130. $openid = $this->request->request('openid');
  131. if (!$username || !$password) {
  132. $this->error(__('Invalid parameters'));
  133. }
  134. if ($email && !Validate::is($email, "email")) {
  135. $this->error(__('Email is incorrect'));
  136. }
  137. if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
  138. $this->error(__('Mobile is incorrect'));
  139. }
  140. $ret = Sms::check($mobile, $captcha, 'register');
  141. if (!$ret) {
  142. //$this->error(__('Captcha is incorrect'));
  143. }
  144. $ret = $this->auth->register($username, $password, $email, $mobile, [
  145. 'nickname' => $nickname,
  146. 'avatar' => $avatar,
  147. 'gender' => $gender,
  148. 'group_id' => 1,
  149. ]);
  150. if ($ret) {
  151. $data = ['userinfo' => $this->auth->getUserinfo()];
  152. Db::name('ddrive_user_token')->insert(['openid' => $openid, 'user_id' => $this->auth->id]);
  153. $this->success(__('Sign up successful'), $data);
  154. } else {
  155. $this->error($this->auth->getError());
  156. }
  157. }
  158. /**
  159. * 注销登录
  160. */
  161. public function logout()
  162. {
  163. $this->auth->logout();
  164. $this->success(__('Logout successful'));
  165. }
  166. /**
  167. * 修改会员个人信息
  168. *
  169. * @param string $avatar 头像地址
  170. * @param string $username 用户名
  171. * @param string $nickname 昵称
  172. * @param string $bio 个人简介
  173. */
  174. public function profile()
  175. {
  176. $user = $this->auth->getUser();
  177. $nickname = $this->request->request('nickname');
  178. $bio = $this->request->request('bio');
  179. $avatar = $this->request->request('avatar', '', 'trim,strip_tags,htmlspecialchars');
  180. if ($nickname) {
  181. $user->nickname = $nickname;
  182. }
  183. if ($bio) {
  184. $user->bio = $bio;
  185. }
  186. if ($avatar) {
  187. $user->avatar = $avatar;
  188. }
  189. $user->save();
  190. $this->success('更新成功');
  191. }
  192. /**
  193. * 重置密码
  194. *
  195. * @param string $mobile 手机号
  196. * @param string $newpassword 新密码
  197. * @param string $captcha 验证码
  198. */
  199. public function resetpwd()
  200. {
  201. $mobile = $this->request->param("mobile");
  202. $newpassword = $this->request->param("newpassword");
  203. $captcha = $this->request->param("captcha");
  204. if (!$newpassword || !$captcha) {
  205. $this->error(__('Invalid parameters'));
  206. }
  207. if (!Validate::regex($mobile, "^1\d{10}$")) {
  208. $this->error(__('Mobile is incorrect'));
  209. }
  210. $user = \app\common\model\User::getByMobile($mobile);
  211. if (!$user) {
  212. $this->error(__('User not found'));
  213. }
  214. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  215. if (!$ret) {
  216. $this->error(__('Captcha is incorrect'));
  217. }
  218. Sms::flush($mobile, 'resetpwd');
  219. //模拟一次登录
  220. $this->auth->direct($user->id);
  221. $ret = $this->auth->changepwd($newpassword, '', true);
  222. if ($ret) {
  223. $this->success(__('Reset password successful'));
  224. } else {
  225. $this->error($this->auth->getError());
  226. }
  227. }
  228. /**
  229. * 手机验证码登录
  230. *
  231. * @param string $mobile 手机号
  232. * @param string $captcha 验证码
  233. */
  234. public function mobilelogin()
  235. {
  236. $mobile = $this->request->param('mobile');
  237. $captcha = $this->request->param('captcha');
  238. $event = $this->request->param('event');
  239. $password = $this->request->param('password');
  240. $event = $event ? $event : 'mobilelogin';
  241. if (!$mobile || !$captcha) {
  242. $this->error(__('Invalid parameters'));
  243. }
  244. if (!Validate::regex($mobile, "^1\d{10}$")) {
  245. $this->error(__('Mobile is incorrect'));
  246. }
  247. if (!Sms::check($mobile, $captcha, $event)) {
  248. $this->error(__('Captcha is incorrect'));
  249. }
  250. $user = \app\common\model\User::getByMobile($mobile);
  251. if ($user) {
  252. if ($user->status != 'normal') {
  253. $this->error(__('Account is locked'));
  254. }
  255. //如果已经有账号则直接登录
  256. $ret = $this->auth->direct($user->id);
  257. } else {
  258. $ret = $this->auth->register($mobile, $password, '', $mobile, []);
  259. }
  260. if ($ret) {
  261. Sms::flush($mobile, 'mobilelogin');
  262. $data = ['userinfo' => $this->auth->getUserinfo()];
  263. $coupon = Db::name('coupon')->where('coupon_name', 1)->select();
  264. if ($coupon && $event == 'register') {
  265. foreach ($coupon as $k => $v) {
  266. $user_coupon[] = [
  267. 'user_id' => $data['userinfo']['id'],
  268. 'coupon_id' => $v['id'],
  269. 'expiration' => $v['expiration'] * 86400 + time(),
  270. 'coupon_status' => 0,
  271. 'createtime' => time(),
  272. ];
  273. }
  274. (new UserCoupon())->saveAll($user_coupon);
  275. }
  276. $user_verified = Db::name('user_verified')->where('user_id', $data['userinfo']['id'])->find();
  277. $ddrive_user = Db::name('ddrive_user_token')->where('user_id', $data['userinfo']['id'])->find();
  278. if (!$ddrive_user) {
  279. Db::name('ddrive_user_token')->insert([
  280. 'wx_openid' => '',
  281. 'mini_openid' => '',
  282. 'wx_name' => '',
  283. 'user_id' => $data['userinfo']['id'],
  284. 'unionId' => '',
  285. ]);
  286. }
  287. if (!$user_verified) {
  288. Db::name('user_verified')->insert([
  289. 'user_id' => $data['userinfo']['id'],
  290. 'real_verified' => 0,
  291. 'driver_verified' => 0,
  292. 'card_verified' => 0,
  293. 'createtime' => time(),
  294. 'updatetime' => time(),
  295. ]);
  296. }
  297. $user = Db::name('user')->alias('U')
  298. ->join('ddrive_user_token DU', 'DU.user_id = U.id', 'LEFT')
  299. ->join('real_verified RV', 'RV.user_id = U.id', 'LEFT')
  300. ->join('card_verified CV', 'CV.user_id = U.id', 'LEFT')
  301. ->join('driver_status DS', 'DS.user_id = U.id', 'LEFT')
  302. ->field('U.mobile,DU.wx_openid,DU.mini_openid,U.avatar,DU.wx_name,RV.truename,RV.idcard,U.emergency_contact,U.contact_tel,CV.card_brand,CV.card_type,DS.status as driver_status')
  303. ->where('U.id', $data['userinfo']['id'])
  304. ->find();
  305. $data['userinfo']['avatar'] = $user['avatar'] ? cdnurl($user['avatar']) : '';
  306. $data['userinfo']['wx_name'] = $user['wx_name'] ? $user['wx_name'] : '';
  307. $data['userinfo']['openid'] = $user['wx_openid'] ? $user['wx_openid'] : '';
  308. $data['userinfo']['mini_openid'] = $user['mini_openid'] ? $user['mini_openid'] : '';
  309. $data['userinfo']['emergency_contact'] = $user['emergency_contact'] ? $user['emergency_contact'] : '';
  310. $data['userinfo']['contact_tel'] = $user['contact_tel'] ? $user['contact_tel'] : '';
  311. $verified = Db::name('user_verified')->where('user_id', $data['userinfo']['id'])->order('id desc')->find();
  312. $data['userinfo']['real_verified'] = $verified['real_verified'];
  313. $data['userinfo']['driver_verified'] = $verified['driver_verified'];
  314. $data['userinfo']['card_verified'] = $verified['card_verified'];
  315. $data['userinfo']['truename'] = $user['truename'] ? $user['truename'] : '';
  316. $data['userinfo']['idcard'] = $user['idcard'] ? $user['idcard'] : '';
  317. $data['userinfo']['card_brand'] = $user['card_brand'] ? $user['card_brand'] : '';
  318. $data['userinfo']['card_type'] = $user['card_type'] ? $user['card_type'] : '';
  319. $data['userinfo']['driver_status'] = $user['driver_status'] === 0 ? $user['driver_status'] : 1;
  320. $data['userinfo']['coupon_count'] = Db::name('user_coupon')->where('user_id', $data['userinfo']['id'])->where('coupon_status', 0)->count();
  321. $this->success(__('Logged in successful'), $data);
  322. } else {
  323. $this->error($this->auth->getError());
  324. }
  325. }
  326. /**
  327. * 实名认证
  328. *
  329. * @param string $truename 真实姓名
  330. * @param string $idcard 身份证号
  331. * @param string $front_card_image 身份证正面
  332. * @param string $back_card_image 身份证反面
  333. */
  334. public function verified()
  335. {
  336. $type = $this->request->param('type');
  337. $truename = $this->request->param('truename');
  338. $idcard = $this->request->param('idcard');
  339. $front_card_image = $this->request->param('front_card_image');
  340. $back_card_image = $this->request->param('back_card_image');
  341. $sign_areas = $this->request->param('sign_areas');
  342. $areas = $this->request->param('areas');
  343. $driver_license = $this->request->param('driver_license');
  344. $driver_front_image = $this->request->param('driver_front_image');
  345. $driver_back_image = $this->request->param('driver_back_image');
  346. $card_brand = $this->request->param('card_brand');
  347. $card_type = $this->request->param('card_type');
  348. $number_plate = $this->request->param('number_plate');
  349. $card_front_image = $this->request->param('card_front_image');
  350. $card_back_image = $this->request->param('card_back_image');
  351. $user_verified = Db::name('user_verified')->where('user_id', $this->auth->id)->find();
  352. Db::startTrans();
  353. try {
  354. if ($type == 1) {
  355. if (!$truename || !$idcard || !$front_card_image || !$back_card_image) {
  356. exception(__('Invalid parameters'));
  357. }
  358. $real_verified = Db::name('real_verified')->where('user_id', $this->auth->id)->whereIn('status', [0, 1])->find();
  359. if ($real_verified) {
  360. if ($real_verified['status'] == 0) {
  361. exception(__('您当前正在审核中,请耐心等待'));
  362. }
  363. if ($real_verified['status'] == 1) {
  364. exception(__('您已实名认证,无需再审核'));
  365. }
  366. $data = [
  367. 'user_id' => $this->auth->id,
  368. 'truename' => $truename,
  369. 'idcard' => $idcard,
  370. 'front_card_image' => $front_card_image,
  371. 'back_card_image' => $back_card_image,
  372. 'status' => 0,
  373. 'createtime' => time(),
  374. ];
  375. RealVerified::update($data);
  376. } else {
  377. $data = [
  378. 'user_id' => $this->auth->id,
  379. 'truename' => $truename,
  380. 'idcard' => $idcard,
  381. 'front_card_image' => $front_card_image,
  382. 'back_card_image' => $back_card_image,
  383. 'status' => 0,
  384. 'createtime' => time(),
  385. ];
  386. RealVerified::create($data);
  387. }
  388. Db::name('user_verified')->where('user_id', $this->auth->id)->setField('real_verified', 2);
  389. } elseif ($type == 2) {
  390. if ($user_verified['real_verified'] != 1) {
  391. exception('请先实名认证');
  392. }
  393. if (!$sign_areas || !$areas || !$driver_license || !$driver_front_image || !$driver_back_image) {
  394. exception(__('Invalid parameters'));
  395. }
  396. $sign_areas = Db::name('areas')->where(['id' => $sign_areas])->find();
  397. if (empty($sign_areas)) {
  398. exception('地址不存在');
  399. }
  400. $sign_path = explode(',', $sign_areas['parent_path']);
  401. $areas = Db::name('areas')->where(['id' => $areas])->find();
  402. if (empty($areas)) {
  403. exception('地址不存在');
  404. }
  405. $parent_path = explode(',', $areas['parent_path']);
  406. $driver_verified = Db::name('driver_verified')->where('user_id', $this->auth->id)->whereIn('status', [0, 1])->find();
  407. if ($driver_verified) {
  408. if ($driver_verified['status'] == 0) {
  409. exception(__('您当前正在审核中,请耐心等待'));
  410. }
  411. if ($driver_verified['status'] == 1) {
  412. exception(__('您已驾照认证,无需再审核'));
  413. }
  414. $data = [
  415. 'user_id' => $this->auth->id,
  416. 'province' => $parent_path['0'],
  417. 'city' => $parent_path['1'],
  418. 'area' => $parent_path['2'],
  419. 'sign_province' => $sign_path['0'],
  420. 'sign_city' => $sign_path['1'],
  421. 'driver_license' => $driver_license,
  422. 'driver_front_image' => $driver_front_image,
  423. 'driver_back_image' => $driver_back_image,
  424. ];
  425. DriverVerified::update($data);
  426. } else {
  427. $data = [
  428. 'user_id' => $this->auth->id,
  429. 'province' => $parent_path['0'],
  430. 'city' => $parent_path['1'],
  431. 'area' => $parent_path['2'],
  432. 'sign_province' => $sign_path['0'],
  433. 'sign_city' => $sign_path['1'],
  434. 'driver_license' => $driver_license,
  435. 'driver_front_image' => $driver_front_image,
  436. 'driver_back_image' => $driver_back_image,
  437. ];
  438. DriverVerified::create($data);
  439. }
  440. Db::name('user_verified')->where('user_id', $this->auth->id)->setField('driver_verified', 2);
  441. } else {
  442. if ($user_verified['driver_verified'] != 1 || $user_verified['real_verified'] != 1) {
  443. exception('请先实名认证或者驾照认证');
  444. }
  445. if (!$sign_areas || !$areas || !$card_brand || !$number_plate || !$card_front_image || !$card_back_image) {
  446. exception(__('Invalid parameters'));
  447. }
  448. $sign_areas = Db::name('areas')->where(['id' => $sign_areas])->find();
  449. if (empty($sign_areas)) {
  450. exception('地址不存在');
  451. }
  452. $sign_path = explode(',', $sign_areas['parent_path']);
  453. $areas = Db::name('areas')->where(['id' => $areas])->find();
  454. if (empty($areas)) {
  455. exception('地址不存在');
  456. }
  457. $parent_path = explode(',', $areas['parent_path']);
  458. $card_verified = Db::name('card_verified')->where('user_id', $this->auth->id)->whereIn('status', [0, 1])->find();
  459. if ($card_verified) {
  460. if ($card_verified['status'] == 0) {
  461. exception(__('您当前正在审核中,请耐心等待'));
  462. }
  463. if ($card_verified['status'] == 1) {
  464. exception(__('您已车主认证,无需再审核'));
  465. }
  466. $data = [
  467. 'user_id' => $this->auth->id,
  468. 'province' => $parent_path['0'],
  469. 'city' => $parent_path['1'],
  470. 'area' => $parent_path['2'],
  471. 'sign_province' => $sign_path['0'],
  472. 'sign_city' => $sign_path['1'],
  473. 'card_brand' => $card_brand,
  474. 'card_type' => $card_type,
  475. 'number_plate' => $number_plate,
  476. 'card_front_image' => $card_front_image,
  477. 'card_back_image' => $card_back_image,
  478. ];
  479. CardVerified::update($data);
  480. } else {
  481. $data = [
  482. 'user_id' => $this->auth->id,
  483. 'province' => $parent_path['0'],
  484. 'city' => $parent_path['1'],
  485. 'area' => $parent_path['2'],
  486. 'sign_province' => $sign_path['0'],
  487. 'sign_city' => $sign_path['1'],
  488. 'card_brand' => $card_brand,
  489. 'card_type' => $card_type,
  490. 'number_plate' => $number_plate,
  491. 'card_front_image' => $card_front_image,
  492. 'card_back_image' => $card_back_image,
  493. ];
  494. CardVerified::create($data);
  495. }
  496. Db::name('user_verified')->where('user_id', $this->auth->id)->setField('card_verified', 2);
  497. }
  498. Db::commit();
  499. } catch (\Exception $e) {
  500. $this->error($e->getMessage());
  501. Db::rollback();
  502. }
  503. $this->success('提交成功,请耐心等待');
  504. }
  505. /**
  506. * 修改手机号
  507. *
  508. * @param string $mobile 手机号
  509. * @param string $captcha 验证码
  510. */
  511. public function changemobile()
  512. {
  513. $user = $this->auth->getUser();
  514. $mobile = $this->request->param('mobile');
  515. $captcha = $this->request->param('captcha');
  516. if (!$mobile || !$captcha) {
  517. $this->error(__('Invalid parameters'));
  518. }
  519. if (!Validate::regex($mobile, "^1\d{10}$")) {
  520. $this->error(__('Mobile is incorrect'));
  521. }
  522. if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
  523. $this->error(__('Mobile already exists'));
  524. }
  525. $result = Sms::check($mobile, $captcha, 'changemobile');
  526. if (!$result) {
  527. $this->error(__('Captcha is incorrect'));
  528. }
  529. $verification = $user->verification;
  530. $verification->mobile = 1;
  531. $user->verification = $verification;
  532. $user->mobile = $mobile;
  533. $user->save();
  534. Sms::flush($mobile, 'changemobile');
  535. $this->success('修改手机号成功');
  536. }
  537. /**
  538. * 检测是否可修改手机号/微信
  539. * @ApiMethod (POST)
  540. * @ApiParams (name="type", type="string", required=true, description="1手机号2微信")
  541. * @param string $live_video 视频
  542. */
  543. public function check_account()
  544. {
  545. $type = $this->request->param('type');
  546. $user = Db::name('user')->alias('U')
  547. ->join('ddrive_user_token DU', 'DU.user_id = U.id', 'LEFT')
  548. ->field('U.mobile,DU.openid')
  549. ->where('U.id', $this->auth->id)
  550. ->find();
  551. Db::startTrans();
  552. try {
  553. if ($type == 1) {
  554. if (!$user['openid']) {
  555. exception('您当前不可修改手机号,请先绑定微信');
  556. }
  557. } else {
  558. if (!$user['mobile']) {
  559. exception('您当前不可修改微信号,请先绑定手机号');
  560. }
  561. }
  562. Db::commit();
  563. } catch (\Exception $e) {
  564. Db::rollback();
  565. $this->error($e->getMessage());
  566. }
  567. $this->success('成功');
  568. }
  569. /**
  570. * 微信登录绑定已有账号
  571. *
  572. * @param string $mobile 手机号
  573. * @param string $captcha 验证码
  574. */
  575. public function bindOnAccount()
  576. {
  577. $mobile = $this->request->param('mobile');
  578. $captcha = $this->request->param('captcha');
  579. if (!$mobile) {
  580. $this->error('请填写手机号');
  581. }
  582. if (!$captcha) {
  583. $this->error('请填写验证码');
  584. }
  585. $ret = Sms::check($mobile, $captcha, 'mobilelogin');
  586. if (!$ret) {
  587. $this->error('验证码错误');
  588. }
  589. $user = Db::name('user')->where('mobile', $mobile)->find();
  590. if ($user) {
  591. $this->error('该账号已被绑定');
  592. }
  593. $nickname = preg_match("/^1[3-9]{1}\d{9}$/", $mobile) ? substr_replace($mobile, '****', 3, 4) : $mobile;
  594. Db::name('user')->where('id', $this->auth->id)->update(['mobile' => $mobile, 'username' => $mobile, 'nickname' => $nickname]);
  595. $this->success('绑定成功');
  596. }
  597. /**
  598. * 收益
  599. * @ApiReturnParams (name="today_income", type="str", required=true, description="今日收益")
  600. */
  601. public function userIncome()
  602. {
  603. $begin_time = strtotime(date('Y-m-d', time()));
  604. $end_time = $begin_time + 86400;
  605. $today_income = (new Details())
  606. ->where('user_id', $this->auth->id)
  607. ->where('assets_type', 2)
  608. ->where('fluctuate_type', 1)
  609. ->whereBetween('createtime', [$begin_time, $end_time])
  610. ->sum('amount');
  611. $income = (new Details())
  612. ->where('user_id', $this->auth->id)
  613. ->where('assets_type', 2)
  614. ->where('fluctuate_type', 1)
  615. ->sum('amount');
  616. $user = Db::name('user')->where('id', $this->auth->id)->field('money,platform_service_fee')->find();
  617. $platform_service_fee = get_addon_config('ddrive')['platform_service_fee'] / 100;
  618. $this->success('成功', [
  619. 'today_income' => $today_income,
  620. 'money' => $user['money'],
  621. 'income' => $income,
  622. 'platform_service_fee' => $user['platform_service_fee'],
  623. 'withdraw_money' => round($user['money'] - round($platform_service_fee * $user['money'], 2),2),
  624. ]);
  625. }
  626. /**
  627. * 账单管理
  628. * @ApiMethod (POST)
  629. * @ApiParams (name="source_type", type="int", required=true, description="来源类型:1=提现,2=接单)
  630. * @ApiReturnParams (name="user_id", type="str", required=true, description="用户id")
  631. * @ApiReturnParams (name="task_id", type="str", required=true, description="消费类型:1=健身,2=ktv,3=酒吧,4=保龄球")
  632. * @ApiReturnParams (name="fluctuate_type", type="str", required=true, description="状态 1=增加,2=减少")
  633. * @ApiReturnParams (name="msg", type="str", required=true, description="说明")
  634. * @ApiReturnParams (name="amount", type="str", required=true, description="消费金额")
  635. * @ApiReturnParams (name="assets_type", type="str", required=true, description="资产类型:1=余额,2=奖金")
  636. * @ApiReturnParams (name="source_type", type="str", required=true, description="来源类型:1=消费,2=平台分红,3=提现,4=推广返利")
  637. * @ApiReturnParams (name="income", type="str", required=true, description="收入")
  638. * @ApiReturnParams (name="expenses", type="str", required=true, description="支出")
  639. *
  640. */
  641. public function assets()
  642. {
  643. $source_type = $this->request->param('source_type');
  644. $where = [];
  645. if ($source_type) {
  646. $where['source_type'] = $source_type;
  647. }
  648. $result = Db::name('details')
  649. ->where($where)
  650. ->where('user_id', $this->auth->id)
  651. ->order('createtime desc')
  652. ->select();
  653. foreach ($result as $k => $v) {
  654. $result[$k]['amount'] = $v['amount'] ? $v['amount'] : 0;
  655. $result[$k]['createtime'] = date('Y-m-d H:i:d', $v['createtime']);
  656. }
  657. $this->success('成功', ['data' => $result ?: []]);
  658. }
  659. /**
  660. * 用户信息
  661. *
  662. */
  663. public function userInfo()
  664. {
  665. //**提现开启关闭状态
  666. $marketInfo = Db::name('market')->find();
  667. $userInfo = Db::name('user')->alias('U')
  668. ->join('user_verified UV', 'UV.user_id = U.id')
  669. ->join('ddrive_user_token DU', 'DU.user_id = U.id', 'LEFT')
  670. ->join('real_verified RV', 'RV.user_id = U.id', 'LEFT')
  671. ->join('card_verified CV', 'CV.user_id = U.id', 'LEFT')
  672. ->join('driver_status DS', 'DS.user_id = U.id', 'LEFT')
  673. ->where('U.id', $this->auth->id)
  674. ->field('U.id,U.username,U.nickname,U.mobile,U.score,U.money,U.avatar,UV.real_verified,UV.driver_verified,UV.card_verified,DU.wx_openid,DU.mini_openid,DU.wx_name,RV.truename,RV.idcard,U.emergency_contact,U.contact_tel,CV.card_brand,CV.card_type,DS.status as driver_status')
  675. ->find();
  676. //设置Token
  677. $this->_token = Random::uuid();
  678. \app\common\library\Token::set($this->_token, $userInfo['id'], $this->keeptime);
  679. $userInfo = array_merge($userInfo, \app\common\library\Token::get($this->_token));
  680. $userInfo['avatar'] = $userInfo['avatar'] ? cdnurl($userInfo['avatar']) : '';
  681. $userInfo['openid'] = $userInfo['wx_openid'] ? $userInfo['wx_openid'] : '';
  682. $userInfo['mini_openid'] = $userInfo['mini_openid'] ? $userInfo['mini_openid'] : '';
  683. $userInfo['truename'] = $userInfo['truename'] ? $userInfo['truename'] : '';
  684. $userInfo['idcard'] = $userInfo['idcard'] ? $userInfo['idcard'] : '';
  685. $userInfo['emergency_contact'] = $userInfo['emergency_contact'] ? $userInfo['emergency_contact'] : '';
  686. $userInfo['contact_tel'] = $userInfo['contact_tel'] ? $userInfo['contact_tel'] : '';
  687. $userInfo['card_brand'] = $userInfo['card_brand'] ? $userInfo['card_brand'] : '';
  688. $userInfo['card_type'] = $userInfo['card_type'] ? $userInfo['card_type'] : '';
  689. $userInfo['driver_status'] = $userInfo['driver_status'] === 0 ? $userInfo['driver_status'] : 1;
  690. $userInfo['coupon_count'] = Db::name('user_coupon')->where('user_id', $this->auth->id)->where('coupon_status', 0)->count();
  691. $userInfo['ts_status'] = $marketInfo['ts_status'];
  692. $this->success('成功', $userInfo);
  693. }
  694. /**
  695. * 手机登录绑定微信
  696. *
  697. * @param string $mobile 手机号
  698. * @param string $openid openid
  699. * @param string $wx_name wx_name
  700. */
  701. public function mobileOnAccount()
  702. {
  703. $openid = $this->request->param('openid');
  704. $wx_name = $this->request->param('wx_name');
  705. $unionId = $this->request->param('unionId');
  706. if (!$openid || !$wx_name || !$unionId) {
  707. $this->error('参数错误');
  708. }
  709. $user = Db::name('user')->where('id', $this->auth->id)->find();
  710. if (!$user) {
  711. $this->error('该用户不存在');
  712. }
  713. $ddrive_user = Db::name('ddrive_user_token')->where('wx_openid', $openid)->find();
  714. if ($ddrive_user['wx_openid']) {
  715. $this->error('该微信账户已存在');
  716. }
  717. Db::name('ddrive_user_token')->where('user_id', $this->auth->id)->update(['wx_openid' => $openid, 'wx_name' => $wx_name, 'unionId' => $unionId]);
  718. $this->success('绑定成功');
  719. }
  720. /**
  721. * 提现配置
  722. *
  723. * @param string $mobile 手机号
  724. * @param string $openid openid
  725. * @param string $wx_name wx_name
  726. */
  727. public function cash_set()
  728. {
  729. $ddrive_config = get_addon_config('ddrive');
  730. $cash_set = [];
  731. $cash_set['withdraw_rate'] = $ddrive_config['withdraw_rate'];
  732. $cash_set['withdraw_min'] = $ddrive_config['withdraw_min'];
  733. $cash_set['withdraw_max'] = $ddrive_config['withdraw_max'];
  734. $this->success('成功', ['cash_set' => $cash_set]);
  735. }
  736. /**
  737. * 服务费支付
  738. *
  739. * @param string $type 1余额2微信
  740. */
  741. public function service_pay()
  742. {
  743. $type = $this->request->param('type');
  744. $user = Db::name('user')->where('id', $this->auth->id)->find();
  745. if ($user['platform_service_fee'] > 0) {
  746. if ($type == 1) {
  747. if ($user['money'] < $user['platform_service_fee']) {
  748. $this->error('余额不足');
  749. }
  750. try {
  751. Db::name('user')->where('id', $this->auth->id)->setDec('money', $user['platform_service_fee']);
  752. Db::name('user')->where('id', $this->auth->id)->setField('platform_service_fee', 0);
  753. $detailModel = new Details();
  754. $detailModel->addDetail($this->auth->id, 2, '支付平台服务费', $user['platform_service_fee'], 2, 2, 0);
  755. } catch (\Exception $e) {
  756. $this->error($e->getMessage());
  757. }
  758. $this->success('支付成功');
  759. } else {
  760. //回调链接
  761. $notifyurl = $this->request->root(true) . '/addons/ddrive/user/notifyx/paytype/wechat';
  762. $merchant_order = $this->auth->id . 'SE' . date('Ymd') . str_pad(mt_rand(1, 999999), 6, '0', STR_PAD_LEFT);
  763. $params = [
  764. 'type' => 'driver_wechat',
  765. 'orderid' => $merchant_order,
  766. 'title' => '代驾',
  767. 'amount' => $user['platform_service_fee'],
  768. 'method' => 'app',
  769. 'notifyurl' => $notifyurl,
  770. ];
  771. try {
  772. $pay = json_encode(Service::submitOrder($params));
  773. return json_encode(['code' => 1, 'msg' => '成功', 'data' => json_decode(json_decode($pay, true), true)]);
  774. } catch (\Throwable $th) {
  775. return json_encode(['code' => 0, 'msg' => '失败']);
  776. }
  777. }
  778. } else {
  779. $this->error('您暂时不欠平台服务费');
  780. }
  781. }
  782. /**
  783. * 支付成功
  784. *
  785. * @return void
  786. */
  787. public function notifyx()
  788. {
  789. Log::record('支付回调');
  790. $paytype = $this->request->param('paytype');
  791. $pay = \addons\epay\library\Service::checkNotify($paytype);
  792. if (!$pay) {
  793. Log::record('签名错误');
  794. echo '签名错误';
  795. return;
  796. }
  797. $data = $pay->verify();
  798. try {
  799. $user_id = substr($data['out_trade_no'], 0, strpos($data['out_trade_no'], 'SE'));
  800. Db::name('user')->where('id', $user_id)->setField('platform_service_fee', 0);
  801. } catch (Exception $e) {
  802. Log::record($e->getMessage());
  803. }
  804. echo $pay->success();
  805. }
  806. /**
  807. * 投诉中心
  808. *
  809. */
  810. public function complaint_category()
  811. {
  812. $order_id = $this->request->param('order_id');
  813. $sf_type = $this->request->param('sf_type');
  814. if (!$order_id) {
  815. $this->error('参数错误');
  816. }
  817. if ($sf_type == 1) {
  818. $order = (new \addons\ddrive\model\Sforder())->where('id', $order_id)->find();
  819. } elseif ($sf_type == 2) {
  820. $order = (new \addons\ddrive\model\Hyorder())::with('shaddress')->where('id', $order_id)->where('user_id', $this->auth->id)->find();
  821. } else {
  822. $order = (new \addons\ddrive\model\Order())->where('id', $order_id)->where('user_id', $this->auth->id)->find();
  823. }
  824. if (!$order) {
  825. $this->error('该订单不存在');
  826. }
  827. if ($order['status'] != 99 && in_array($sf_type, [1, 2])) {
  828. $this->error('该订单还未完成,暂无法投诉');
  829. }
  830. if ($order['status'] != 5 && $sf_type == 1) {
  831. $this->error('该订单还未完成,暂无法投诉');
  832. }
  833. if (($order['complete_time'] + 86400 * 7) < time()) {
  834. $this->error('该订单已超过售后时间');
  835. }
  836. $order_info = [];
  837. $order_info['createtime'] = date('m-d H:i', $order['createtime']);
  838. $order_info['status'] = $order['status'];
  839. $order_info['start_address'] = $order['start_address'];
  840. if($sf_type == 2){
  841. $order_info['end_address'] = $order['shaddress'];
  842. }else{
  843. $order_info['end_address'] = $order['end_address'];
  844. }
  845. $list = (new ComplaintCategory())->select();
  846. foreach ($list as $k => $v) {
  847. $list[$k]['category_image'] = cdnurl($v['category_image']);
  848. }
  849. $this->success('成功', ['list' => $list ? $list : [], 'order_info' => $order_info]);
  850. }
  851. /**
  852. * 投诉
  853. *
  854. */
  855. public function complaint()
  856. {
  857. $order_id = $this->request->param('order_id');
  858. $complaint_id = $this->request->param('complaint_id');
  859. $remark = $this->request->param('remark');
  860. $certificate_image = $this->request->param('certificate_image');
  861. $sf_type = $this->request->param('sf_type');
  862. if (!$order_id || !$remark || !$certificate_image || !$complaint_id) {
  863. $this->error('参数错误');
  864. }
  865. $id = (new Complaint())->insertGetId([
  866. 'user_id' => $this->auth->id,
  867. 'order_id' => $order_id,
  868. 'complaint_id' => $complaint_id,
  869. 'type' => $sf_type == 1 ? 2 : ($sf_type == 2 ? 3 : 1),
  870. 'remark' => $remark,
  871. 'certificate_image' => $certificate_image,
  872. 'status' => 0,
  873. 'createtime' => time(),
  874. 'updatetime' => time(),
  875. ]);
  876. if ($id) {
  877. $this->success('投诉成功,请等待审核结果', ['id' => $id]);
  878. } else {
  879. $this->error('网络错误,请稍后再试');
  880. }
  881. }
  882. /**
  883. * 投诉进度
  884. *
  885. */
  886. public function complaint_schedule()
  887. {
  888. $order = Db::name('ddrive_order')->alias('O')
  889. ->join('complaint C', 'C.order_id = O.id')
  890. ->join('complaint_category CA', 'CA.id = C.complaint_id')
  891. ->where('C.user_id', $this->auth->id)
  892. ->where('C.type', 1)
  893. ->field('C.createtime,C.status,O.start_address,C.type,O.end_address,O.createtime as create_time,CA.name,C.id')
  894. ->order('C.id desc')
  895. ->select();
  896. $sforder = Db::name('ddrive_sf_order')->alias('SO')
  897. ->join('complaint C', 'C.order_id = SO.id')
  898. ->join('complaint_category CA', 'CA.id = C.complaint_id')
  899. ->where('C.user_id', $this->auth->id)
  900. ->where('C.type', 2)
  901. ->field('C.createtime,C.status,SO.start_address,C.type,SO.end_address,SO.createtime as create_time,CA.name,C.id')
  902. ->order('C.id desc')
  903. ->select();
  904. $hyorder = (new \addons\ddrive\model\Hyorder())->alias('HO')
  905. ->join('complaint C', 'C.order_id = HO.id')
  906. ->join('complaint_category CA', 'CA.id = C.complaint_id')
  907. ->where('C.user_id', $this->auth->id)
  908. ->where('C.type', '3')
  909. ->field('C.createtime,C.status,HO.start_address,C.type,HO.createtime as create_time,CA.name,C.id,C.order_id')
  910. ->order('C.id desc')
  911. ->select();
  912. foreach ($hyorder as $k=>$v){
  913. $hyorder[$k]['shaddress'] = (new Hyaddress())->where('order_id',$v['order_id'])->select();
  914. }
  915. $new_order = array_merge($order, $sforder, $hyorder);
  916. foreach ($new_order as $k => $v) {
  917. $new_order[$k]['createtime'] = (new Common())->getTimeInfoUser($v['createtime']);
  918. }
  919. $this->success('成功', ['order_info' => $new_order]);
  920. }
  921. /**
  922. * 投诉详情
  923. *
  924. */
  925. public function complaint_info()
  926. {
  927. $id = $this->request->param('complaint_id');
  928. if (!$id) {
  929. $this->error('参数错误');
  930. }
  931. $complaint = (new Complaint())->where('id', $id)->find();
  932. $complaint['certificate_image'] = explode(',', $complaint['certificate_image']);
  933. foreach ($complaint['certificate_image'] as $k => $v) {
  934. $certificate_image[] = cdnurl($v);
  935. }
  936. $complaint['createtime'] = date('Y-m-d H:i:s', time());
  937. $complaint['updatetime'] = $complaint['updatetime'] ? $complaint['updatetime'] : '';
  938. $complaint['certificate_image'] = $certificate_image;
  939. $complaint['handling_opinions'] = $complaint['handling_opinions'] ? $complaint['handling_opinions'] : '平台正在核查,请耐心等待';
  940. $this->success('成功', ['complaint_info' => $complaint]);
  941. }
  942. /**
  943. * 客服电话
  944. *
  945. */
  946. public function consumer_hotline()
  947. {
  948. $tel = get_addon_config('ddrive')['phone'];
  949. $this->success('成功', ['tel' => $tel]);
  950. }
  951. /**
  952. * 添加紧急联系人
  953. *
  954. */
  955. public function add_contact()
  956. {
  957. $emergency_contact = $this->request->param('emergency_contact');
  958. $contact_tel = $this->request->param('contact_tel');
  959. if (!$emergency_contact || !$contact_tel) {
  960. $this->error('参数错误');
  961. }
  962. $ret = Db::name('user')->where('id', $this->auth->id)->update(['emergency_contact' => $emergency_contact, 'contact_tel' => $contact_tel]);
  963. if ($ret) {
  964. $this->success('添加成功');
  965. }
  966. }
  967. /**
  968. * 优惠券
  969. *
  970. */
  971. public function coupon()
  972. {
  973. $type = $this->request->param('type', 1); //用户 1=待使用,2=已使用,3=已过期
  974. $where = [];
  975. if ($type == 1) {
  976. $where['coupon_status'] = 0;
  977. } elseif ($type == 2) {
  978. $where['coupon_status'] = 1;
  979. } else {
  980. $where['coupon_status'] = 2;
  981. }
  982. $coupon_list = Db::name('user_coupon')
  983. ->where($where)
  984. ->where('user_id', $this->auth->id)
  985. ->field('coupon_id,coupon_type,coupon_name,remark,coupon_price,limit_price,coupon_status,createtime,coupon_status as status,id,expiration as exp')
  986. ->order('id desc')
  987. ->select();
  988. foreach ($coupon_list as $k => $v) {
  989. $coupon_list[$k]['expiration'] = $v['exp'] ? date('Y-m-d', $v['exp']) : '';
  990. $coupon_list[$k]['createtime'] = $v['createtime'] ? date('Y-m-d', $v['createtime']) : '';
  991. }
  992. $this->success('成功', $coupon_list ? $coupon_list : []);
  993. }
  994. /**
  995. * 支付优惠券
  996. *
  997. */
  998. public function pay_coupon()
  999. {
  1000. $order_id = $this->request->param('order_id');
  1001. $sf = $this->request->param('sf_type');
  1002. $hy_order_price = $this->request->param('order_price');
  1003. $where = [];
  1004. if ($sf == 1) {
  1005. $where['coupon_type'] = 2;
  1006. $order = Db::name('ddrive_sf_order')->where('id', $order_id)->find();
  1007. if (!$order) {
  1008. $this->error('该订单不存在');
  1009. }
  1010. $order_money = $order['order_money'];
  1011. } elseif ($sf == 2){
  1012. $where['coupon_type'] = 3;
  1013. if(empty($hy_order_price)){
  1014. $this->error('请选择订单金额');
  1015. }
  1016. $order_money = $hy_order_price;
  1017. }else {
  1018. $where['coupon_type'] = 1;
  1019. $order = Db::name('ddrive_order')->where('id', $order_id)->find();
  1020. if (!$order) {
  1021. $this->error('该订单不存在');
  1022. }
  1023. $order_money = $order['price'];
  1024. }
  1025. $coupon_list = Db::name('user_coupon')->alias('UC')
  1026. ->where('coupon_status', 0)
  1027. ->where('user_id', $this->auth->id)
  1028. ->field('coupon_id,coupon_type,coupon_name,remark,coupon_price,limit_price,coupon_status,createtime,coupon_status as status,id,expiration as exp')
  1029. ->order('id desc')
  1030. ->select();
  1031. foreach ($coupon_list as $k => $v) {
  1032. if ($v['limit_price'] <= $order_money) {
  1033. $coupon_list[$k]['be_status'] = 1;
  1034. } else {
  1035. $coupon_list[$k]['be_status'] = 0;
  1036. }
  1037. $coupon_list[$k]['expiration'] = $v['exp'] ? date('Y-m-d', $v['exp']) : '';
  1038. $coupon_list[$k]['createtime'] = $v['createtime'] ? date('Y-m-d', $v['createtime']) : '';
  1039. }
  1040. $this->success('成功', $coupon_list ? $coupon_list : []);
  1041. }
  1042. public function driver_status()
  1043. {
  1044. $status = $this->request->param('status', 1);
  1045. if (!in_array($status, [0, 1])) {
  1046. $this->error('参数错误');
  1047. }
  1048. $driver_status = Db::name('driver_status')->where('user_id', $this->auth->id)->find();
  1049. if ($driver_status) {
  1050. Db::name('driver_status')->where('user_id', $this->auth->id)->setField('status', $status);
  1051. Db::name('driver_status')->where('user_id', $this->auth->id)->setField('createtime', time());
  1052. } else {
  1053. Db::name('driver_status')->insert([
  1054. 'user_id' => $this->auth->id,
  1055. 'status' => $status,
  1056. 'createtime' => time(),
  1057. ]);
  1058. }
  1059. $this->success('成功');
  1060. }
  1061. }