Rescue.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 Rescue 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/Rescue')
  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 getRescueByID($id)
  54. {
  55. (new IDMustBePositiveInt())->valid();
  56. $taxi = model('common/Rescue')
  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. 'rescue_id|关联服务' => 'require',
  81. 'price|价格' => 'require',
  82. 'remark|服务内容' => 'require',
  83. 'arrive|送达位置' => 'require',
  84. 'address|详细位置' => 'require'
  85. ]);
  86. // 错误返回
  87. if(true !== $valid){
  88. return $this->ApiJson(-1, $valid);
  89. };
  90. // 创建订单 -- 附加数据
  91. $params['order_no'] = get_order_no();
  92. $params['user_id'] = $this->auth->user()['id'];
  93. $orderId = model('common/RescueOrder')->storeBy($params);
  94. if ($orderId){
  95. // 创建对应支付记录
  96. $trade_no = get_order_no();
  97. model('common/OrderPaylog')->storeBy([
  98. 'out_trade_no' => $trade_no,
  99. 'total_price' => $params['price'],
  100. 'order_idx' => $orderId,
  101. 'ascription' => 'rescue' // 归属订单
  102. ]);
  103. // 返回支付单号
  104. return $this->ApiJson(0,'订单提交成功', $trade_no);
  105. }
  106. return $this->ApiJson(-1,'发生异常,请骚后重试...');
  107. }
  108. /**
  109. * 获取订单列表
  110. *
  111. * @author 许祖兴 < zuxing.xu@lettered.cn>
  112. * @date 2020/7/6 10:58
  113. *
  114. * @return \think\response\Json
  115. * @throws \Lettered\Support\Exceptions\FailedException
  116. * @throws \think\db\exception\DataNotFoundException
  117. * @throws \think\db\exception\ModelNotFoundException
  118. * @throws \think\exception\DbException
  119. */
  120. public function order()
  121. {
  122. $param = $this->request->param();
  123. $limit = 10;
  124. // 数据校验
  125. $valid = $this->validate($param, [
  126. 'page' => 'require',
  127. ]);
  128. // 错误
  129. if (true !== $valid) {
  130. return $this->ApiJson(-1, $valid);
  131. }
  132. $orders = model('common/RescueOrder')
  133. ->where(['user_id' => $this->auth->user()['id']])
  134. ->limit((($param['page'] - 1) * $limit) . "," . $limit)
  135. ->order(['created_at' => 'desc'])
  136. ->select();
  137. return $this->ApiJson(0,'获取成功', $orders);
  138. }
  139. }