* @date 2020/7/3 16:16 * * @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/Skill') ->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 getSkillByID($id) { (new IDMustBePositiveInt())->valid(); $taxi = model('common/Skill')->with(['user']) ->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, [ 'skill_id|关联服务' => 'require', 'skill_user_id|关联服务师傅' => 'require', 'price|价格' => '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/SkillOrder')->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' => 'skill' // 归属订单 ]); // 返回支付单号 return $this->ApiJson(0,'订单提交成功', $trade_no); } return $this->ApiJson(-1,'发生异常,请骚后重试...'); } /** * 获取订单列表 * * @author 许祖兴 < zuxing.xu@lettered.cn> * @date 2020/7/6 10:58 * * @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/SkillOrder') ->where(['user_id' => $this->auth->user()['id']]) ->limit((($param['page'] - 1) * $limit) . "," . $limit) ->order(['created_at' => 'desc']) ->select(); return $this->ApiJson(0,'获取成功', $orders); } }