| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- <?php
- /**
- * Niushop商城系统 - 团队十年电商经验汇集巨献!
- * =========================================================
- * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
- * ----------------------------------------------
- * 官方网址: https://www.niushop.com
- * =========================================================
- */
- namespace addon\replacebuy\shop\controller;
- use addon\replacebuy\model\ReplacebuyOrderCreate as OrderCreateModel;
- /**
- * 订单
- * Class Order
- * @package app\shop\controller
- */
- class Ordercreate extends Replacebuy
- {
- public function __construct()
- {
- //执行父类构造函数
- parent::__construct();
- }
- /**
- * 创建订单
- */
- public function create()
- {
- //通过传递的sku_id数据,模拟操作购物车
- $order_create = new OrderCreateModel();
- $cart = input("cart", "");
- $coupon_id = input("coupon_id", 0);
- $cart_data_result = $this->tranSkuData($cart);
- if ($cart_data_result["code"] < 0) {
- return $cart_data_result;
- }
- $cart_data = $cart_data_result["data"];
- $sku_ids = $cart_data["sku_ids"];
- $nums = $cart_data["nums"];
- $buyer_member_id = $this->buyer();
- if ($buyer_member_id <= 0)
- return $order_create->error([], "当前没有登录会员");
- $address_id = $this->address_id;
- if ($address_id <= 0)
- return $order_create->error([], "当前没有选择地址");
- $data = [
- 'site_id' => $this->site_id,
- 'sku_ids' => $sku_ids,
- 'nums' => $nums,
- 'member_id' => $buyer_member_id,
- 'is_balance' => input('is_balance', 0),//是否使用余额
- 'order_from' => "pc",
- 'order_from_name' => "PC",
- 'coupon' => ["coupon_id" => $coupon_id],
- 'member_address' => [],
- "buyer_message" => '',
- 'address_id' => $address_id,//收货地址ID
- 'is_point' => input('is_point', 0),//是否使用积分
- 'is_open_card' => input('is_open_card', 0),
- 'is_invoice' => input("is_invoice", 0),
- 'invoice_type' => input("invoice_type", 0),
- 'invoice_title' => input("invoice_title", ''),
- 'taxpayer_number' => input("taxpayer_number", ''),
- 'invoice_content' => input("invoice_content", ''),
- 'invoice_full_address' => input("invoice_full_address", ''),
- 'is_tax_invoice' => input("is_tax_invoice", 0),
- 'invoice_email' => input("invoice_email", ''),
- 'invoice_title_type' => input("invoice_email", 0),
- 'app_module' => $this->app_module
- ];
- $res = $order_create->create($data);
- return $res;
- }
- /**
- * 计算信息
- */
- public function calculate()
- {
- //通过传递的sku_id数据,模拟操作购物车
- $order_create = new OrderCreateModel();
- $cart = input("cart", "");
- $coupon_id = input("coupon_id", 0);
- $cart_data_result = $this->tranSkuData($cart);
- if ($cart_data_result["code"] < 0) {
- return $cart_data_result;
- }
- $cart_data = $cart_data_result["data"];
- $sku_ids = $cart_data["sku_ids"];
- $nums = $cart_data["nums"];
- $buyer_member_id = $this->buyer();
- if ($buyer_member_id <= 0)
- return $order_create->error([], "当前没有登录会员");
- $data = [
- 'sku_ids' => $sku_ids,
- 'nums' => $nums,
- 'site_id' => $this->site_id,
- 'member_id' => $buyer_member_id,
- 'is_balance' => input('is_balance', 0),//是否使用余额
- 'order_from' => "pc",
- 'order_from_name' => "PC",
- 'coupon' => ["coupon_id" => $coupon_id],
- 'address_id' => $this->address_id,//收货地址ID
- 'is_invoice' => input("is_invoice", 0),
- 'invoice_type' => input("invoice_type", 0),
- 'invoice_title' => input("invoice_title", ''),
- 'taxpayer_number' => input("taxpayer_number", ''),
- 'invoice_content' => input("invoice_content", ''),
- 'invoice_full_address' => input("invoice_full_address", ''),
- 'is_tax_invoice' => input("is_tax_invoice", 0),
- 'invoice_email' => input("invoice_email", '')
- ];
- $res = $order_create->calculate($data);
- return $order_create->success($res);
- }
- /**
- * 待支付订单 数据初始化
- * @return string
- */
- public function payment()
- {
- if (request()->isAjax()) {
- //通过传递的sku_id数据,模拟操作购物车
- $order_create = new OrderCreateModel();
- $cart = input("cart", "");
- $cart_data_result = $this->tranSkuData($cart);
- if ($cart_data_result["code"] < 0) {
- return $cart_data_result;
- }
- $cart_data = $cart_data_result["data"];
- $sku_ids = $cart_data["sku_ids"];
- $nums = $cart_data["nums"];
- //查看是否登陆了会员
- $buyer_member_id = $this->buyer();
- if ($buyer_member_id <= 0)
- return $order_create->error([], "当前没有选择会员");
- $data = [
- 'sku_ids' => $sku_ids,
- 'nums' => $nums,
- 'site_id' => $this->site_id,
- 'member_id' => $buyer_member_id,
- 'is_balance' => input('is_balance', 0),//是否使用余额
- 'is_point' => input('is_point', 0),//是否使用积分
- 'is_open_card' => input('is_open_card', 0),
- 'order_from' => "pc",
- 'order_from_name' => "PC",
- 'address_id' => $this->address_id//收货地址ID
- ];
- $res = $order_create->orderPayment($data);
- return $res;
- }
- }
- /**
- * "格式化" 购物车数据
- * @param $cart
- * @return array
- */
- public function tranSkuData($cart)
- {
- $order_create = new OrderCreateModel();
- if (empty($cart)) {
- return $order_create->error([], "'购物车中还没有商品!");
- }
- $cart = json_decode($cart, true);
- $sku_ids = [];
- $nums = [];
- foreach ($cart as $k => $v) {
- $sku_ids[] = $v["sku_id"];
- $nums[$v["sku_id"]] = $v["num"];
- }
- return $order_create->success(["sku_ids" => $sku_ids, "nums" => $nums]);
- }
- /**
- * @return array
- */
- public function test()
- {
- // $this->loginBuyer();
- $order_create = new OrderCreateModel();
- $temp_array = array(
- [
- "sku_id" => 586,
- "num" => 1,
- ]
- );
- $cart = input("cart", json_encode($temp_array));
- $cart_data_result = $this->tranSkuData($cart);
- if ($cart_data_result["code"] < 0) {
- return $cart_data_result;
- }
- $cart_data = $cart_data_result["data"];
- $sku_ids = $cart_data["sku_ids"];
- $nums = $cart_data["nums"];
- //查看是否登陆了会员
- $buyer_member_id = $this->buyer();
- $data = [
- 'sku_ids' => $sku_ids,
- 'nums' => $nums,
- 'store_id' => $this->store_id,
- 'site_id' => $this->site_id,
- 'member_id' => $buyer_member_id,
- 'is_balance' => input('is_balance', 0),//是否使用余额
- 'order_from' => "pc",
- 'order_from_name' => "PC",
- 'coupon' => ["coupon_id" => 0],
- "buyer_message" => ''
- // 'member_address' => []
- ];
- // $res = $order_create->calculate($data);
- $res = $order_create->create($data);
- // $res = $order_create->orderPayment($data);
- var_dump($res);
- // return $res;
- }
- }
|