Skill.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\ApiController;
  4. use app\common\validate\IDMustBePositiveInt;
  5. use EasyWeChat\Factory;
  6. class Skill extends ApiController
  7. {
  8. /**
  9. * 技能列表
  10. *
  11. * @url GET /skill/nearby?page=1
  12. * @author 许祖兴 < zuxing.xu@lettered.cn>
  13. * @date 2020/7/3 16:16
  14. *
  15. * @return \think\response\Json
  16. * @throws \think\db\exception\DataNotFoundException
  17. * @throws \think\db\exception\ModelNotFoundException
  18. * @throws \think\exception\DbException
  19. */
  20. public function getNearby()
  21. {
  22. $param = $this->request->param();
  23. $limit = 10;
  24. // 数据校验
  25. $valid = $this->validate($param, [
  26. 'page' => 'require',
  27. ]);
  28. // 错误
  29. if (true !== $valid){
  30. return $this->ApiJson(-1,$valid);
  31. }
  32. //
  33. $taxi = model('common/Skill')
  34. ->where([ 'status' => 1])
  35. ->limit((($param['page'] - 1) * $limit) . "," . $limit)
  36. ->select();
  37. return $this->ApiJson(0,'获取成功', $taxi);
  38. }
  39. /**
  40. * 技能详情
  41. *
  42. * @url GET /taxi/nearby?page=1
  43. * @author 许祖兴 < zuxing.xu@lettered.cn>
  44. * @date 2020/7/3 16:16
  45. *
  46. * @param $id
  47. * @return \think\response\Json
  48. * @throws \Lettered\Support\Exceptions\EvidentException
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. * @throws \think\exception\DbException
  52. */
  53. public function getSkillByID($id)
  54. {
  55. (new IDMustBePositiveInt())->valid();
  56. $taxi = model('common/Skill')->with(['user'])
  57. ->find($id);
  58. if (!$taxi){
  59. return $this->ApiJson(-1, '不存在技能编号');
  60. }
  61. return $this->ApiJson(0, '获取技能信息成功', $taxi);
  62. }
  63. /**
  64. * 技能服务
  65. *
  66. * @author 许祖兴 < zuxing.xu@lettered.cn>
  67. * @date 2020/7/3 16:29
  68. *
  69. * @return \think\response\Json
  70. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  71. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  72. * @throws \GuzzleHttp\Exception\GuzzleException
  73. * @throws \Lettered\Support\Exceptions\FailedException
  74. */
  75. public function userServe()
  76. {
  77. $params = $this->request->param();
  78. // 参数校验
  79. $valid = $this->validate($params, [
  80. 'skill_id|关联服务' => 'require',
  81. 'skill_user_id|关联服务师傅' => 'require',
  82. 'price|价格' => 'require'
  83. ]);
  84. // 错误返回
  85. if(true !== $valid){
  86. return $this->ApiJson(-1, $valid);
  87. };
  88. // 创建订单 -- 附加数据
  89. $params['order_no'] = get_order_no();
  90. $params['user_id'] = $this->auth->user()['id'];
  91. $orderId = model('common/SkillOrder')->storeBy($params);
  92. if ($orderId){
  93. // 创建对应支付记录
  94. $trade_no = get_order_no();
  95. model('common/OrderPaylog')->storeBy([
  96. 'out_trade_no' => $trade_no,
  97. 'total_price' => $params['price'],
  98. 'order_idx' => $orderId,
  99. 'ascription' => 'skill' // 归属订单
  100. ]);
  101. // 返回支付单号
  102. return $this->ApiJson(0,'订单提交成功', $trade_no);
  103. }
  104. return $this->ApiJson(-1,'发生异常,请骚后重试...');
  105. }
  106. /**
  107. * 获取订单列表
  108. *
  109. * @author 许祖兴 < zuxing.xu@lettered.cn>
  110. * @date 2020/7/6 10:58
  111. *
  112. * @return \think\response\Json
  113. * @throws \Lettered\Support\Exceptions\FailedException
  114. * @throws \think\db\exception\DataNotFoundException
  115. * @throws \think\db\exception\ModelNotFoundException
  116. * @throws \think\exception\DbException
  117. */
  118. public function order()
  119. {
  120. $param = $this->request->param();
  121. $limit = 10;
  122. // 数据校验
  123. $valid = $this->validate($param, [
  124. 'page' => 'require',
  125. ]);
  126. // 错误
  127. if (true !== $valid) {
  128. return $this->ApiJson(-1, $valid);
  129. }
  130. $orders = model('common/SkillOrder')
  131. ->where(['user_id' => $this->auth->user()['id']])
  132. ->limit((($param['page'] - 1) * $limit) . "," . $limit)
  133. ->order(['created_at' => 'desc'])
  134. ->select();
  135. return $this->ApiJson(0,'获取成功', $orders);
  136. }
  137. }