初始上传
This commit is contained in:
361
addon/bundling/model/Bundling.php
Executable file
361
addon/bundling/model/Bundling.php
Executable file
@@ -0,0 +1,361 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\bundling\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
|
||||
/**
|
||||
* 优惠套餐
|
||||
*/
|
||||
class Bundling extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 添加优惠套餐
|
||||
* @param $data
|
||||
* @param $sku_ids
|
||||
* @return array
|
||||
*/
|
||||
public function addBundling($data, $sku_ids)
|
||||
{
|
||||
if ($data['bl_price'] <= 0) {
|
||||
return $this->error([], '优惠套餐价格不能小于或等与0');
|
||||
}
|
||||
model('promotion_bundling')->startTrans();
|
||||
try {
|
||||
$sku_id_array = explode(',', $sku_ids);
|
||||
$goods_money = 0;
|
||||
$sku_array = [];
|
||||
foreach ($sku_id_array as $k => $v) {
|
||||
$sku_info = model('goods_sku')->getInfo([ [ 'sku_id', '=', $v ] ], 'sku_id,sku_name,price,sku_image,is_virtual');
|
||||
if ($sku_info['is_virtual'] == 1) {
|
||||
model('promotion_bundling')->rollback();
|
||||
return $this->error([], '优惠套餐中不能包含虚拟商品');
|
||||
}
|
||||
unset($sku_info['is_virtual']);
|
||||
$goods_money += $sku_info[ 'price' ];
|
||||
$sku_array[] = $sku_info;
|
||||
}
|
||||
|
||||
$data['goods_money'] = $goods_money;
|
||||
$data['update_time'] = time();
|
||||
$bundling_id = model('promotion_bundling')->add($data);
|
||||
foreach ($sku_array as $k => $v) {
|
||||
$v[ 'bl_id' ] = $bundling_id;
|
||||
$v[ 'site_id' ] = $data['site_id'];
|
||||
$v[ 'promotion_price' ] = $v[ 'price' ] / $goods_money * $data[ 'bl_price' ];
|
||||
model('promotion_bundling_goods')->add($v);
|
||||
}
|
||||
model('promotion_bundling')->commit();
|
||||
return $this->success($bundling_id);
|
||||
} catch (\Exception $e) {
|
||||
model('promotion_bundling')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑优惠套餐
|
||||
* @param $data
|
||||
* @param $sku_ids
|
||||
* @param $condition
|
||||
* @return array
|
||||
*/
|
||||
public function editBundling($data, $sku_ids, $condition)
|
||||
{
|
||||
if ($data['bl_price'] <= 0) {
|
||||
return $this->error([], '优惠套餐价格不能小于或等与0');
|
||||
}
|
||||
$check_condition = array_column($condition, 2, 0);
|
||||
model('promotion_bundling')->startTrans();
|
||||
try {
|
||||
model('promotion_bundling_goods')->delete($condition);
|
||||
$sku_id_array = explode(',', $sku_ids);
|
||||
$goods_money = 0;
|
||||
$sku_array = [];
|
||||
foreach ($sku_id_array as $k => $v) {
|
||||
$sku_info = model('goods_sku')->getInfo([ [ 'sku_id', '=', $v ] ], 'sku_id,sku_name,price,sku_image,is_virtual');
|
||||
if ($sku_info['is_virtual'] == 1) {
|
||||
model('promotion_bundling')->rollback();
|
||||
return $this->error([], '优惠套餐中不能包含虚拟商品');
|
||||
}
|
||||
unset($sku_info['is_virtual']);
|
||||
$sku_info[ 'bl_id' ] = $check_condition[ 'bl_id' ];
|
||||
$goods_money += $sku_info[ 'price' ];
|
||||
$sku_array[] = $sku_info;
|
||||
}
|
||||
$data['goods_money'] = $goods_money;
|
||||
$data['update_time'] = time();
|
||||
$res = model('promotion_bundling')->update($data, $condition);
|
||||
foreach ($sku_array as $k => $v) {
|
||||
$v[ 'promotion_price' ] = $v[ 'price' ] / $goods_money * $data[ 'bl_price' ];
|
||||
$v['site_id'] = $check_condition['site_id'];
|
||||
model('promotion_bundling_goods')->add($v);
|
||||
}
|
||||
model('promotion_bundling')->commit();
|
||||
return $this->success($res);
|
||||
} catch (\Exception $e) {
|
||||
model('promotion_bundling')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除优惠套餐
|
||||
* @param number $bl_id
|
||||
* @param number $site_id
|
||||
*/
|
||||
public function deleteBundling($bl_id, $site_id)
|
||||
{
|
||||
$condition = array (
|
||||
[ 'bl_id', '=', $bl_id ],
|
||||
['site_id', '=', $site_id ]
|
||||
);
|
||||
$res = model('promotion_bundling')->delete($condition);
|
||||
if ($res) {
|
||||
model('promotion_bundling_goods')->delete([ 'bl_id' => $bl_id ]);
|
||||
return $this->success($res);
|
||||
} else {
|
||||
return $this->error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取优惠套餐详情
|
||||
* @param $condition
|
||||
* @return array
|
||||
*/
|
||||
public function getBundlingInfo($condition)
|
||||
{
|
||||
$data = model('promotion_bundling')->getInfo($condition, 'bl_id,bl_name, site_id, site_name, bl_price, goods_money, shipping_fee_type,status');
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取优惠套餐详情
|
||||
* @param $condition
|
||||
* @return array
|
||||
*/
|
||||
public function getBundlingDetail($condition)
|
||||
{
|
||||
$check_condition = array_column($condition, 2, 0);
|
||||
$bl_id = $check_condition['bl_id'] ?? '';
|
||||
$data = model('promotion_bundling')->getInfo($condition, 'bl_id,bl_name, site_id, site_name, bl_price, goods_money, shipping_fee_type,status');
|
||||
if (!empty($data)) {
|
||||
$order = '';
|
||||
$alias = 'pbg';
|
||||
$condition = [
|
||||
[ 'pbg.bl_id', '=', $bl_id ],
|
||||
[ 'ngs.is_delete', '=', 0 ]
|
||||
];
|
||||
|
||||
$field = 'ngs.sku_id,ngs.goods_id, ngs.sku_name, ngs.price, ngs.sku_image, ngs.stock,ngs.unit,pbg.promotion_price,g.sale_store';
|
||||
$join = [
|
||||
[
|
||||
'goods_sku ngs',
|
||||
'pbg.sku_id = ngs.sku_id',
|
||||
'inner'
|
||||
],
|
||||
[
|
||||
'goods g',
|
||||
'g.goods_id = ngs.goods_id',
|
||||
'left'
|
||||
],
|
||||
];
|
||||
$bundling_goods = model('promotion_bundling_goods')->getList($condition, $field, $order, $alias, $join);
|
||||
foreach ($bundling_goods as $k => $v) {
|
||||
$bundling_goods[ $k ][ 'stock' ] = numberFormat($bundling_goods[ $k ][ 'stock' ]);
|
||||
}
|
||||
|
||||
$data[ 'bundling_goods' ] = $bundling_goods;
|
||||
$data[ 'bundling_goods_count' ] = count($data[ 'bundling_goods' ]);
|
||||
}
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品优惠套餐
|
||||
* @param $sku_id
|
||||
* @return array
|
||||
*/
|
||||
public function getBundlingGoods($sku_id)
|
||||
{
|
||||
$bundling_ids = model('promotion_bundling_goods')->getList([ [ 'sku_id', '=', $sku_id ] ], 'bl_id');
|
||||
$bundling_array = [];
|
||||
foreach ($bundling_ids as $k => $v) {
|
||||
$temp_result = $this->getBundlingDetail([ [ 'bl_id', '=', $v['bl_id'] ], [ 'status', '=', 1 ] ]);
|
||||
if (!empty($temp_result['data'])) $bundling_array[] = $temp_result['data'];
|
||||
}
|
||||
return $this->success($bundling_array);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取优惠餐列表
|
||||
* @param array $condition
|
||||
* @param number $page
|
||||
* @param string $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
*/
|
||||
public function getBundlingPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
|
||||
{
|
||||
$list = model('promotion_bundling')->pageList($condition, $field, $order, $page, $page_size);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品(需判断套餐是否存在该商品,存在活动关闭)
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function cronDeleteGoods($param)
|
||||
{
|
||||
//获取商品sku_id
|
||||
$sku_ids = model('goods_sku')->getColumn([ [ 'goods_id', 'in', (array) $param[ 'goods_id' ] ], [ 'site_id', '=', $param[ 'site_id' ] ] ], 'sku_id');
|
||||
if (!empty($sku_ids)) {
|
||||
|
||||
//获取组合套餐id
|
||||
$bl_ids = model('promotion_bundling_goods')->getColumn([ [ 'sku_id', 'in', $sku_ids ], [ 'site_id', '=', $param[ 'site_id' ] ] ], 'bl_id');
|
||||
if (!empty($bl_ids)) {
|
||||
$bl_ids = array_unique($bl_ids);
|
||||
//将组合套餐活动下架
|
||||
$res = model('promotion_bundling')->update([ 'status' => 0 ], [ [ 'bl_id', 'in', $bl_ids ], [ 'site_id', '=', $param[ 'site_id' ] ] ]);
|
||||
return $this->success($res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取组合
|
||||
*
|
||||
* @param $sku_id
|
||||
* @return array
|
||||
*/
|
||||
public function getBundlingGoodsNew($sku_id)
|
||||
{
|
||||
$goods_id = model('goods_sku')->getInfo([ [ 'sku_id', '=', $sku_id ] ], 'goods_id');
|
||||
$sku_list_id = model('goods_sku')->getList([ [ 'goods_id', '=', $goods_id[ 'goods_id' ] ] ], 'sku_id');
|
||||
$sku_id_arr = [];
|
||||
foreach ($sku_list_id as $key => $val) {
|
||||
if ($val[ 'sku_id' ] != $sku_id) {
|
||||
$sku_id_arr[] = $val[ 'sku_id' ];
|
||||
}
|
||||
}
|
||||
$bundling_list1 = model('promotion_bundling_goods')->getList([ [ 'sku_id', '=', $sku_id ] ], 'bl_id');
|
||||
$bundling_list = model('promotion_bundling_goods')->getList([ [ 'sku_id', 'in', $sku_id_arr ] ], 'bl_id');
|
||||
$bl_id_arr1 = [];
|
||||
if ($bundling_list1) {
|
||||
foreach ($bundling_list1 as $kes => $vas) {
|
||||
$bl_id_arr1[] = $vas[ 'bl_id' ];
|
||||
}
|
||||
}
|
||||
|
||||
$bl_id_arr = [];
|
||||
if ($bundling_list) {
|
||||
foreach ($bundling_list as $ke => $va) {
|
||||
$bl_id_arr[] = $va[ 'bl_id' ];
|
||||
}
|
||||
}
|
||||
|
||||
$bl_id_arr = array_unique(array_merge($bl_id_arr1, $bl_id_arr));
|
||||
$bundling_array = [];
|
||||
foreach ($bl_id_arr as $k => $v) {
|
||||
$temp_result = $this->getBundlingDetail([ [ 'bl_id', '=', $v ], [ 'status', '=', 1 ] ]);
|
||||
if (!empty($temp_result['data'])) $bundling_array[] = $temp_result['data'];
|
||||
}
|
||||
return $this->success($bundling_array);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取组合套餐
|
||||
* @param $goods_sku_detail_array
|
||||
* @return array
|
||||
*/
|
||||
public function getBundlingGoodsInApi($goods_sku_detail_array)
|
||||
{
|
||||
$goods_sku_detail_array[ 'goods_sku_detail' ][ 'bundling_list' ] = [];
|
||||
$goods_sku_detail = $goods_sku_detail_array['goods_sku_detail'];
|
||||
//查询商品对应skuid组
|
||||
$sku_list_ids = model('goods_sku')->getList([ [ 'goods_id', '=', $goods_sku_detail[ 'goods_id' ] ] ], 'sku_id');
|
||||
$sku_ids = array_column($sku_list_ids, 'sku_id');
|
||||
$sku_ids = implode(',', $sku_ids);
|
||||
$bundling_goods_ids = model('promotion_bundling_goods')->getList([['sku_id', 'in', $sku_ids]], 'bl_id');
|
||||
if(empty($bundling_goods_ids)) return $goods_sku_detail_array;
|
||||
$bl_ids = [];
|
||||
foreach ($bundling_goods_ids as $k => $v)
|
||||
{
|
||||
if(!in_array($v['bl_id'], $bl_ids))
|
||||
{
|
||||
$bl_ids[] = $v['bl_id'];
|
||||
}
|
||||
}
|
||||
$bl_ids = implode(',', $bl_ids);
|
||||
$bundling_list = $data = model('promotion_bundling')->getList([['bl_id', 'in', $bl_ids], ['status', '=', 1]], 'bl_id,bl_name, site_id, site_name, bl_price, goods_money, shipping_fee_type,status');
|
||||
if(empty($bundling_list))
|
||||
{
|
||||
$goods_sku_detail_array[ 'goods_sku_detail' ][ 'bundling_list' ] = [];
|
||||
return $goods_sku_detail_array;
|
||||
}
|
||||
|
||||
$order = '';
|
||||
$alias = 'pbg';
|
||||
$condition = [
|
||||
[ 'pbg.bl_id', 'in', $bl_ids ],
|
||||
];
|
||||
|
||||
$field = 'ngs.sku_id,ngs.goods_id, ngs.sku_name, ngs.price, ngs.sku_image, ngs.stock,ngs.unit,pbg.promotion_price,g.sale_store,pbg.bl_id';
|
||||
$join = [
|
||||
[
|
||||
'goods_sku ngs',
|
||||
'pbg.sku_id = ngs.sku_id',
|
||||
'inner'
|
||||
],
|
||||
[
|
||||
'goods g',
|
||||
'g.goods_id = ngs.goods_id',
|
||||
'left'
|
||||
],
|
||||
];
|
||||
$bundling_goods = model('promotion_bundling_goods')->getList($condition, $field, $order, $alias, $join);
|
||||
|
||||
foreach ($bundling_list as $k => $v)
|
||||
{
|
||||
$bundling_list[$k]['bundling_goods_count'] = 0;
|
||||
foreach ($bundling_goods as $k_goods => $v_goods)
|
||||
{
|
||||
if($v['bl_id'] == $v_goods['bl_id'])
|
||||
{
|
||||
$v_goods[ 'stock' ] = numberFormat($v_goods[ 'stock' ]);
|
||||
$bundling_list[$k]['bundling_goods'][] = $v_goods;
|
||||
$bundling_list[$k]['bundling_goods_count'] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
$goods_sku_detail_array[ 'goods_sku_detail' ][ 'bundling_list' ] = $bundling_list;
|
||||
return $goods_sku_detail_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取组合套餐列表
|
||||
* @param $condition
|
||||
* @param $field
|
||||
* @param $order
|
||||
* @param $alias
|
||||
* @param $join
|
||||
* @param $group
|
||||
* @param $limit
|
||||
* @return array
|
||||
*/
|
||||
public function getBundlingGoodsList($condition = [], $field = '', $order = '', $alias = '', $join = [], $group = null, $limit = null): array
|
||||
{
|
||||
$result = model('promotion_bundling')->getList($condition, $field, $order, $alias, $join, $group, $limit);
|
||||
return $this->success($result);
|
||||
}
|
||||
}
|
||||
272
addon/bundling/model/BundlingOrderCreate.php
Executable file
272
addon/bundling/model/BundlingOrderCreate.php
Executable file
@@ -0,0 +1,272 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\bundling\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use app\model\order\OrderCreate;
|
||||
use app\model\order\OrderCreateTool;
|
||||
use app\model\system\Pay;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 订单创建(优惠套餐)
|
||||
*
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
class BundlingOrderCreate extends BaseModel
|
||||
{
|
||||
|
||||
use OrderCreateTool;
|
||||
|
||||
public $bunding_info;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->promotion_type = 'bundling';
|
||||
$this->promotion_type_name = '组合套餐';
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单创建
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//计算
|
||||
$this->confirm();
|
||||
if ($this->error > 0) {
|
||||
return $this->error([ 'error_code' => $this->error ], $this->error_msg);
|
||||
}
|
||||
model('order')->startTrans();
|
||||
//循环生成多个订单
|
||||
try {
|
||||
|
||||
//订单创建数据
|
||||
$order_insert_data = $this->getOrderInsertData([ 'discount' ], 'invert');
|
||||
$order_insert_data[ 'store_id' ] = $this->store_id;
|
||||
$order_insert_data[ 'create_time' ] = time();
|
||||
$order_insert_data[ 'is_enable_refund' ] = 0;
|
||||
//订单类型以及状态
|
||||
$this->orderType();
|
||||
$order_insert_data[ 'order_type' ] = $this->order_type[ 'order_type_id' ];
|
||||
$order_insert_data[ 'order_type_name' ] = $this->order_type[ 'order_type_name' ];
|
||||
$order_insert_data[ 'order_status_name' ] = $this->order_type[ 'order_status' ][ 'name' ];
|
||||
$order_insert_data[ 'order_status_action' ] = json_encode($this->order_type[ 'order_status' ], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
$this->order_id = model('order')->add($order_insert_data);
|
||||
$order_goods_insert_data = [];
|
||||
//订单项目表
|
||||
foreach ($this->goods_list as &$order_goods_v) {
|
||||
$order_goods_insert_data[] = $this->getOrderGoodsInsertData($order_goods_v);
|
||||
}
|
||||
model('order_goods')->addList($order_goods_insert_data);
|
||||
//扣除余额(统一扣除)
|
||||
$this->useBalance();
|
||||
//批量库存处理(卡密商品支付后在扣出库存)//todo 可以再商品中设置扣除库存步骤
|
||||
$this->batchDecOrderGoodsStock();
|
||||
model('order')->commit();
|
||||
//订单创建后事件
|
||||
$this->orderCreateAfter();
|
||||
//生成整体支付单据
|
||||
$pay_model = new Pay();
|
||||
$pay_model->addPay($this->site_id, $this->out_trade_no, $this->pay_type, $this->order_name, $this->order_name, $this->pay_money, '', 'OrderPayNotify', '', $this->order_id, $this->member_id);
|
||||
return $this->success($this->out_trade_no);
|
||||
} catch (Exception $e) {
|
||||
model('order')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算后的进一步计算(不存缓存,每次都是重新计算)
|
||||
* @return array
|
||||
*/
|
||||
public function confirm()
|
||||
{
|
||||
$order_key = $this->param[ 'order_key' ];
|
||||
$this->getOrderCache($order_key);
|
||||
//初始化地址
|
||||
$this->initMemberAddress();
|
||||
//初始化门店信息
|
||||
$this->initStore();
|
||||
//配送计算
|
||||
$this->calculateDelivery();
|
||||
//批量校验配送方式
|
||||
$this->batchCheckDeliveryType();
|
||||
//计算发票相关
|
||||
$this->calculateInvoice();
|
||||
//计算余额
|
||||
$this->calculateBalcnce();
|
||||
$this->pay_money = $this->order_money - $this->balance_money;
|
||||
//设置过的商品项信息
|
||||
return get_object_vars($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化订单数据
|
||||
*/
|
||||
public function orderPayment()
|
||||
{
|
||||
//计算
|
||||
$this->calculate();
|
||||
//查询配送信息
|
||||
$this->getDeliveryData();
|
||||
//订单初始项
|
||||
event('OrderPayment', [ 'order_object' => $this ]);
|
||||
return get_object_vars($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单计算
|
||||
*/
|
||||
public function calculate()
|
||||
{
|
||||
$this->initMemberAddress();
|
||||
$this->initMemberAccount();//初始化会员账户
|
||||
//组合套餐id 查询订单商品数据
|
||||
$bunding_model = new Bundling();
|
||||
$this->bunding_info = $bunding_model->getBundlingInfo([ [ 'bl_id', '=', $this->param[ 'bl_id' ] ], [ 'site_id', '=', $this->site_id ] ])[ 'data' ] ?? [];
|
||||
if (empty($this->bunding_info)) throw new Exception('找不到活动!');
|
||||
//商品列表信息
|
||||
$this->getOrderGoodsCalculate();
|
||||
$this->shopOrderCalculate();
|
||||
//获取发票相关
|
||||
$this->getInovice();
|
||||
|
||||
$this->order_key = create_no();
|
||||
$this->setOrderCache(get_object_vars($this), $this->order_key);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品的计算信息
|
||||
*/
|
||||
public function getOrderGoodsCalculate()
|
||||
{
|
||||
$this->getBundlingGoodsList();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取组合套餐商品列表信息
|
||||
* @return array
|
||||
*/
|
||||
public function getBundlingGoodsList()
|
||||
{
|
||||
//组装商品列表
|
||||
$field = ' ngbg.sku_id, ngs.sku_name, ngs.sku_no,
|
||||
ngs.price, ngs.discount_price, ngs.cost_price, ngs.stock, ngs.weight, ngs.volume, ngs.sku_image,
|
||||
ngs.site_id, ngs.goods_state, ngs.is_virtual, ngs.support_trade_type,ngs.supplier_id,
|
||||
ngs.is_free_shipping, ngs.shipping_template, ngs.goods_class, ngs.goods_class_name, ngs.goods_id, ns.site_name,ngs.sku_spec_format,ngs.goods_name';
|
||||
$alias = 'ngbg';
|
||||
$join = [
|
||||
[
|
||||
'goods_sku ngs',
|
||||
'ngbg.sku_id = ngs.sku_id',
|
||||
'inner'
|
||||
],
|
||||
[
|
||||
'site ns',
|
||||
'ngs.site_id = ns.site_id',
|
||||
'inner'
|
||||
]
|
||||
];
|
||||
$goods_list = model('promotion_bundling_goods')->getList([ [ 'ngbg.bl_id', '=', $this->param[ 'bl_id' ] ] ], $field, '', $alias, $join);
|
||||
if (!empty($goods_list)) {
|
||||
$num = $this->param[ 'num' ];
|
||||
foreach ($goods_list as $v) {
|
||||
$v[ 'num' ] = $num;
|
||||
$this->is_virtual = $v[ 'is_virtual' ];
|
||||
$price = $v[ 'discount_price' ];
|
||||
$v[ 'price' ] = $price;
|
||||
$v[ 'goods_money' ] = $price * $v[ 'num' ];
|
||||
$v[ 'real_goods_money' ] = $v[ 'goods_money' ];
|
||||
$v[ 'coupon_money' ] = 0;//优惠券金额
|
||||
$v[ 'promotion_money' ] = 0;//优惠金额
|
||||
|
||||
$this->goods_list[] = $v;
|
||||
$order_name = $this->order_name ?? '';
|
||||
if ($order_name) {
|
||||
$len = strlen_mb($order_name);
|
||||
if ($len > 200) {
|
||||
$this->order_name = str_sub($order_name, 200);
|
||||
} else {
|
||||
$this->order_name = string_split($order_name, ',', $v[ 'sku_name' ]);
|
||||
}
|
||||
} else {
|
||||
$this->order_name = string_split('', ',', $v[ 'sku_name' ]);
|
||||
}
|
||||
$this->site_name = $v[ 'site_name' ];
|
||||
$this->goods_num += $v[ 'num' ];
|
||||
$this->goods_money += $v[ 'goods_money' ];
|
||||
//以;隔开的商品项
|
||||
$goods_list_str = $this->goods_list_str ?? '';
|
||||
if ($goods_list_str) {
|
||||
$this->goods_list_str = $goods_list_str . ';' . $v[ 'sku_id' ] . ':' . $v[ 'num' ];
|
||||
} else {
|
||||
$this->goods_list_str = $v[ 'sku_id' ] . ':' . $v[ 'num' ];
|
||||
}
|
||||
//有错误也会导致商品无法购买
|
||||
$item_error = $v[ 'error' ] ?? [];
|
||||
if (!empty($item_error)) {
|
||||
$this->setError(1, $item_error[ 'message' ]);
|
||||
}
|
||||
}
|
||||
|
||||
//循环计算订单项商品价格(受组合套餐的影响)
|
||||
//todo 要考虑原价为0的情况
|
||||
$rate = $this->bunding_info[ 'bl_price' ] * $num / $this->goods_money;//计算组合套餐与原商品价格计算比率
|
||||
$rate = substr(sprintf('%.5f', $rate), 0, -1);
|
||||
|
||||
$this->goods_money = $this->bunding_info[ 'bl_price' ] * $num;//累计金额
|
||||
$total_temp_money = $this->goods_money;
|
||||
$count = count($this->goods_list);
|
||||
foreach ($this->goods_list as $k => &$v) {
|
||||
if ($k == ($count - 1)) {
|
||||
$temp_money = $total_temp_money;
|
||||
$temp_price = round($temp_money / $num, 3);
|
||||
$temp_price = substr(sprintf('%.3f', $temp_price), 0, -1);
|
||||
$temp_money = substr(sprintf('%.3f', $temp_money), 0, -1);
|
||||
} else {
|
||||
$temp_price = round($v[ 'discount_price' ] * $rate, 3);
|
||||
$temp_money = round($v[ 'discount_price' ] * $num * $rate, 3);
|
||||
$temp_price = substr(sprintf('%.3f', $temp_price), 0, -1);
|
||||
$temp_money = substr(sprintf('%.3f', $temp_money), 0, -1);
|
||||
$total_temp_money -= $temp_money;
|
||||
}
|
||||
$v[ 'price' ] = $temp_price;
|
||||
$v[ 'goods_money' ] = $temp_money;
|
||||
$v[ 'real_goods_money' ] = $temp_money;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺订单计算
|
||||
*/
|
||||
public function shopOrderCalculate()
|
||||
{
|
||||
$this->is_free_delivery = $this->bunding_info[ 'shipping_fee_type' ] == 1;
|
||||
//重新计算订单总额
|
||||
$this->getOrderMoney();
|
||||
//理论上是多余的操作
|
||||
if ($this->order_money < 0) {
|
||||
$this->order_money = 0;
|
||||
}
|
||||
//总结计算
|
||||
$this->pay_money = $this->order_money;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user