Ordercreate.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\replacebuy\shop\controller;
  11. use addon\replacebuy\model\ReplacebuyOrderCreate as OrderCreateModel;
  12. /**
  13. * 订单
  14. * Class Order
  15. * @package app\shop\controller
  16. */
  17. class Ordercreate extends Replacebuy
  18. {
  19. public function __construct()
  20. {
  21. //执行父类构造函数
  22. parent::__construct();
  23. }
  24. /**
  25. * 创建订单
  26. */
  27. public function create()
  28. {
  29. //通过传递的sku_id数据,模拟操作购物车
  30. $order_create = new OrderCreateModel();
  31. $cart = input("cart", "");
  32. $coupon_id = input("coupon_id", 0);
  33. $cart_data_result = $this->tranSkuData($cart);
  34. if ($cart_data_result["code"] < 0) {
  35. return $cart_data_result;
  36. }
  37. $cart_data = $cart_data_result["data"];
  38. $sku_ids = $cart_data["sku_ids"];
  39. $nums = $cart_data["nums"];
  40. $buyer_member_id = $this->buyer();
  41. if ($buyer_member_id <= 0)
  42. return $order_create->error([], "当前没有登录会员");
  43. $address_id = $this->address_id;
  44. if ($address_id <= 0)
  45. return $order_create->error([], "当前没有选择地址");
  46. $data = [
  47. 'site_id' => $this->site_id,
  48. 'sku_ids' => $sku_ids,
  49. 'nums' => $nums,
  50. 'member_id' => $buyer_member_id,
  51. 'is_balance' => input('is_balance', 0),//是否使用余额
  52. 'order_from' => "pc",
  53. 'order_from_name' => "PC",
  54. 'coupon' => ["coupon_id" => $coupon_id],
  55. 'member_address' => [],
  56. "buyer_message" => '',
  57. 'address_id' => $address_id,//收货地址ID
  58. 'is_point' => input('is_point', 0),//是否使用积分
  59. 'is_open_card' => input('is_open_card', 0),
  60. 'is_invoice' => input("is_invoice", 0),
  61. 'invoice_type' => input("invoice_type", 0),
  62. 'invoice_title' => input("invoice_title", ''),
  63. 'taxpayer_number' => input("taxpayer_number", ''),
  64. 'invoice_content' => input("invoice_content", ''),
  65. 'invoice_full_address' => input("invoice_full_address", ''),
  66. 'is_tax_invoice' => input("is_tax_invoice", 0),
  67. 'invoice_email' => input("invoice_email", ''),
  68. 'invoice_title_type' => input("invoice_email", 0),
  69. 'app_module' => $this->app_module
  70. ];
  71. $res = $order_create->create($data);
  72. return $res;
  73. }
  74. /**
  75. * 计算信息
  76. */
  77. public function calculate()
  78. {
  79. //通过传递的sku_id数据,模拟操作购物车
  80. $order_create = new OrderCreateModel();
  81. $cart = input("cart", "");
  82. $coupon_id = input("coupon_id", 0);
  83. $cart_data_result = $this->tranSkuData($cart);
  84. if ($cart_data_result["code"] < 0) {
  85. return $cart_data_result;
  86. }
  87. $cart_data = $cart_data_result["data"];
  88. $sku_ids = $cart_data["sku_ids"];
  89. $nums = $cart_data["nums"];
  90. $buyer_member_id = $this->buyer();
  91. if ($buyer_member_id <= 0)
  92. return $order_create->error([], "当前没有登录会员");
  93. $data = [
  94. 'sku_ids' => $sku_ids,
  95. 'nums' => $nums,
  96. 'site_id' => $this->site_id,
  97. 'member_id' => $buyer_member_id,
  98. 'is_balance' => input('is_balance', 0),//是否使用余额
  99. 'order_from' => "pc",
  100. 'order_from_name' => "PC",
  101. 'coupon' => ["coupon_id" => $coupon_id],
  102. 'address_id' => $this->address_id,//收货地址ID
  103. 'is_invoice' => input("is_invoice", 0),
  104. 'invoice_type' => input("invoice_type", 0),
  105. 'invoice_title' => input("invoice_title", ''),
  106. 'taxpayer_number' => input("taxpayer_number", ''),
  107. 'invoice_content' => input("invoice_content", ''),
  108. 'invoice_full_address' => input("invoice_full_address", ''),
  109. 'is_tax_invoice' => input("is_tax_invoice", 0),
  110. 'invoice_email' => input("invoice_email", '')
  111. ];
  112. $res = $order_create->calculate($data);
  113. return $order_create->success($res);
  114. }
  115. /**
  116. * 待支付订单 数据初始化
  117. * @return string
  118. */
  119. public function payment()
  120. {
  121. if (request()->isAjax()) {
  122. //通过传递的sku_id数据,模拟操作购物车
  123. $order_create = new OrderCreateModel();
  124. $cart = input("cart", "");
  125. $cart_data_result = $this->tranSkuData($cart);
  126. if ($cart_data_result["code"] < 0) {
  127. return $cart_data_result;
  128. }
  129. $cart_data = $cart_data_result["data"];
  130. $sku_ids = $cart_data["sku_ids"];
  131. $nums = $cart_data["nums"];
  132. //查看是否登陆了会员
  133. $buyer_member_id = $this->buyer();
  134. if ($buyer_member_id <= 0)
  135. return $order_create->error([], "当前没有选择会员");
  136. $data = [
  137. 'sku_ids' => $sku_ids,
  138. 'nums' => $nums,
  139. 'site_id' => $this->site_id,
  140. 'member_id' => $buyer_member_id,
  141. 'is_balance' => input('is_balance', 0),//是否使用余额
  142. 'is_point' => input('is_point', 0),//是否使用积分
  143. 'is_open_card' => input('is_open_card', 0),
  144. 'order_from' => "pc",
  145. 'order_from_name' => "PC",
  146. 'address_id' => $this->address_id//收货地址ID
  147. ];
  148. $res = $order_create->orderPayment($data);
  149. return $res;
  150. }
  151. }
  152. /**
  153. * "格式化" 购物车数据
  154. * @param $cart
  155. * @return array
  156. */
  157. public function tranSkuData($cart)
  158. {
  159. $order_create = new OrderCreateModel();
  160. if (empty($cart)) {
  161. return $order_create->error([], "'购物车中还没有商品!");
  162. }
  163. $cart = json_decode($cart, true);
  164. $sku_ids = [];
  165. $nums = [];
  166. foreach ($cart as $k => $v) {
  167. $sku_ids[] = $v["sku_id"];
  168. $nums[$v["sku_id"]] = $v["num"];
  169. }
  170. return $order_create->success(["sku_ids" => $sku_ids, "nums" => $nums]);
  171. }
  172. /**
  173. * @return array
  174. */
  175. public function test()
  176. {
  177. // $this->loginBuyer();
  178. $order_create = new OrderCreateModel();
  179. $temp_array = array(
  180. [
  181. "sku_id" => 586,
  182. "num" => 1,
  183. ]
  184. );
  185. $cart = input("cart", json_encode($temp_array));
  186. $cart_data_result = $this->tranSkuData($cart);
  187. if ($cart_data_result["code"] < 0) {
  188. return $cart_data_result;
  189. }
  190. $cart_data = $cart_data_result["data"];
  191. $sku_ids = $cart_data["sku_ids"];
  192. $nums = $cart_data["nums"];
  193. //查看是否登陆了会员
  194. $buyer_member_id = $this->buyer();
  195. $data = [
  196. 'sku_ids' => $sku_ids,
  197. 'nums' => $nums,
  198. 'store_id' => $this->store_id,
  199. 'site_id' => $this->site_id,
  200. 'member_id' => $buyer_member_id,
  201. 'is_balance' => input('is_balance', 0),//是否使用余额
  202. 'order_from' => "pc",
  203. 'order_from_name' => "PC",
  204. 'coupon' => ["coupon_id" => 0],
  205. "buyer_message" => ''
  206. // 'member_address' => []
  207. ];
  208. // $res = $order_create->calculate($data);
  209. $res = $order_create->create($data);
  210. // $res = $order_create->orderPayment($data);
  211. var_dump($res);
  212. // return $res;
  213. }
  214. }