| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- namespace app\api\controller\v1;
- use app\api\controller\ApiController;
- use app\common\validate\IDMustBePositiveInt;
- use EasyWeChat\Factory;
- class Skill extends ApiController
- {
- /**
- * 技能列表
- *
- * @url GET /skill/nearby?page=1
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @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);
- }
- }
|