| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- <?php
- namespace app\api\controller\v1;
- use app\api\controller\ApiController;
- use app\api\service\SmsCode;
- use app\common\validate\IDMustBePositiveInt;
- use EasyWeChat\Factory;
- class Mission extends ApiController
- {
- /**
- * 获取配送列表
- *
- * @url GET /mission/nearby?page=1
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/7/6 08:46
- *
- * @return \think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getNearby()
- {
- $param = $this->request->param();
- $limit = 10;
- // 数据校验
- $valid = $this->validate($param, [
- 'page' => 'require',
- ]);
- // 错误
- if (true !== $valid){
- return $this->ApiJson(-1,$valid);
- }
- //
- $taxi = model('common/Mission')
- ->where([ 'status' => 1])
- ->limit((($param['page'] - 1) * $limit) . "," . $limit)
- ->select();
- return $this->ApiJson(0,'获取成功', $taxi);
- }
- /**
- * 技能详情
- *
- * @url GET /taxi/nearby?page=1
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/7/3 16:16
- *
- * @param $id
- * @return \think\response\Json
- * @throws \Lettered\Support\Exceptions\EvidentException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getMissionByID($id)
- {
- (new IDMustBePositiveInt())->valid();
- $taxi = model('common/Mission')
- ->find($id);
- if (!$taxi){
- return $this->ApiJson(-1, '不存在配送编号');
- }
- return $this->ApiJson(0, '获取配送信息成功', $taxi);
- }
- /**
- * 技能服务
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/7/3 16:29
- *
- * @return \think\response\Json
- * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
- * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
- * @throws \GuzzleHttp\Exception\GuzzleException
- * @throws \Lettered\Support\Exceptions\FailedException
- */
- public function userServe()
- {
- $params = $this->request->param();
- // 参数校验
- $valid = $this->validate($params, [
- 'mission_id|关联服务' => 'require',
- 'price|价格' => 'require',
- 'remark|服务内容' => 'require',
- 'arrive|送达位置' => 'require',
- 'address|详细位置' => 'require'
- ]);
- // 错误返回
- if(true !== $valid){
- return $this->ApiJson(-1, $valid);
- };
- // 创建订单 -- 附加数据
- $params['order_no'] = get_order_no();
- $params['user_id'] = $this->auth->user()['id'];
- $orderId = model('common/MissionOrder')->storeBy($params);
- if ($orderId){
- // 创建对应支付记录
- $trade_no = get_order_no();
- model('common/OrderPaylog')->storeBy([
- 'out_trade_no' => $trade_no,
- 'total_price' => $params['price'],
- 'order_idx' => $orderId,
- 'ascription' => 'mission' // 归属订单
- ]);
- // 返回支付单号
- return $this->ApiJson(0,'订单提交成功', $trade_no);
- }
- return $this->ApiJson(-1,'发生异常,请骚后重试...');
- }
- /**
- * 订单
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/7/8 11:09
- *
- * @return \think\response\Json
- * @throws \Lettered\Support\Exceptions\FailedException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function order()
- {
- $param = $this->request->param();
- $limit = 10;
- // 数据校验
- $valid = $this->validate($param, [
- 'page' => 'require',
- ]);
- // 错误
- if (true !== $valid) {
- return $this->ApiJson(-1, $valid);
- }
- $orders = model('common/missionOrder')
- ->where(['user_id' => $this->auth->user()['id']])
- ->limit((($param['page'] - 1) * $limit) . "," . $limit)
- ->order(['created_at' => 'desc'])
- ->select();
- return $this->ApiJson(0,'获取成功', $orders);
- }
- /**
- * 申请配送员
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/7/30 16:47
- *
- * @return \think\response\Json
- * @throws \Lettered\Support\Exceptions\FailedException
- */
- public function joinInStore()
- {
- // 获取信息
- $store = model('common/MissionUser')->getBy(['user_id' => $this->auth->user()['id']]);
- // 这简单做,get 查状态 post 修改数据
- if ($this->request->isPost()){
- // 接收参数
- $params = $this->request->param();
- // 参数校验
- $valid = $this->validate($params, [
- 'area_id|区域信息' => 'require'
- ]);
- // 错误返回
- if(true !== $valid){
- return $this->ApiJson(-1, $valid);
- }
- // 验证码
- $sms = new SmsCode();
- if (!$sms->verify(input('mobile'),input('vercode'))) {
- return $this->ApiJson(-1, "验证码错误!");
- }
- // 再次验证身份信息
- $verify = model("common/UsersVerify")
- ->getBy(['user_id' => $this->auth->user()['id']]);
- if($verify['status'] != 2){
- return $this->ApiJson(-1, "身份验证尚未完成,请完善后再试!");
- }
- // 用户身份信息复用
- $params['id_card'] = $verify['id_card'];
- $params['id_card_img'] = $verify['id_card_img'];
- if (!$store) {
- // 写入用户信息 身份证信息
- $params['user_id'] = $this->auth->user()['id'];
- // 写入数据
- $ret = model('common/Seller')::create($params,true);
- }else {
- // 更新数据
- $ret = $store->updateBy($store['id'], $params);
- }
- // 消息
- if ($ret) {
- return $this->ApiJson(0,'入驻信息提交成功,请等待审核');
- }
- return $this->ApiJson(-1,'数据异常,请稍后再试');
- }
- return $this->ApiJson(0,'获取信息成功', $store);
- }
- }
|