User.php 25 KB

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