User.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\ApiController;
  4. use app\api\service\SmsCode;
  5. use app\http\IResponse;
  6. use EasyWeChat\Factory;
  7. use Lettered\Support\Upload;
  8. use Lettered\Support\Exceptions\TokenException;
  9. use think\Db;
  10. use think\Exception;
  11. class User extends ApiController
  12. {
  13. /**
  14. * 获取个人中心数据
  15. * 1. 用户昵称、手机号、头像、余额、提现
  16. *
  17. * @author 许祖兴 < zuxing.xu@lettered.cn>
  18. * @date 2020/6/30 15:46
  19. *
  20. * @return \think\response\Json
  21. * @throws \Lettered\Support\Exceptions\FailedException
  22. */
  23. public function getUserCenter()
  24. {
  25. $user = $this->auth->user();
  26. // 用户判断是不是被删除了,及时退出
  27. if($user){
  28. if ($user['status'] == 0) {
  29. throw new TokenException([
  30. 'errmsg' => 'Unauthorized: 用户冻结!'
  31. ]);
  32. }
  33. unset($user['paycode']);
  34. // 2. 加载已提现金额
  35. $user['withdraw'] = model('common/UsersWithdraw')
  36. ->where([
  37. 'user_id' => $this->auth->user()['id'],
  38. 'status' => 2
  39. ])->sum('amount');
  40. return $this->ApiJson(0,'加载用户数据成功', $user);
  41. }
  42. throw new TokenException([
  43. 'errmsg' => 'Unauthorized:Request token denied!'
  44. ]);
  45. }
  46. /**
  47. * 更新用户信息
  48. *
  49. * @author 许祖兴 < zuxing.xu@lettered.cn>
  50. * @date 2020/7/6 15:33
  51. *
  52. * @return \think\response\Json
  53. * @throws \Lettered\Support\Exceptions\FailedException
  54. */
  55. public function updateUserInfo()
  56. {
  57. // 接收参数
  58. $params = $this->request->param();
  59. // 参数校验
  60. $valid = $this->validate($params, [
  61. 'field|更新字段' => 'require',
  62. 'value|更新内容' => 'require'
  63. ]);
  64. // 错误返回
  65. if (true !== $valid) {
  66. return $this->ApiJson(-1, $valid);
  67. }
  68. // 交易密码要验证手机码
  69. // if ($params['field'] == 'paycode'){
  70. // 验证
  71. $sms = new SmsCode();
  72. // if (!$sms->verify(input('mobile'),input('vercode'))) {
  73. // return $this->ApiJson(-1, "验证码错误!");
  74. // }
  75. // }
  76. // 改
  77. model('common/Users')
  78. ->updateBy($this->auth->user()['id'], [
  79. $params['field'] => $params['value']
  80. ]);
  81. return $this->ApiJson(0, '更新信息成功');
  82. }
  83. /**
  84. * 金额提现
  85. *
  86. * @author 许祖兴 < zuxing.xu@lettered.cn>
  87. * @date 2020/7/8 18:30
  88. *
  89. * @return \think\response\Json
  90. * @throws \Lettered\Support\Exceptions\FailedException
  91. */
  92. public function userWithdraw()
  93. {
  94. // 接收参数
  95. $params = $this->request->param();
  96. // 参数校验
  97. $valid = $this->validate($params, [
  98. 'realname|真实姓名' => 'require',
  99. 'type|收款方式' => 'require',
  100. // 'bank|开户行' => 'requireIf:type,1',
  101. 'account|收款账号' => 'require',
  102. 'amount|提现金额' => 'require',
  103. 'paycode|交易密码' => 'require'
  104. ]);
  105. // 错误返回
  106. if(true !== $valid){
  107. return $this->ApiJson(-1, $valid);
  108. }
  109. // 密码验证
  110. $user = $this->auth->user();
  111. if ($user['paycode'] !== $params['paycode']){
  112. return $this->ApiJson(-1, "交易密码有误,请检查!");
  113. }
  114. // 资金是不是提现之后再扣减还是直接扣减,驳回的时候再返回
  115. // 用户余额限制
  116. if ($user['balance'] <= sys_config('user_withdraw_limit','user')){
  117. return $this->ApiJson(-1, "当前可提现金额不满足!余额:【". $user['balance'] . "】");
  118. }
  119. // 最低限制
  120. if ($params['amount'] <= ($limit = sys_config('user_withdraw_limit','user'))){
  121. // return $this->ApiJson(-1, "申请提现金额不满足最低提现!最低:【" . $limit . "】");
  122. }
  123. // 最高限制
  124. if ($user['balance'] <= $params['amount']){
  125. return $this->ApiJson(-1, "当前可提现金额不满足!余额:【". $user['balance'] . "】");
  126. }
  127. // 写入用户ID
  128. $params['user_id'] = $this->auth->user()['id'];
  129. // 交易单号
  130. $params['draw_no'] = get_order_no();
  131. // p($params, 1);
  132. // 写入数据
  133. $result = false;
  134. Db::startTrans();
  135. try {
  136. $params['status'] = 2;
  137. $ret = model('common/UsersWithdraw')::create($params,true);
  138. // 加载配置
  139. $wechat = sys_config('', 'wechat');
  140. $config = [
  141. // 前面的appid什么的也得保留哦
  142. 'app_id' => $wechat['mini_appid'],
  143. 'mch_id' => $wechat['pay_mch_id'],
  144. 'key' => $wechat['pay_secret_key'],
  145. // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书)
  146. 'cert_path' => $wechat['cert_path'], // XXX: 绝对路径!!!!
  147. 'key_path' => $wechat['key_path'], // XXX: 绝对路径!!!!
  148. // 'notify_url' => 'https://api.gxrrj.cn/api/v1/wechat/notify',
  149. // 'notify_url' => 'http://rrj.gxnwsoft.com/api/v1/wechat/refundNotify',
  150. // 'sandbox' => true
  151. ];
  152. // 创建应用实例
  153. $app = Factory::payment($config);
  154. $result = $app->transfer->toBalance([
  155. 'partner_trade_no' => $ret['draw_no'], // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号)
  156. 'openid' => $user['open_id'],
  157. 'check_name' => 'FORCE_CHECK', // NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名
  158. 're_user_name' => $ret['realname'], // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名
  159. 'amount' => $ret['amount'] * 100, // 企业付款金额,单位为分
  160. 'desc' => '用户提现', // 企业付款操作说明信息。必填
  161. ]);
  162. $result = $result['return_code'] == 'SUCCESS' && $result['result_code'] != 'FAIL';
  163. Db::commit();
  164. }
  165. catch(Exception $e) {
  166. Db::rollback();
  167. }
  168. if (!$result){
  169. return $this->ApiJson(-1, '数据异常,请稍后重试');
  170. }
  171. return $this->ApiJson(0, '更新信息成功');
  172. }
  173. /**
  174. *
  175. * @author 许祖兴 < zuxing.xu@lettered.cn>
  176. * @date 2020/7/2 10:50
  177. *
  178. * @return \think\response\Json
  179. * @throws \Lettered\Support\Exceptions\FailedException
  180. */
  181. public function userVerify()
  182. {
  183. // 获取信息
  184. $verify = model('common/UsersVerify')->getBy(['user_id' => $this->auth->user()['id']]);
  185. // 这简单做,get 查状态 post 修改数据
  186. if ($this->request->isPost()){
  187. // 接收参数
  188. $params = $this->request->param();
  189. // 参数校验
  190. $valid = $this->validate($params, [
  191. 'name|真实姓名' => 'require',
  192. 'id_card|身份证号' => 'require',
  193. 'id_card_img|身份证信息' => 'require'
  194. ]);
  195. // 错误返回
  196. if(true !== $valid){
  197. return $this->ApiJson(-1, $valid);
  198. }
  199. // 取得当前用户
  200. $user = $this->auth->user();
  201. if (!$verify) {
  202. // 写入用户ID
  203. $params['user_id'] = $user['id'];
  204. // 写入数据
  205. $ret = model('common/UsersVerify')::create($params,true);
  206. }else {
  207. // 更新数据
  208. $ret = $verify->updateBy($verify['id'], $params);
  209. }
  210. // 提交或者创建,用户这都是待审核状态 1
  211. model('common/Users')->updateBy($user['id'], [
  212. 'is_verify' => 1
  213. ]);
  214. // 消息
  215. if ($ret) {
  216. return $this->ApiJson(0,'身份信息提交成功,请等待审核');
  217. }
  218. return $this->ApiJson(-1,'数据异常,请稍后再试');
  219. }
  220. return $this->ApiJson(0,'获取信息成功', $verify);
  221. }
  222. /**
  223. * 获取用户资金记录
  224. * 资金记录表和资产记录表应该可以合并为一张表,然后字段区分
  225. *
  226. * @author 许祖兴 < zuxing.xu@lettered.cn>
  227. * @date 2020/7/9 11:39
  228. *
  229. * @return \think\response\Json
  230. * @throws \Lettered\Support\Exceptions\FailedException
  231. * @throws \think\db\exception\DataNotFoundException
  232. * @throws \think\db\exception\ModelNotFoundException
  233. * @throws \think\exception\DbException
  234. */
  235. public function getUserBalance()
  236. {
  237. $param = $this->request->param();
  238. $limit = 10;
  239. // 数据校验
  240. $valid = $this->validate($param, [
  241. 'page' => 'require',
  242. ]);
  243. // 错误
  244. if (true !== $valid) {
  245. return $this->ApiJson(-1, $valid);
  246. }
  247. $withdraw = [];
  248. switch ($param['type']){
  249. case "balance":
  250. $model = "UsersBalanceRecord";
  251. break;
  252. case "property":
  253. $model = "UsersPropertyRecord";
  254. break;
  255. default :
  256. $model = "UsersWithdraw";
  257. }
  258. // 按月份
  259. for($month = 1; $month <= date('m'); $month ++ ){
  260. $data = model('common/' . $model)
  261. ->where(['user_id' => $this->auth->user()['id']])
  262. ->field("*,FROM_UNIXTIME(created_at, '%Y-%m-%d %H:%i:%s') as created_at")
  263. ->whereTime('created_at', 'between', $this->getMonthTime($month))
  264. // ->limit((($param['page'] - 1) * $limit) . "," . $limit)
  265. ->order(['id' => 'desc', 'updated_at' => 'desc'])
  266. ->select();
  267. if (count($data) != 0)
  268. $withdraw[date('Y') . $month] = $data;
  269. }
  270. return $this->ApiJson(0, '获取信息成功', $withdraw);
  271. }
  272. private function getMonthTime($month)
  273. {
  274. //
  275. $firstday = date('Y-m-01', strtotime(date('Y') . '-' . $month . '-1'));
  276. $lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));
  277. return array($firstday,$lastday);
  278. }
  279. /**
  280. * 获取用户分享二维码
  281. * 1.自己的码还是小程序码?
  282. *
  283. * @author 许祖兴 < zuxing.xu@lettered.cn>
  284. * @date 2020/6/30 15:59
  285. *
  286. * @return \think\response\Json
  287. */
  288. public function getUserSpread()
  289. {
  290. // 生成小程序码
  291. // 1. 是否生成
  292. // 2. 为生成创建返回/直接返回
  293. //$Qr = (new Qrcode())->createServer("/pages/index/index?spd=RYVBJKC");
  294. // return $this->ApiJson(0,'',$Qr);
  295. }
  296. /**
  297. *
  298. * @author 许祖兴 < zuxing.xu@lettered.cn>
  299. * @date 2020/7/2 16:16
  300. *
  301. * @return \think\response\Json
  302. * @throws \Lettered\Support\Exceptions\FailedException
  303. */
  304. public function joinInStore()
  305. {
  306. // 获取信息
  307. $store = model('common/Seller')->getBy(['user_id' => $this->auth->user()['id']]);
  308. // 这简单做,get 查状态 post 修改数据
  309. if ($this->request->isPost()){
  310. // 接收参数
  311. $params = $this->request->param();
  312. // 参数校验
  313. $valid = $this->validate($params, [
  314. 'area_id|区域信息' => 'require',
  315. 'lng|经度位置' => 'require',
  316. 'lat|维度位置' => 'require',
  317. 'contact|联系人' => 'require',
  318. 'seller_name|店铺信息' => 'require',
  319. 'products|主营产品' => 'require',
  320. 'mobile|手机号' => 'require',
  321. 'province|详细地址' => 'require',
  322. 'city|详细地址' => 'require',
  323. 'country|详细地址' => 'require',
  324. 'address|详细地址' => 'require',
  325. 'fd_img|门店照片' => 'require',
  326. 'bi_license|营业执照' => 'require',
  327. ]);
  328. // 错误返回
  329. if(true !== $valid){
  330. return $this->ApiJson(-1, $valid);
  331. }
  332. // 验证码
  333. // $sms = new SmsCode();
  334. // if (!$sms->verify(input('mobile'),input('vercode'))) {
  335. // return $this->ApiJson(-1, "验证码错误!");
  336. // }
  337. // 再次验证身份信息
  338. $verify = model("common/UsersVerify")
  339. ->getBy(['user_id' => $this->auth->user()['id']]);
  340. if($verify['status'] != 2){
  341. return $this->ApiJson(-1, "身份验证尚未完成,请完善后再试!");
  342. }
  343. // 用户身份信息复用
  344. $params['id_card'] = $verify['id_card'];
  345. $params['id_card_img'] = $verify['id_card_img'];
  346. if (!$store) {
  347. // 写入用户信息 身份证信息
  348. $params['user_id'] = $this->auth->user()['id'];
  349. // 写入数据
  350. $ret = model('common/Seller')::create($params,true);
  351. }else {
  352. // 更新数据
  353. $ret = $store->updateBy($store['id'], $params);
  354. }
  355. // 消息
  356. if ($ret) {
  357. return $this->ApiJson(0,'入驻信息提交成功,请等待审核');
  358. }
  359. return $this->ApiJson(-1,'数据异常,请稍后再试');
  360. }
  361. return $this->ApiJson(0,'获取信息成功', $store);
  362. }
  363. /**
  364. * 代理统计
  365. *
  366. * @author 许祖兴 < zuxing.xu@lettered.cn>
  367. * @date 2020/7/10 16:43
  368. *
  369. * @return \think\response\Json
  370. * @throws \Lettered\Support\Exceptions\FailedException
  371. * @throws \think\db\exception\DataNotFoundException
  372. * @throws \think\db\exception\ModelNotFoundException
  373. * @throws \think\exception\DbException
  374. */
  375. public function userAgent()
  376. {
  377. // 接收参数
  378. $params = $this->request->param();
  379. // 参数校验
  380. $valid = $this->validate($params, [
  381. 'area_id|地区数据' => 'require'
  382. ]);
  383. // 错误返回
  384. if(true !== $valid){
  385. return $this->ApiJson(-1, $valid);
  386. }
  387. // 1. 查我的代理信息
  388. $agent = model('common/UsersAgent')->getBy(['user_id' => $this->auth->user()['id']]);
  389. // 我是代理
  390. if ($agent && $agent['status'] == 2){
  391. // 1. 查我代理区域的订单信息和营业额信息
  392. $where = ['area_id' => $agent['area_id']];
  393. // 商品订单统计
  394. // 摩的订单统计
  395. // 配送订单统计
  396. // 技能订单统计
  397. $data = [
  398. 'goods' => db('goods_order')->where($where)->field("count(id) as total_order,sum(pay_price) as total_price")->find(),
  399. 'motor' => db('taxi_order')->where($where)->field("count(id) as total_order,sum(price) as total_price")->find(),
  400. 'skill' => db('skill_order')->where($where)->field("count(id) as total_order,sum(price) as total_price")->find(),
  401. 'mission' => db('mission_order')->where($where)->field("count(id) as total_order,sum(price) as total_price")->find(),
  402. ];
  403. $total_order = 0;
  404. $total_fee = 0;
  405. foreach ($data as $item){
  406. $total_order += $item['total_order'];
  407. $total_fee += $item['total_price'];
  408. }
  409. // 2. 我的区域信息
  410. $info['area'] = db('china')->where(['id' => $agent['area_id']])->value('name');
  411. // 总营业额
  412. $info['total_fee'] = sprintf("%.2f",$total_fee);
  413. // 总订单
  414. $info['total_order'] = $total_order;
  415. // 商户统计
  416. $info['total_store'] = db('seller')->where(['area_id' => $agent['area_id']])->count();
  417. return $this->ApiJson(0,'获取信息成功',[
  418. 'info' => $info,
  419. 'data' => $data,
  420. 'agent' => $agent
  421. ]);
  422. }
  423. // 获取当前地区已经申请通过的
  424. $pass = model('common/UsersAgent')->where('area_id','like', substr($params['area_id'], 0, strlen($params['area_id']) - 2) . '%' )
  425. ->where('status','=','2')->select();
  426. $area = model('common/China')->findBy($params['area_id']);
  427. $model = model('common/China');
  428. $where = [];
  429. foreach ($pass as $p){
  430. $where[] = ['id','<>', $p['area_id']];
  431. }
  432. $areas = $model->where($where)->where(['parent_id' => $area['parent_id']])->select();
  433. // ->where('id', ['>', 0], ['<>', 10], 'and')
  434. return $this->ApiJson(0,'获取信息成功', ['agent' => $agent,'areas' => $areas]);
  435. }
  436. /**
  437. * 月订单统计和列表
  438. *
  439. * @author 许祖兴 < zuxing.xu@lettered.cn>
  440. * @date 2020/7/13 10:11
  441. *
  442. * @return \think\response\Json
  443. * @throws \think\db\exception\DataNotFoundException
  444. * @throws \think\db\exception\ModelNotFoundException
  445. * @throws \think\exception\DbException
  446. */
  447. public function userAgentMonth()
  448. {
  449. // 接收参数
  450. $params = $this->request->param();
  451. $limit = 10;
  452. // 参数校验
  453. $valid = $this->validate($params, [
  454. 'area_id|地区数据' => 'require',
  455. 'otype|订单类型' => 'require',
  456. 'month|记录月份' => 'require',
  457. 'page' => 'require',
  458. ]);
  459. // 错误返回
  460. if(true !== $valid){
  461. return $this->ApiJson(-1, $valid);
  462. }
  463. switch ($params['otype']){
  464. case "goods":
  465. $model = "GoodsOrder";
  466. break;
  467. case "skill":
  468. $model = "SkillOrder";
  469. break;
  470. case "motor":
  471. $model = "TaxiOrder";
  472. break;
  473. case "mission":
  474. $model = "MissionOrder";
  475. break;
  476. default :
  477. $model = "GoodsOrder";
  478. }
  479. // 查询字段
  480. $price_field = ($params['otype'] == 'goods') ? 'pay_price' : 'price';
  481. // 月份处理
  482. list($year, $month) = str2arr($params['month'],'-');
  483. // 数据以及订单
  484. $data = model('common/' . $model)
  485. ->where(['area_id' => $params['area_id']])
  486. ->field("FROM_UNIXTIME(created_at,'%Y-%m') as month,count(id) as total_order,sum($price_field) total_price")
  487. ->whereTime('created_at', 'between', [$params['month'] . '-1', $year . '-' . ($month + 1) . '-1'])
  488. ->group('month')
  489. ->find();
  490. $data['order'] = model('common/' . $model)
  491. ->where(['area_id' => $params['area_id']])
  492. ->whereTime('created_at', 'between', [$params['month'] . '-1', $year . '-' . ($month + 1) . '-1'])
  493. ->limit((($params['page'] - 1) * $limit) . "," . $limit)
  494. ->select();
  495. return $this->ApiJson(0,'获取信息成功', $data);
  496. }
  497. /**
  498. * 提交申请
  499. *
  500. * @author 许祖兴 < zuxing.xu@lettered.cn>
  501. * @date 2020/8/28 9:08
  502. *
  503. * @return \think\response\Json
  504. * @throws \Lettered\Support\Exceptions\FailedException
  505. * @throws \think\db\exception\DataNotFoundException
  506. * @throws \think\db\exception\ModelNotFoundException
  507. * @throws \think\exception\DbException
  508. */
  509. public function userAgentApply()
  510. {
  511. // 接收参数
  512. $params = $this->request->param();
  513. // 参数校验
  514. $valid = $this->validate($params, [
  515. 'area_id|地区数据' => 'require'
  516. ]);
  517. // 错误返回
  518. if(true !== $valid){
  519. return $this->ApiJson(-1, $valid);
  520. }
  521. // 先看是否已经有这个区域代理了
  522. if (model('common/UsersAgent')->getBy(['area_id' => $params['area_id'],'status' => 2])){
  523. // 查找其他区域
  524. $area = model('common/China')->findBy($params['area_id']);
  525. $parent = model('common/China')->where('id','<>',$params['area_id'])
  526. ->where(['parent_id' => $area['parent_id']])->select();
  527. return $this->ApiJson(-1, "抱歉,当前区域已经存在代理,请选择其他区域申请!");
  528. }
  529. // 查找
  530. $agent = model('common/UsersAgent')
  531. ->getBy(['user_id' => $this->auth->user()['id'], 'area_id' => $params['area_id']]);
  532. // 写入用户信息 身份证信息
  533. $params['user_id'] = $this->auth->user()['id'];
  534. // 更新用户信息
  535. model('common/Users')->updateBy($params['user_id'],['is_agent' => 1]);
  536. if (!$agent) {
  537. // 写入数据
  538. $ret = model('common/UsersAgent')::create([
  539. 'user_id' => $params['user_id'],
  540. 'area_id' => $params['area_id']
  541. ]);
  542. }else {
  543. // 更新数据
  544. $ret = $agent->updateBy($agent['id'], [
  545. 'area_id' => $params['area_id'],
  546. 'status' => 1
  547. ]);
  548. }
  549. // 消息
  550. if ($ret){
  551. return $this->ApiJson(0,'提交成功,请等待管理员审核!', $ret);
  552. }
  553. return $this->ApiJson(-1,'数据异常,请稍后重试!');
  554. }
  555. /**
  556. * 配送员申请
  557. *
  558. * @author 许祖兴 < zuxing.xu@lettered.cn>
  559. * @date 2020/7/10 17:30
  560. *
  561. * @return \think\response\Json
  562. * @throws \Lettered\Support\Exceptions\FailedException
  563. */
  564. public function deliveryApply()
  565. {
  566. // 查找
  567. $missionUser = model('common/MissionUser')
  568. ->getBy(['user_id' => $this->auth->user()['id']]);
  569. if ($this->request->isPost()){
  570. // 接收参数
  571. $params = $this->request->param();
  572. $valid = $this->validate($params, [
  573. 'hl_license|健康证明' => 'require',
  574. 'province|省份' => 'require',
  575. 'city|城市' => 'require',
  576. 'country|地区' => 'require',
  577. 'area|地区数据' => 'require',
  578. 'address|区域详情' => 'require',
  579. ]);
  580. // 错误返回
  581. if(true !== $valid){
  582. return $this->ApiJson(-1, $valid);
  583. }
  584. // 再次验证身份信息
  585. $verify = model("common/UsersVerify")
  586. ->getBy(['user_id' => $this->auth->user()['id']]);
  587. if($verify['status'] != 2){
  588. return $this->ApiJson(-1, "身份验证尚未完成,请完善后再试!");
  589. }
  590. // 用户身份信息复用
  591. $params['uname'] = $verify['name'];
  592. $params['id_card'] = $verify['id_card'];
  593. $params['id_card_img'] = $verify['id_card_img'];
  594. $params['status'] = 1;
  595. if (!$missionUser) {
  596. // 写入用户信息 身份证信息
  597. $params['user_id'] = $this->auth->user()['id'];
  598. // 写入数据
  599. $ret = model('common/MissionUser')::create($params, true);
  600. }else {
  601. // 更新数据
  602. $ret = $missionUser->updateBy($missionUser['id'],$params);
  603. }
  604. // 消息
  605. if ($ret){
  606. return $this->ApiJson(0,'提交成功,请等待管理员审核!');
  607. }
  608. return $this->ApiJson(-1,'数据异常,请稍后重试!');
  609. }
  610. return $this->ApiJson(0,'获取信息成功', $missionUser);
  611. }
  612. /**
  613. * 用户文件上传
  614. *
  615. * @author 许祖兴 < zuxing.xu@lettered.cn>
  616. * @date 2020/7/2 9:09
  617. *
  618. * @return \think\response\Json
  619. */
  620. public function uploadUserFile()
  621. {
  622. // 接收数据
  623. $params = $this->request->param();
  624. // 参数校验
  625. $valid = $this->validate($params, [
  626. 'action|上传操作' => 'require'
  627. ]);
  628. // 错误返回
  629. if(true !== $valid){
  630. return $this->ApiJson(-1, $valid);
  631. };
  632. // 上传
  633. $upload = new Upload(config('upload.'));
  634. $ret = $upload->setPath( '/' . $params['action'])->upload($this->request->file('file'));
  635. return $this->ApiJson(0,'', get_annex_url($ret));
  636. }
  637. }