Mission.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\ApiController;
  4. use app\api\service\SmsCode;
  5. use app\common\validate\IDMustBePositiveInt;
  6. use EasyWeChat\Factory;
  7. class Mission extends ApiController
  8. {
  9. /**
  10. * 获取配送列表
  11. *
  12. * @url GET /mission/nearby?page=1
  13. * @author 许祖兴 < zuxing.xu@lettered.cn>
  14. * @date 2020/7/6 08:46
  15. *
  16. * @return \think\response\Json
  17. * @throws \think\db\exception\DataNotFoundException
  18. * @throws \think\db\exception\ModelNotFoundException
  19. * @throws \think\exception\DbException
  20. */
  21. public function getNearby()
  22. {
  23. $param = $this->request->param();
  24. $limit = 10;
  25. // 数据校验
  26. $valid = $this->validate($param, [
  27. 'page' => 'require',
  28. ]);
  29. // 错误
  30. if (true !== $valid){
  31. return $this->ApiJson(-1,$valid);
  32. }
  33. //
  34. $taxi = model('common/Mission')
  35. ->where([ 'status' => 1])
  36. ->limit((($param['page'] - 1) * $limit) . "," . $limit)
  37. ->select();
  38. return $this->ApiJson(0,'获取成功', $taxi);
  39. }
  40. /**
  41. * 技能详情
  42. *
  43. * @url GET /taxi/nearby?page=1
  44. * @author 许祖兴 < zuxing.xu@lettered.cn>
  45. * @date 2020/7/3 16:16
  46. *
  47. * @param $id
  48. * @return \think\response\Json
  49. * @throws \Lettered\Support\Exceptions\EvidentException
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. * @throws \think\exception\DbException
  53. */
  54. public function getMissionByID($id)
  55. {
  56. (new IDMustBePositiveInt())->valid();
  57. $taxi = model('common/Mission')
  58. ->find($id);
  59. if (!$taxi){
  60. return $this->ApiJson(-1, '不存在配送编号');
  61. }
  62. return $this->ApiJson(0, '获取配送信息成功', $taxi);
  63. }
  64. /**
  65. * 技能服务
  66. *
  67. * @author 许祖兴 < zuxing.xu@lettered.cn>
  68. * @date 2020/7/3 16:29
  69. *
  70. * @return \think\response\Json
  71. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  72. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  73. * @throws \GuzzleHttp\Exception\GuzzleException
  74. * @throws \Lettered\Support\Exceptions\FailedException
  75. */
  76. public function userServe()
  77. {
  78. $params = $this->request->param();
  79. // 参数校验
  80. $valid = $this->validate($params, [
  81. 'mission_id|关联服务' => 'require',
  82. 'price|价格' => 'require',
  83. 'remark|服务内容' => 'require',
  84. 'arrive|送达位置' => 'require',
  85. 'address|详细位置' => 'require'
  86. ]);
  87. // 错误返回
  88. if(true !== $valid){
  89. return $this->ApiJson(-1, $valid);
  90. };
  91. // 创建订单 -- 附加数据
  92. $params['order_no'] = get_order_no();
  93. $params['user_id'] = $this->auth->user()['id'];
  94. $orderId = model('common/MissionOrder')->storeBy($params);
  95. if ($orderId){
  96. // 创建对应支付记录
  97. $trade_no = get_order_no();
  98. model('common/OrderPaylog')->storeBy([
  99. 'out_trade_no' => $trade_no,
  100. 'total_price' => $params['price'],
  101. 'order_idx' => $orderId,
  102. 'ascription' => 'mission' // 归属订单
  103. ]);
  104. // 返回支付单号
  105. return $this->ApiJson(0,'订单提交成功', $trade_no);
  106. }
  107. return $this->ApiJson(-1,'发生异常,请骚后重试...');
  108. }
  109. /**
  110. * 订单
  111. *
  112. * @author 许祖兴 < zuxing.xu@lettered.cn>
  113. * @date 2020/7/8 11:09
  114. *
  115. * @return \think\response\Json
  116. * @throws \Lettered\Support\Exceptions\FailedException
  117. * @throws \think\db\exception\DataNotFoundException
  118. * @throws \think\db\exception\ModelNotFoundException
  119. * @throws \think\exception\DbException
  120. */
  121. public function order()
  122. {
  123. $param = $this->request->param();
  124. $limit = 10;
  125. // 数据校验
  126. $valid = $this->validate($param, [
  127. 'page' => 'require',
  128. ]);
  129. // 错误
  130. if (true !== $valid) {
  131. return $this->ApiJson(-1, $valid);
  132. }
  133. $orders = model('common/missionOrder')
  134. ->where(['user_id' => $this->auth->user()['id']])
  135. ->limit((($param['page'] - 1) * $limit) . "," . $limit)
  136. ->order(['created_at' => 'desc'])
  137. ->select();
  138. return $this->ApiJson(0,'获取成功', $orders);
  139. }
  140. /**
  141. * 申请配送员
  142. *
  143. * @author 许祖兴 < zuxing.xu@lettered.cn>
  144. * @date 2020/7/30 16:47
  145. *
  146. * @return \think\response\Json
  147. * @throws \Lettered\Support\Exceptions\FailedException
  148. */
  149. public function joinInStore()
  150. {
  151. // 获取信息
  152. $store = model('common/MissionUser')->getBy(['user_id' => $this->auth->user()['id']]);
  153. // 这简单做,get 查状态 post 修改数据
  154. if ($this->request->isPost()){
  155. // 接收参数
  156. $params = $this->request->param();
  157. // 参数校验
  158. $valid = $this->validate($params, [
  159. 'area_id|区域信息' => 'require'
  160. ]);
  161. // 错误返回
  162. if(true !== $valid){
  163. return $this->ApiJson(-1, $valid);
  164. }
  165. // 验证码
  166. $sms = new SmsCode();
  167. if (!$sms->verify(input('mobile'),input('vercode'))) {
  168. return $this->ApiJson(-1, "验证码错误!");
  169. }
  170. // 再次验证身份信息
  171. $verify = model("common/UsersVerify")
  172. ->getBy(['user_id' => $this->auth->user()['id']]);
  173. if($verify['status'] != 2){
  174. return $this->ApiJson(-1, "身份验证尚未完成,请完善后再试!");
  175. }
  176. // 用户身份信息复用
  177. $params['id_card'] = $verify['id_card'];
  178. $params['id_card_img'] = $verify['id_card_img'];
  179. if (!$store) {
  180. // 写入用户信息 身份证信息
  181. $params['user_id'] = $this->auth->user()['id'];
  182. // 写入数据
  183. $ret = model('common/Seller')::create($params,true);
  184. }else {
  185. // 更新数据
  186. $ret = $store->updateBy($store['id'], $params);
  187. }
  188. // 消息
  189. if ($ret) {
  190. return $this->ApiJson(0,'入驻信息提交成功,请等待审核');
  191. }
  192. return $this->ApiJson(-1,'数据异常,请稍后再试');
  193. }
  194. return $this->ApiJson(0,'获取信息成功', $store);
  195. }
  196. }