Ordercreate.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * Index.php
  4. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  5. * =========================================================
  6. * Copy right 2015-2025 杭州牛之云科技有限公司, 保留所有权利。
  7. * ----------------------------------------------
  8. * 官方网址: https://www.niushop.com
  9. * =========================================================
  10. * @author : niuteam
  11. * @date : 2022.8.8
  12. * @version : v5.0.0.1
  13. */
  14. namespace addon\bundling\api\controller;
  15. use app\api\controller\BaseApi;
  16. use addon\bundling\model\BundlingOrderCreate as OrderCreateModel;
  17. /**
  18. * 订单创建
  19. * @author Administrator
  20. *
  21. */
  22. class Ordercreate extends BaseApi
  23. {
  24. /**
  25. * 创建订单
  26. */
  27. public function create()
  28. {
  29. $token = $this->checkToken();
  30. if ($token[ 'code' ] < 0) return $this->response($token);
  31. $order_create = new OrderCreateModel();
  32. $data = [
  33. 'bl_id' => isset($this->params[ 'bl_id' ]) ? $this->params[ 'bl_id' ] : '',//组合套餐id
  34. 'num' => isset($this->params[ 'num' ]) ? $this->params[ 'num' ] : 1,//组合套餐数量(买几套)
  35. 'member_id' => $this->member_id,
  36. 'site_id' => $this->site_id,
  37. 'order_from' => $this->params[ 'app_type' ],
  38. 'order_from_name' => $this->params[ 'app_type_name' ],
  39. 'is_balance' => isset($this->params[ 'is_balance' ]) ? $this->params[ 'is_balance' ] : 0,//是否使用余额
  40. 'pay_password' => isset($this->params[ 'pay_password' ]) ? $this->params[ 'pay_password' ] : '',//支付密码
  41. 'buyer_message' => $this->params[ 'buyer_message' ] ?? '',
  42. 'delivery' => isset($this->params[ "delivery" ]) && !empty($this->params[ "delivery" ]) ? json_decode($this->params[ "delivery" ], true) : [],
  43. 'coupon' => isset($this->params[ "coupon" ]) && !empty($this->params[ "coupon" ]) ? json_decode($this->params[ "coupon" ], true) : [],
  44. 'member_address' => isset($this->params[ "member_address" ]) && !empty($this->params[ "member_address" ]) ? json_decode($this->params[ "member_address" ], true) : [],
  45. 'latitude' => $this->params[ "latitude" ] ?? '',
  46. 'longitude' => $this->params[ "longitude" ] ?? '',
  47. 'is_invoice' => $this->params[ "is_invoice" ] ?? 0,
  48. 'invoice_type' => $this->params[ "invoice_type" ] ?? 0,
  49. 'invoice_title' => $this->params[ "invoice_title" ] ?? '',
  50. 'taxpayer_number' => $this->params[ "taxpayer_number" ] ?? '',
  51. 'invoice_content' => $this->params[ "invoice_content" ] ?? '',
  52. 'invoice_full_address' => $this->params[ "invoice_full_address" ] ?? '',
  53. 'is_tax_invoice' => $this->params[ "is_tax_invoice" ] ?? 0,
  54. 'invoice_email' => $this->params[ "invoice_email" ] ?? '',
  55. 'invoice_title_type' => $this->params[ "invoice_title_type" ] ?? 0,
  56. 'buyer_ask_delivery_time' => $this->params[ "buyer_ask_delivery_time" ] ?? '',
  57. 'form_data' => isset($this->params[ "form_data" ]) && !empty($this->params[ "form_data" ]) ? json_decode($this->params[ "form_data" ], true) : [],
  58. ];
  59. if (empty($data[ 'bl_id' ])) {
  60. return $this->response($this->error('', '缺少必填参数商品数据'));
  61. }
  62. if ($data[ 'num' ] < 1) {
  63. return $this->response($this->error('', '购买数量不能小于1'));
  64. }
  65. $res = $order_create->create($data);
  66. return $this->response($res);
  67. }
  68. /**
  69. * 计算信息
  70. */
  71. public function calculate()
  72. {
  73. $token = $this->checkToken();
  74. if ($token[ 'code' ] < 0) return $this->response($token);
  75. $order_create = new OrderCreateModel();
  76. $data = [
  77. 'bl_id' => isset($this->params[ 'bl_id' ]) ? $this->params[ 'bl_id' ] : '',//组合套餐id
  78. 'num' => isset($this->params[ 'num' ]) ? $this->params[ 'num' ] : 1,//组合套餐数量(买几套)
  79. 'member_id' => $this->member_id,
  80. 'site_id' => $this->site_id,//站点id
  81. 'order_from' => $this->params[ 'app_type' ],
  82. 'order_from_name' => $this->params[ 'app_type_name' ],
  83. 'is_balance' => isset($this->params[ 'is_balance' ]) ? $this->params[ 'is_balance' ] : 0,//是否使用余额
  84. 'delivery' => isset($this->params[ "delivery" ]) && !empty($this->params[ "delivery" ]) ? json_decode($this->params[ "delivery" ], true) : [],
  85. 'coupon' => isset($this->params[ "coupon" ]) && !empty($this->params[ "coupon" ]) ? json_decode($this->params[ "coupon" ], true) : [],
  86. 'member_address' => isset($this->params[ "member_address" ]) && !empty($this->params[ "member_address" ]) ? json_decode($this->params[ "member_address" ], true) : [],
  87. 'latitude' => $this->params[ "latitude" ] ?? '',
  88. 'longitude' => $this->params[ "longitude" ] ?? '',
  89. 'is_invoice' => $this->params[ "is_invoice" ] ?? 0,
  90. 'invoice_type' => $this->params[ "invoice_type" ] ?? 0,
  91. 'invoice_title' => $this->params[ "invoice_title" ] ?? '',
  92. 'taxpayer_number' => $this->params[ "taxpayer_number" ] ?? '',
  93. 'invoice_content' => $this->params[ "invoice_content" ] ?? '',
  94. 'invoice_full_address' => $this->params[ "invoice_full_address" ] ?? '',
  95. 'is_tax_invoice' => $this->params[ "is_tax_invoice" ] ?? 0,
  96. 'invoice_email' => $this->params[ "invoice_email" ] ?? '',
  97. 'invoice_title_type' => $this->params[ "invoice_title_type" ] ?? 0,
  98. 'buyer_ask_delivery_time' => $this->params[ "buyer_ask_delivery_time" ] ?? '',
  99. ];
  100. if (empty($data[ 'bl_id' ])) {
  101. return $this->response($this->error('', '缺少必填参数商品数据'));
  102. }
  103. $res = $order_create->calculate($data);
  104. return $this->response($this->success($res));
  105. }
  106. /**
  107. * 待支付订单 数据初始化
  108. * @return string
  109. */
  110. public function payment()
  111. {
  112. $token = $this->checkToken();
  113. if ($token[ 'code' ] < 0) return $this->response($token);
  114. $order_create = new OrderCreateModel();
  115. $data = [
  116. 'bl_id' => isset($this->params[ 'bl_id' ]) ? $this->params[ 'bl_id' ] : '',
  117. 'num' => isset($this->params[ 'num' ]) ? $this->params[ 'num' ] : '',
  118. 'member_id' => $this->member_id,
  119. 'site_id' => $this->site_id,//站点id
  120. 'order_from' => $this->params[ 'app_type' ],
  121. 'is_balance' => isset($this->params[ 'is_balance' ]) ? $this->params[ 'is_balance' ] : 0,//是否使用余额
  122. 'order_from_name' => $this->params[ 'app_type_name' ],
  123. 'latitude' => $this->params[ "latitude" ] ?? '',
  124. 'longitude' => $this->params[ "longitude" ] ?? '',
  125. 'default_store_id' => $this->params[ "default_store_id" ] ?? 0,
  126. ];
  127. if (empty($data[ 'bl_id' ])) {
  128. return $this->response($this->error('', '缺少必填参数商品数据'));
  129. }
  130. $res = $order_create->orderPayment($data);
  131. return $this->response($this->success($res));
  132. }
  133. }