Ordercreate.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. /**
  3. * Index.php
  4. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  5. * =========================================================
  6. * Copy right 2015-2025 杭州牛之云科技有限公司, 保留所有权利。
  7. * ----------------------------------------------
  8. * 官方网址: http://www.niushop.com.cn
  9. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  10. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  11. * =========================================================
  12. * @author : niuteam
  13. * @date : 2022.8.8
  14. * @version : v5.0.0.1
  15. */
  16. namespace addon\presale\api\controller;
  17. use app\api\controller\BaseApi;
  18. use addon\presale\model\PresaleOrderCreate as OrderCreateModel;
  19. /**
  20. * 订单创建
  21. * @author Administrator
  22. *
  23. */
  24. class Ordercreate extends BaseApi
  25. {
  26. /**
  27. * 定金创建订单
  28. */
  29. public function depositCreate()
  30. {
  31. $token = $this->checkToken();
  32. if ($token[ 'code' ] < 0) return $this->response($token);
  33. $order_create = new OrderCreateModel();
  34. $data = [
  35. 'presale_id' => isset($this->params[ 'presale_id' ]) ? $this->params[ 'presale_id' ] : '', //预售id
  36. 'sku_id' => isset($this->params[ 'sku_id' ]) ? $this->params[ 'sku_id' ] : '',
  37. 'num' => isset($this->params[ 'num' ]) ? $this->params[ 'num' ] : '',//购买的商品数量
  38. 'site_id' => $this->site_id,//站点id
  39. 'member_id' => $this->member_id,
  40. 'is_balance' => isset($this->params[ 'is_balance' ]) ? $this->params[ 'is_balance' ] : 0,//是否使用余额
  41. 'order_from' => $this->params[ 'app_type' ],
  42. 'order_from_name' => $this->params[ 'app_type_name' ],
  43. 'pay_password' => isset($this->params[ 'pay_password' ]) ? $this->params[ 'pay_password' ] : '',//支付密码
  44. 'buyer_message' => isset($this->params[ "buyer_message" ]) && !empty($this->params[ "buyer_message" ]) ? $this->params[ "buyer_message" ] : '',
  45. 'delivery' => isset($this->params[ "delivery" ]) && !empty($this->params[ "delivery" ]) ? json_decode($this->params[ "delivery" ], true) : [],
  46. 'coupon' => isset($this->params[ "coupon" ]) && !empty($this->params[ "coupon" ]) ? json_decode($this->params[ "coupon" ], true) : [],
  47. 'member_address' => isset($this->params[ "member_address" ]) && !empty($this->params[ "member_address" ]) ? json_decode($this->params[ "member_address" ], true) : [],
  48. 'latitude' => $this->params[ "latitude" ] ?? '',
  49. 'longitude' => $this->params[ "longitude" ] ?? '',
  50. 'is_invoice' => $this->params[ "is_invoice" ] ?? 0,
  51. 'invoice_type' => $this->params[ "invoice_type" ] ?? 0,
  52. 'invoice_title' => $this->params[ "invoice_title" ] ?? '',
  53. 'taxpayer_number' => $this->params[ "taxpayer_number" ] ?? '',
  54. 'invoice_content' => $this->params[ "invoice_content" ] ?? '',
  55. 'invoice_full_address' => $this->params[ "invoice_full_address" ] ?? '',
  56. 'is_tax_invoice' => $this->params[ "is_tax_invoice" ] ?? 0,
  57. 'invoice_email' => $this->params[ "invoice_email" ] ?? '',
  58. 'invoice_title_type' => $this->params[ "invoice_title_type" ] ?? 0,
  59. 'buyer_ask_delivery_time' => $this->params[ "buyer_ask_delivery_time" ] ?? 0,
  60. 'form_data' => isset($this->params[ "form_data" ]) && !empty($this->params[ "form_data" ]) ? json_decode($this->params[ "form_data" ], true) : [],
  61. ];
  62. if (empty($data[ 'presale_id' ]) && empty($data[ 'sku_id' ])) {
  63. return $this->response($this->error('', '缺少必填参数商品数据'));
  64. }
  65. if ($data[ 'num' ] < 1) {
  66. return $this->response($this->error('', '购买数量不能小于1'));
  67. }
  68. if ($data[ 'buyer_ask_delivery_time' ]) {
  69. $data[ 'buyer_ask_delivery_time' ] = strtotime($data[ "buyer_ask_delivery_time" ]);
  70. }
  71. $res = $order_create->create($data);
  72. return $this->response($res);
  73. }
  74. /**
  75. * 定金计算信息
  76. */
  77. public function depositCalculate()
  78. {
  79. $token = $this->checkToken();
  80. if ($token[ 'code' ] < 0) return $this->response($token);
  81. $order_create = new OrderCreateModel();
  82. $data = [
  83. 'presale_id' => isset($this->params[ 'presale_id' ]) ? $this->params[ 'presale_id' ] : '', //预售id
  84. 'sku_id' => isset($this->params[ 'sku_id' ]) ? $this->params[ 'sku_id' ] : '',
  85. 'num' => isset($this->params[ 'num' ]) ? $this->params[ 'num' ] : '',
  86. 'site_id' => $this->site_id,//站点id
  87. 'member_id' => $this->member_id,
  88. 'is_balance' => isset($this->params[ 'is_balance' ]) ? $this->params[ 'is_balance' ] : 0,//是否使用余额
  89. 'pay_password' => isset($this->params[ 'pay_password' ]) ? $this->params[ 'pay_password' ] : '',//支付密码
  90. 'order_from' => $this->params[ 'app_type' ],
  91. 'order_from_name' => $this->params[ 'app_type_name' ],
  92. 'delivery' => isset($this->params[ "delivery" ]) && !empty($this->params[ "delivery" ]) ? json_decode($this->params[ "delivery" ], true) : [],
  93. 'coupon' => isset($this->params[ "coupon" ]) && !empty($this->params[ "coupon" ]) ? json_decode($this->params[ "coupon" ], true) : [],
  94. 'member_address' => isset($this->params[ "member_address" ]) && !empty($this->params[ "member_address" ]) ? json_decode($this->params[ "member_address" ], true) : [],
  95. 'latitude' => $this->params[ "latitude" ] ?? '',
  96. 'longitude' => $this->params[ "longitude" ] ?? '',
  97. 'is_invoice' => $this->params[ "is_invoice" ] ?? 0,
  98. 'invoice_type' => $this->params[ "invoice_type" ] ?? 0,
  99. 'invoice_title' => $this->params[ "invoice_title" ] ?? '',
  100. 'taxpayer_number' => $this->params[ "taxpayer_number" ] ?? '',
  101. 'invoice_content' => $this->params[ "invoice_content" ] ?? '',
  102. 'invoice_full_address' => $this->params[ "invoice_full_address" ] ?? '',
  103. 'is_tax_invoice' => $this->params[ "is_tax_invoice" ] ?? 0,
  104. 'invoice_email' => $this->params[ "invoice_email" ] ?? '',
  105. 'invoice_title_type' => $this->params[ "invoice_title_type" ] ?? 0,
  106. 'buyer_ask_delivery_time' => $this->params[ "buyer_ask_delivery_time" ] ?? '',
  107. ];
  108. if (empty($data[ 'presale_id' ]) && empty($data[ 'sku_id' ])) {
  109. return $this->response($this->error('', '缺少必填参数商品数据'));
  110. }
  111. if ($data[ 'buyer_ask_delivery_time' ]) {
  112. $data[ 'buyer_ask_delivery_time' ] = strtotime($data[ "buyer_ask_delivery_time" ]);
  113. }
  114. $res = $order_create->depositCalculate($data);
  115. return $this->response($this->success($res));
  116. }
  117. /**
  118. * 待支付订单(定金)
  119. * @return string
  120. */
  121. public function depositPayment()
  122. {
  123. $token = $this->checkToken();
  124. if ($token[ 'code' ] < 0) return $this->response($token);
  125. $order_create = new OrderCreateModel();
  126. $data = [
  127. 'presale_id' => isset($this->params[ 'presale_id' ]) ? $this->params[ 'presale_id' ] : '', //预售id
  128. 'sku_id' => isset($this->params[ 'sku_id' ]) ? $this->params[ 'sku_id' ] : '',
  129. 'site_id' => $this->site_id,//站点id
  130. 'num' => isset($this->params[ 'num' ]) ? $this->params[ 'num' ] : '',
  131. 'member_id' => $this->member_id,
  132. 'is_balance' => isset($this->params[ 'is_balance' ]) ? $this->params[ 'is_balance' ] : 0,//是否使用余额
  133. 'order_from' => $this->params[ 'app_type' ],
  134. 'order_from_name' => $this->params[ 'app_type_name' ],
  135. 'latitude' => $this->params[ "latitude" ] ?? '',
  136. 'longitude' => $this->params[ "longitude" ] ?? '',
  137. 'default_store_id' => $this->params[ "default_store_id" ] ?? 0,
  138. ];
  139. if (empty($data[ 'presale_id' ]) && empty($data[ 'sku_id' ])) {
  140. return $this->response($this->error('', '缺少必填参数商品数据'));
  141. }
  142. $res = $order_create->depositOrderPayment($data);
  143. return $this->response($this->success($res));
  144. }
  145. /**
  146. * 待支付订单(尾款)
  147. * @return string
  148. */
  149. public function finalPayment()
  150. {
  151. $token = $this->checkToken();
  152. if ($token[ 'code' ] < 0) return $this->response($token);
  153. $order_create = new OrderCreateModel();
  154. $data = [
  155. 'id' => isset($this->params[ 'id' ]) ? $this->params[ 'id' ] : '', //预售订单id
  156. 'site_id' => $this->site_id,//站点id
  157. 'member_id' => $this->member_id,
  158. 'is_balance' => isset($this->params[ 'is_balance' ]) ? $this->params[ 'is_balance' ] : 0,//是否使用余额
  159. 'pay_password' => isset($this->params[ 'pay_password' ]) ? $this->params[ 'pay_password' ] : '',//支付密码
  160. ];
  161. if (empty($data[ 'id' ])) {
  162. return $this->response($this->error('', '缺少必填参数订单数据'));
  163. }
  164. $res = $order_create->finalCalculate($data);
  165. return $this->response($this->success($res));
  166. }
  167. /**
  168. * 尾款订单
  169. */
  170. public function finalCreate()
  171. {
  172. $token = $this->checkToken();
  173. if ($token[ 'code' ] < 0) return $this->response($token);
  174. $order_create = new OrderCreateModel();
  175. $data = [
  176. 'id' => isset($this->params[ 'id' ]) ? $this->params[ 'id' ] : '', //预售订单id
  177. 'site_id' => $this->site_id,//站点id
  178. 'member_id' => $this->member_id,
  179. 'is_balance' => isset($this->params[ 'is_balance' ]) ? $this->params[ 'is_balance' ] : 0,//是否使用余额
  180. 'pay_password' => isset($this->params[ 'pay_password' ]) ? $this->params[ 'pay_password' ] : '',//支付密码
  181. ];
  182. if (empty($data[ 'id' ])) {
  183. return $this->response($this->error('', '缺少必填参数订单数据'));
  184. }
  185. $res = $order_create->payfinalMoneyPresaleOrder($data);
  186. return $this->response($res);
  187. }
  188. }