UserOrder.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\UserApi;
  4. use app\service\Pet;
  5. use app\service\UserOrderService;
  6. use app\UserException;
  7. use app\validate\UserOrderValidate;
  8. use think\Exception;
  9. /**
  10. * 用户端订单接口
  11. */
  12. class UserOrder extends UserApi
  13. {
  14. protected $noNeedLogin = ['category','spec','protect'];
  15. protected $noNeedRight = '*';
  16. /**
  17. * 常用地址
  18. * @ApiReturnParams (name=id,description=id)
  19. * @ApiReturnParams (name=name,description=姓名)
  20. * @ApiReturnParams (name=mobile,description=手机号)
  21. * @ApiReturnParams (name=address,description=地址)
  22. * @ApiReturnParams (name=city,description=城市)
  23. */
  24. public function address(){
  25. $user=$this->auth->getUser();
  26. $this->success('',$user->address()->order('id','desc')->select());
  27. }
  28. /**
  29. * 宠物类别
  30. * @ApiReturnParams (name=id,description=id)
  31. * @ApiReturnParams (name=name,description=名称)
  32. */
  33. public function category(Pet $pet){
  34. $this->success('',$pet::category());
  35. }
  36. /**
  37. * 宠物规格
  38. * @ApiReturnParams (name=id,description=id)
  39. * @ApiReturnParams (name=name,description=名称)
  40. * @ApiReturnParams (name=weight,description=重量范围)
  41. */
  42. public function spec(Pet $pet){
  43. $this->success('',$pet::spec());
  44. }
  45. /**
  46. * 宠物保
  47. * @ApiReturnParams (name=id,description=id)
  48. * @ApiReturnParams (name=name,description=名称)
  49. * @ApiReturnParams (name=max,description=最高保多少)
  50. * @ApiReturnParams (name=price,description=价格)
  51. */
  52. public function protect(Pet $pet){
  53. $this->success('',$pet::protect());
  54. }
  55. /**
  56. * 预下单
  57. * @ApiMethod (POST)
  58. * @param array from_addr 必须,取宠地址信息
  59. * @param string from_addr[longitude] 必须,取宠地址经度
  60. * @param string from_addr[latitude] 必须,取宠地址纬度
  61. * @param string from_addr[name] 必须,取宠人
  62. * @param string from_addr[mobile] 必须,取宠手机号
  63. * @param string from_addr[city] 必须,取宠城市
  64. * @param string from_addr[address] 必须,取宠详细地址
  65. * @param array to_addr 必须,收宠地址信息
  66. * @param string to_addr[longitude] 必须,收宠地址经度
  67. * @param string to_addr[latitude] 必须,收宠地址纬度
  68. * @param string to_addr[name] 必须,收宠人
  69. * @param string to_addr[mobile] 必须,收宠手机号
  70. * @param string to_addr[city] 必须,收宠城市
  71. * @param string to_addr[address] 必须,收宠详细地址
  72. * @param string pick_up 0无1上门接2上门送4上门接送
  73. * @param string agree_time 取宠时间
  74. * @param string pet_category 宠物分类ID
  75. * @param string num 宠物数量
  76. * @param string weight 宠物重量
  77. * @param string spec 宠物规格
  78. * @param string piece 宠物件数
  79. * @param string has_cage 有无宠具0无1有
  80. * @param string remark 备注信息
  81. * @param string images 照片
  82. * @param string protect_id 安心保ID
  83. * @param string coupon_id 优惠券ID
  84. * @param string freight fast快车air空运special专车
  85. *
  86. * @ApiReturnParams (name=total_amount,type=string,description=总价)
  87. * @ApiReturnParams (name=coupon_amount,type=string,description=优惠券优惠金额)
  88. * @ApiReturnParams (name=real_amount,type=string,description=实付总价)
  89. * @ApiReturnParams (name=freights[0][price],type=string,description=实际价格)
  90. * @ApiReturnParams (name=freights[0][total_price],type=string,description=总价)
  91. * @ApiReturnParams (name=freights[0][type],type=string,description=类型:fast快车air空运special专车)
  92. * @ApiReturnParams (name=freights[0][coupon][0][amount],type=string,description=优惠券优惠额度)
  93. * @ApiReturnParams (name=freights[0][coupon][0][end_time],type=string,description=优惠券过期时间)
  94. * @ApiReturnParams (name=freights[0][coupon][0][id],type=string,description=优惠券id)
  95. * @ApiReturnParams (name=freights[0][coupon][0][is_used],type=string,description=优惠券实付已使用)
  96. * @ApiReturnParams (name=freights[0][coupon][0][max],type=string,description=优惠券满多少可以减)
  97. * @ApiReturnParams (name=freights[0][coupon][0][selected],type=string,description=实付是选中的优惠券)
  98. * @ApiReturnParams (name=freights[0][coupon][0][start_time],type=string,description=优惠券开始时间)
  99. * @ApiReturnParams (name=freights[0][coupon][0][type],type=string,description="优惠券类型,1代金券2满减券3折扣券4新用户下单券")
  100. * @ApiReturnParams (name=freights[0][coupon][0][type_desc],type=string,description=优惠券类型)
  101. */
  102. public function prepare(UserOrderService $userOrder){
  103. $data=input();
  104. $this->validate($data,UserOrderValidate::class);
  105. $user=$this->auth->getUser();
  106. if(!empty($data['freight'])){
  107. $this->validate($data,UserOrderValidate::$freight);
  108. }
  109. try {
  110. $data=$userOrder->setUser($user)
  111. ->import($data)
  112. ->setCoupon($data['coupon_id']??null)
  113. ->prepare();
  114. $this->success('',$data);
  115. }catch (UserException $e){
  116. $this->error($e->getMessage());
  117. }
  118. }
  119. }