Order.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace app\data\controller\api;
  3. use app\data\model\ShopGoodsCart;
  4. use app\data\model\ShopGoods;
  5. use app\data\model\ShopGoodsItem;
  6. use app\data\model\ShopOrder;
  7. use app\data\model\ShopOrderItem;
  8. use app\data\service\OrderService;
  9. use think\admin\Controller;
  10. use hg\apidoc\annotation\Title;
  11. use hg\apidoc\annotation\Method;
  12. use hg\apidoc\annotation\Param;
  13. use hg\apidoc\annotation\Returned;
  14. /**
  15. * 商品订单接口
  16. * Class Order
  17. * @package app\data\controller\api
  18. */
  19. class Order extends Auth
  20. {
  21. /**
  22. * @Title("商品规格下单")
  23. * @Method("post")
  24. * @Param("admin_id",desc="商家id")
  25. * @Param("item_id",desc="规格id")
  26. * @Param("num",desc="数量")
  27. * @Param ("address_id",desc="地址id")
  28. */
  29. public function order_create(){
  30. $user = $this->getUser();
  31. $item_id =input('item_id');
  32. $address_id=input('address_id');
  33. $number = input('number');
  34. $data=[
  35. 'uuid'=>$user['id'],
  36. 'address_id'=>$address_id,
  37. 'item_id'=>$item_id,
  38. 'number'=>$number,
  39. ];
  40. $shop_order_model = new ShopOrder();
  41. $pay_on = $shop_order_model->order_create($data);
  42. $this->success('快去支付吧',$pay_on);
  43. }
  44. /**
  45. * @Title("购物车下单")
  46. * @Method("post")
  47. * @Param("cart_ids",desc="购物车id(数组)")
  48. * @Param ("address_id",desc="地址id")
  49. */
  50. public function crat_create(){
  51. $user =$this->getUser();
  52. $cart_ids = input('cart_ids');
  53. // $cart_ids=array(1,2);
  54. $address_id = input('address_id');
  55. $data=[
  56. 'uuid'=>$user['id'],
  57. 'cart_ids'=>$cart_ids,
  58. 'address_id'=>$address_id,
  59. ];
  60. $shop_order_model = new ShopOrder();
  61. $pay_on = $shop_order_model->cart_create($data);
  62. $this->success('快去支付吧',$pay_on);
  63. }
  64. /**
  65. * @Title("我的订单")
  66. * @Method("post")
  67. * @Param("order_name",desc="搜索名称")
  68. * @Param ("status",desc="1全部 2 待支付 3代发货 4 待收货 5退款/已退款")
  69. */
  70. public function order_list(){
  71. $user = $this->getUser();
  72. $status = input('status',1);
  73. if(!empty($status)){
  74. switch ($status){
  75. case 1:
  76. $array = [0,1,2,3,4,5,6,7];
  77. break;
  78. case 2:
  79. $array = [2];
  80. break;
  81. case 3:
  82. $array = [4];
  83. break;
  84. case 4:
  85. $array = [5];
  86. break;
  87. case 5:
  88. $array = [6,7];
  89. break;
  90. }
  91. }
  92. $query = ShopOrder::mQuery()->like('order_name');
  93. $list = $query ->where('uuid',$user['id'])
  94. ->whereIn('status',$array)->order('id desc')->page(true, false, false, 10);
  95. foreach ($list['list'] as $k=>$v){
  96. $list['list'][$k]['goods_item']=ShopOrderItem::mk()->where('order_no',$list['list'][$k]['order_no'])->select();
  97. }
  98. $this->success('我的订单列表',$list);
  99. }
  100. /**
  101. * @Title ("申请退款")
  102. * @Method ("post")
  103. * @Param ("order_id",desc="订单id")
  104. * @Param ("reason",desc="退款原因")
  105. * @Param("desc",desc="描述
  106. * ")
  107. */
  108. public function refund(){
  109. $user = $this->getUser();
  110. $order_id = input('order_id');
  111. $refund_money = ShopOrder::mk()->where(array('uuid'=>$user['id'],'order_id'=>$order_id))->value('payment_amount');
  112. $refund_reason = input('reason');
  113. if(empty($refund_reason)){
  114. $this->error('退款原因不能为空');
  115. }
  116. $refund_desc = input('desc');
  117. ShopOrder::mk()->where(array('uuid'=>$user['id'],'order_id'=>$order_id))->save(['refund_money'=>$refund_money,'refund_reason'=>$refund_reason,'refund_desc'=>$refund_desc,'status'=>6]);
  118. $this->success('退款已提交');
  119. }
  120. }