初始上传
This commit is contained in:
724
addon/pointexchange/model/Exchange.php
Executable file
724
addon/pointexchange/model/Exchange.php
Executable file
@@ -0,0 +1,724 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\pointexchange\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use addon\coupon\model\Coupon;
|
||||
use app\model\goods\Goods;
|
||||
use app\model\upload\Upload;
|
||||
|
||||
/**
|
||||
* 积分兑换
|
||||
*/
|
||||
class Exchange extends BaseModel
|
||||
{
|
||||
public $type = [
|
||||
1 => [
|
||||
'name' => 'goods',
|
||||
'title' => '兑换商品',
|
||||
],
|
||||
2 => [
|
||||
'name' => 'coupon',
|
||||
'title' => '兑换优惠券',
|
||||
],
|
||||
3 => [
|
||||
'name' => 'balance',
|
||||
'title' => '兑换红包',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* 添加积分兑换
|
||||
* @param array $data
|
||||
*/
|
||||
public function addExchange($data)
|
||||
{
|
||||
|
||||
model('promotion_exchange')->startTrans();
|
||||
try {
|
||||
$exchange_goods_data = [
|
||||
'site_id' => $data[ 'site_id' ],
|
||||
'type' => $data[ 'type' ],
|
||||
'type_name' => $data[ 'type_name' ],
|
||||
'state' => $data[ 'state' ],
|
||||
'create_time' => time(),
|
||||
];
|
||||
if ($data[ 'type' ] == 1) {
|
||||
$exchange_goods = $data[ 'goods_data' ];
|
||||
|
||||
foreach ($exchange_goods as $k => $v) {
|
||||
$exist = model('promotion_exchange_goods')->getInfo([ [ 'type', '=', 1 ], [ 'type_id', '=', $v[ 'goods_id' ] ] ], 'id');
|
||||
if (!empty($exist)) {
|
||||
return $this->error('', '商品已存在,请不要重复添加');
|
||||
}
|
||||
$sku_model = new Goods();
|
||||
$sku_info = $sku_model->getGoodsSkuInfo([ [ 'sku_id', '=', $v[ 'sku_list' ][ 0 ][ 'sku_id' ] ] ], 'sku_name,sku_image,price,stock,goods_content')[ 'data' ];
|
||||
$exchange_goods_data[ 'type_id' ] = $v[ 'goods_id' ];
|
||||
$exchange_goods_data[ 'name' ] = $sku_info[ 'sku_name' ];
|
||||
$exchange_goods_data[ 'image' ] = $sku_info[ 'sku_image' ];
|
||||
$exchange_goods_data[ 'point' ] = $v[ 'sku_list' ][ 0 ][ 'point' ];
|
||||
$exchange_goods_data[ 'price' ] = $v[ 'sku_list' ][ 0 ][ 'exchange_price' ];
|
||||
$exchange_goods_data[ 'content' ] = $sku_info[ 'goods_content' ];
|
||||
$exchange_goods_data[ 'rule' ] = $data[ 'rule' ];
|
||||
$exchange_goods_data[ 'pay_type' ] = $v[ 'sku_list' ][ 0 ][ 'exchange_price' ] ? 1 : 0;
|
||||
$exchange_goods_id = model('promotion_exchange_goods')->add($exchange_goods_data);
|
||||
|
||||
foreach ($v[ 'sku_list' ] as $index => $item) {
|
||||
$sku_info = $sku_model->getGoodsSkuInfo([ [ 'sku_id', '=', $item[ 'sku_id' ] ] ], 'sku_name,sku_image,price,stock,goods_content')[ 'data' ];
|
||||
$exchange_data = [
|
||||
'site_id' => $data[ 'site_id' ],
|
||||
'exchange_goods_id' => $exchange_goods_id,
|
||||
'type' => $data[ 'type' ],
|
||||
'type_name' => $data[ 'type_name' ],
|
||||
'type_id' => $item[ 'sku_id' ],
|
||||
'state' => $data[ 'state' ],
|
||||
'rule' => $data[ 'rule' ],
|
||||
'name' => $sku_info[ 'sku_name' ],
|
||||
'image' => $sku_info[ 'sku_image' ],
|
||||
'stock' => $sku_info[ 'stock' ],
|
||||
'pay_type' => empty($item[ 'exchange_price' ]) ? 0 : 1,
|
||||
'point' => $item[ 'point' ],
|
||||
'market_price' => $sku_info[ 'price' ],
|
||||
'price' => $item[ 'exchange_price' ],
|
||||
'limit_num' => $item[ 'limit_num' ],
|
||||
'create_time' => time(),
|
||||
'content' => $sku_info[ 'goods_content' ],
|
||||
|
||||
'is_free_shipping' => $data[ 'is_free_shipping' ], //是否免邮(0不免邮 1免邮)
|
||||
'delivery_type' => $data[ 'delivery_type' ] ?? 1, //运费类型( 0 固定运费 1运费模板 2按照商品)
|
||||
'shipping_template' => $data[ 'shipping_template' ], //运费模板
|
||||
'delivery_price' => $data[ 'delivery_price' ] ?? 0 //运费
|
||||
];
|
||||
model('promotion_exchange')->add($exchange_data);
|
||||
|
||||
}
|
||||
}
|
||||
} elseif ($data[ 'type' ] == 2) {
|
||||
$exist = model('promotion_exchange_goods')->getInfo([ [ 'type', '=', 2 ], [ 'type_id', '=', $data[ 'coupon_type_id' ] ] ], 'id');
|
||||
if (!empty($exist)) {
|
||||
return $this->error('', '该优惠券已存在,请不要重复添加');
|
||||
}
|
||||
|
||||
$coupon = new Coupon();
|
||||
$coupon_type_info = $coupon->getCouponTypeInfo([ [ 'coupon_type_id', '=', $data[ 'coupon_type_id' ] ] ], 'coupon_type_id,coupon_name,money,count,image,status,type,discount')[ 'data' ];
|
||||
|
||||
$exchange_goods_data[ 'type_id' ] = $data[ 'coupon_type_id' ];
|
||||
$exchange_goods_data[ 'name' ] = $coupon_type_info[ 'coupon_name' ];
|
||||
$exchange_goods_data[ 'image' ] = $coupon_type_info[ 'image' ];
|
||||
$exchange_goods_data[ 'point' ] = $data[ 'point' ];
|
||||
$exchange_goods_data[ 'content' ] = $data[ 'content' ];
|
||||
|
||||
$exchange_goods_id = model('promotion_exchange_goods')->add($exchange_goods_data);
|
||||
|
||||
$exchange_data = [
|
||||
'site_id' => $data[ 'site_id' ],
|
||||
'exchange_goods_id' => $exchange_goods_id,
|
||||
'type' => $data[ 'type' ],
|
||||
'type_name' => $data[ 'type_name' ],
|
||||
'state' => $data[ 'state' ],
|
||||
'type_id' => $data[ 'coupon_type_id' ],
|
||||
'name' => $coupon_type_info[ 'coupon_name' ],
|
||||
'image' => $coupon_type_info[ 'image' ],
|
||||
'stock' => $data[ 'stock' ],
|
||||
'pay_type' => 0,
|
||||
'point' => $data[ 'point' ],
|
||||
'create_time' => time(),
|
||||
'content' => $data[ 'content' ],
|
||||
];
|
||||
if ($coupon_type_info[ 'type' ] == 'reward') {
|
||||
$exchange_data[ 'market_price' ] = $coupon_type_info[ 'money' ];
|
||||
} elseif ($coupon_type_info[ 'type' ] == 'discount') {
|
||||
$exchange_data[ 'market_price' ] = $coupon_type_info[ 'discount' ];
|
||||
}
|
||||
|
||||
model('promotion_exchange')->add($exchange_data);
|
||||
|
||||
} elseif ($data[ 'type' ] == 3) {
|
||||
|
||||
$exchange_goods_data[ 'name' ] = $data[ 'name' ];
|
||||
$exchange_goods_data[ 'image' ] = $data[ 'image' ];
|
||||
$exchange_goods_data[ 'point' ] = $data[ 'point' ];
|
||||
$exchange_goods_data[ 'balance' ] = $data[ 'balance' ];
|
||||
$exchange_goods_data[ 'content' ] = $data[ 'content' ];
|
||||
|
||||
$exchange_goods_id = model('promotion_exchange_goods')->add($exchange_goods_data);
|
||||
|
||||
$exchange_data = [
|
||||
'site_id' => $data[ 'site_id' ],
|
||||
'exchange_goods_id' => $exchange_goods_id,
|
||||
'type' => $data[ 'type' ],
|
||||
'type_name' => $data[ 'type_name' ],
|
||||
'state' => $data[ 'state' ],
|
||||
'name' => $data[ 'name' ],
|
||||
'image' => $data[ 'image' ],
|
||||
'stock' => $data[ 'stock' ],
|
||||
'pay_type' => 0,
|
||||
'point' => $data[ 'point' ],
|
||||
'balance' => $data[ 'balance' ],
|
||||
'create_time' => time(),
|
||||
'content' => $data[ 'content' ],
|
||||
];
|
||||
|
||||
model('promotion_exchange')->add($exchange_data);
|
||||
}
|
||||
|
||||
model('promotion_exchange')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('promotion_exchange')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑积分兑换
|
||||
* @param array $data
|
||||
*/
|
||||
public function editExchange($data)
|
||||
{
|
||||
model('promotion_exchange')->startTrans();
|
||||
try {
|
||||
$exchange_goods_id = $data[ 'id' ];
|
||||
if ($data[ 'type' ] == 1) {
|
||||
$goods_data = $data[ 'goods_data' ];
|
||||
|
||||
$sku_model = new Goods();
|
||||
$sku_info = $sku_model->getGoodsSkuInfo([ [ 'sku_id', '=', $goods_data[ 0 ][ 'sku_id' ] ] ], 'sku_name,sku_image,price,stock,goods_content')[ 'data' ];
|
||||
$exchange_goods_data = [
|
||||
'modify_time' => time(),
|
||||
'pay_type' => $goods_data[ 0 ][ 'exchange_price' ] ? 1 : 0,
|
||||
];
|
||||
$exchange_goods_data[ 'name' ] = $sku_info[ 'sku_name' ];
|
||||
$exchange_goods_data[ 'image' ] = $sku_info[ 'sku_image' ];
|
||||
$exchange_goods_data[ 'point' ] = $goods_data[ 0 ][ 'point' ];
|
||||
$exchange_goods_data[ 'price' ] = $goods_data[ 0 ][ 'exchange_price' ];
|
||||
$exchange_goods_data[ 'content' ] = $sku_info[ 'goods_content' ];
|
||||
$exchange_goods_data[ 'rule' ] = $data[ 'rule' ];
|
||||
$exchange_goods_data[ 'state' ] = $data[ 'state' ];
|
||||
model('promotion_exchange_goods')->update($exchange_goods_data, [ [ 'id', '=', $exchange_goods_id ] ]);
|
||||
|
||||
model('promotion_exchange')->delete([ [ 'exchange_goods_id', '=', $exchange_goods_id ] ]);
|
||||
|
||||
foreach ($goods_data as $index => $item) {
|
||||
$sku_info = $sku_model->getGoodsSkuInfo([ [ 'sku_id', '=', $item[ 'sku_id' ] ] ], 'sku_name,sku_image,price,stock,goods_content')[ 'data' ];
|
||||
$exchange_data = [
|
||||
'site_id' => $data[ 'site_id' ],
|
||||
'exchange_goods_id' => $exchange_goods_id,
|
||||
'type' => $data[ 'type' ],
|
||||
'type_name' => $data[ 'type_name' ],
|
||||
'type_id' => $item[ 'sku_id' ],
|
||||
'state' => $data[ 'state' ],
|
||||
'rule' => $data[ 'rule' ],
|
||||
'name' => $sku_info[ 'sku_name' ],
|
||||
'image' => $sku_info[ 'sku_image' ],
|
||||
'stock' => $sku_info[ 'stock' ],
|
||||
'pay_type' => empty($item[ 'exchange_price' ]) ? 0 : 1,
|
||||
'point' => $item[ 'point' ],
|
||||
'market_price' => $sku_info[ 'price' ],
|
||||
'price' => $item[ 'exchange_price' ],
|
||||
'limit_num' => $item[ 'limit_num' ],
|
||||
'create_time' => time(),
|
||||
'content' => $sku_info[ 'goods_content' ],
|
||||
|
||||
'is_free_shipping' => $data[ 'is_free_shipping' ], //是否免邮(0不免邮 1免邮)
|
||||
'delivery_type' => $data[ 'delivery_type' ] ?? 1, //运费类型( 0 固定运费 1运费模板 2按照商品)
|
||||
'shipping_template' => $data[ 'shipping_template' ], //运费模板
|
||||
'delivery_price' => $data[ 'delivery_price' ] ?? 0 //运费
|
||||
|
||||
];
|
||||
model('promotion_exchange')->add($exchange_data);
|
||||
}
|
||||
|
||||
} else if ($data[ 'type' ] == 2) {
|
||||
$coupon = new Coupon();
|
||||
$coupon_type_info = $coupon->getCouponTypeInfo([ [ 'coupon_type_id', '=', $data[ 'coupon_type_id' ] ] ], 'coupon_type_id,coupon_name,money,count,image,status,type,discount')[ 'data' ];
|
||||
$exchange_goods_data = [];
|
||||
$exchange_goods_data[ 'type_id' ] = $data[ 'coupon_type_id' ];
|
||||
$exchange_goods_data[ 'name' ] = $coupon_type_info[ 'coupon_name' ];
|
||||
$exchange_goods_data[ 'image' ] = $coupon_type_info[ 'image' ];
|
||||
$exchange_goods_data[ 'point' ] = $data[ 'point' ];
|
||||
$exchange_goods_data[ 'content' ] = $data[ 'content' ];
|
||||
$exchange_goods_data[ 'state' ] = $data[ 'state' ];
|
||||
|
||||
model('promotion_exchange_goods')->update($exchange_goods_data, [ [ 'id', '=', $exchange_goods_id ] ]);
|
||||
$exchange_data = [
|
||||
'site_id' => $data[ 'site_id' ],
|
||||
'exchange_goods_id' => $exchange_goods_id,
|
||||
'type' => $data[ 'type' ],
|
||||
'type_name' => $data[ 'type_name' ],
|
||||
'state' => $data[ 'state' ],
|
||||
'type_id' => $data[ 'coupon_type_id' ],
|
||||
'name' => $coupon_type_info[ 'coupon_name' ],
|
||||
'image' => $coupon_type_info[ 'image' ],
|
||||
'stock' => $data[ 'stock' ],
|
||||
'pay_type' => 0,
|
||||
'point' => $data[ 'point' ],
|
||||
'create_time' => time(),
|
||||
'content' => $data[ 'content' ],
|
||||
];
|
||||
if ($coupon_type_info[ 'type' ] == 'reward') {
|
||||
$exchange_data[ 'market_price' ] = $coupon_type_info[ 'money' ];
|
||||
} elseif ($coupon_type_info[ 'type' ] == 'discount') {
|
||||
$exchange_data[ 'market_price' ] = $coupon_type_info[ 'discount' ];
|
||||
}
|
||||
model('promotion_exchange')->delete([ [ 'exchange_goods_id', '=', $exchange_goods_id ] ]);
|
||||
model('promotion_exchange')->add($exchange_data);
|
||||
|
||||
} else if ($data[ 'type' ] == 3) {
|
||||
$exchange_goods_data = [];
|
||||
$exchange_goods_data[ 'name' ] = $data[ 'name' ];
|
||||
$exchange_goods_data[ 'image' ] = $data[ 'image' ];
|
||||
$exchange_goods_data[ 'point' ] = $data[ 'point' ];
|
||||
$exchange_goods_data[ 'balance' ] = $data[ 'balance' ];
|
||||
$exchange_goods_data[ 'content' ] = $data[ 'content' ];
|
||||
$exchange_goods_data[ 'state' ] = $data[ 'state' ];
|
||||
|
||||
$exchange_goods_info = model('promotion_exchange_goods')->getInfo([ [ 'id', '=', $exchange_goods_id ] ]);
|
||||
if (!empty($exchange_goods_info[ 'image' ]) && !empty($data[ 'image' ]) && $exchange_goods_info[ 'image' ] != $data[ 'image' ]) {
|
||||
$upload_model = new Upload();
|
||||
$upload_model->deletePic($exchange_goods_info[ 'image' ], $data[ 'site_id' ]);
|
||||
}
|
||||
|
||||
model('promotion_exchange_goods')->update($exchange_goods_data, [ [ 'id', '=', $exchange_goods_id ] ]);
|
||||
|
||||
$exchange_data = [
|
||||
'site_id' => $data[ 'site_id' ],
|
||||
'exchange_goods_id' => $exchange_goods_id,
|
||||
'type' => $data[ 'type' ],
|
||||
'type_name' => $data[ 'type_name' ],
|
||||
'state' => $data[ 'state' ],
|
||||
'name' => $data[ 'name' ],
|
||||
'image' => $data[ 'image' ],
|
||||
'stock' => $data[ 'stock' ],
|
||||
'pay_type' => 0,
|
||||
'point' => $data[ 'point' ],
|
||||
'balance' => $data[ 'balance' ],
|
||||
'create_time' => time(),
|
||||
'content' => $data[ 'content' ],
|
||||
];
|
||||
model('promotion_exchange')->delete([ [ 'exchange_goods_id', '=', $exchange_goods_id ] ]);
|
||||
model('promotion_exchange')->add($exchange_data);
|
||||
|
||||
}
|
||||
|
||||
model('promotion_exchange')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('promotion_exchange')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除积分兑换
|
||||
* @param string $ids
|
||||
*/
|
||||
public function deleteExchange($ids)
|
||||
{
|
||||
$list = model("promotion_exchange")->getList([ [ 'exchange_goods_id', 'in', $ids ] ]);
|
||||
if ($list) {
|
||||
foreach ($list as $k => $v) {
|
||||
if (!empty($v[ 'image' ])) {
|
||||
$upload_model = new Upload();
|
||||
$upload_model->deletePic($v[ 'image' ], $v[ 'site_id' ]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
model("promotion_exchange")->delete([ [ 'exchange_goods_id', 'in', $ids ] ]);
|
||||
model("promotion_exchange_goods")->delete([ [ 'id', 'in', $ids ] ]);
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取积分兑换信息
|
||||
* @param int $id
|
||||
*/
|
||||
public function getExchangeInfo($id, $field = '*', $sku_id = 0)
|
||||
{
|
||||
|
||||
$condition = [
|
||||
[ 'exchange_goods_id', '=', $id ]
|
||||
];
|
||||
if ($sku_id) $condition[] = [ 'type_id', '=', $sku_id ];
|
||||
|
||||
$info = model("promotion_exchange")->getInfo($condition, $field);
|
||||
if (!empty($info) && !empty($info[ 'type' ])) {
|
||||
switch ( $info[ 'type' ] ) {
|
||||
case 1:
|
||||
//商品
|
||||
$goods = new Goods();
|
||||
$goods_sku_info = $goods->getGoodsSkuInfo([ [ 'sku_id', '=', $info[ 'type_id' ], [ 'goods_state', '=', 1 ], [ 'is_delete', '=', 0 ] ] ], 'sku_id,sku_name,stock')[ 'data' ];
|
||||
if (!empty($goods_sku_info)) {
|
||||
$goods_sku_info[ 'stock' ] = numberFormat($goods_sku_info[ 'stock' ]);
|
||||
$info = array_merge($info, $goods_sku_info);
|
||||
} else {
|
||||
$info = [];
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
//优惠券
|
||||
$coupon = new Coupon();
|
||||
$coupon_type_info = $coupon->getCouponTypeInfo([ [ 'coupon_type_id', '=', $info[ 'type_id' ] ] ], 'type as coupon_type,discount_limit,count,lead_count')[ 'data' ];
|
||||
|
||||
if (!empty($coupon_type_info)) {
|
||||
$info = array_merge($info, $coupon_type_info);
|
||||
} else {
|
||||
$info = [];
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
//余额红包
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $this->success($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取积分兑换商品详情
|
||||
* @param $id
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function getExchangeGoodsDetail($id, $site_id)
|
||||
{
|
||||
$info = model("promotion_exchange_goods")->getInfo([ [ 'id', '=', $id ], [ 'site_id', '=', $site_id ] ], 'id,type,type_name,type_id,name,image,pay_type,point,price,delivery_price,balance,state,content,rule');
|
||||
// 兑换类型,1:商品,2:优惠券,3:红包
|
||||
switch ( $info[ 'type' ] ) {
|
||||
case 1:
|
||||
//商品
|
||||
$goods_sku = model('goods_sku')->getList([ [ 'goods_id', '=', $info[ 'type_id' ] ], [ 'is_delete', '=', 0 ], [ 'goods_state', '=', 1 ] ], 'stock, price,sku_id,sku_name,discount_price,stock as goods_stock,sku_image,sku_images,goods_id,site_id,goods_content');
|
||||
$exchange_list = model("promotion_exchange")->getList([ [ 'exchange_goods_id', '=', $id ], [ 'site_id', '=', $site_id ] ], 'limit_num, id,type,type_name,type_id,name,image,pay_type,point,price,delivery_price,balance,state,content,delivery_type,is_free_shipping,shipping_template,rule');
|
||||
|
||||
foreach ($goods_sku as $k => $v) {
|
||||
$goods_sku[ $k ][ 'is_select' ] = 0;
|
||||
$goods_sku[ $k ][ 'exchange_price' ] = 0;
|
||||
$goods_sku[ $k ][ 'point' ] = 0;
|
||||
$goods_sku[ $k ][ 'limit_num' ] = 0;
|
||||
$goods_sku[ $k ][ 'stock' ] = numberFormat($goods_sku[ $k ][ 'stock' ]);
|
||||
$goods_sku[ $k ][ 'goods_stock' ] = numberFormat($goods_sku[ $k ][ 'goods_stock' ]);
|
||||
foreach ($exchange_list as $key => $val) {
|
||||
if ($val[ 'type_id' ] == $v[ 'sku_id' ]) {
|
||||
$goods_sku[ $k ][ 'is_select' ] = 1;
|
||||
$goods_sku[ $k ][ 'exchange_price' ] = $val[ 'price' ];
|
||||
$goods_sku[ $k ][ 'limit_num' ] = $val[ 'limit_num' ];
|
||||
$goods_sku[ $k ][ 'point' ] = $val[ 'point' ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$info[ 'goods_sku' ] = $goods_sku;
|
||||
$info[ 'exchange_goods' ] = $exchange_list;
|
||||
|
||||
break;
|
||||
case 2:
|
||||
//优惠券
|
||||
$coupon = new Coupon();
|
||||
$coupon_type_info = $coupon->getCouponTypeInfo([ [ 'coupon_type_id', '=', $info[ 'type_id' ] ] ], 'coupon_type_id,coupon_name,money,count as stock,status,lead_count,max_fetch,at_least,end_time,validity_type,fixed_term,goods_type,is_limit,type as coupon_type,discount_limit,discount')[ 'data' ];
|
||||
$exchange_info = model("promotion_exchange")->getInfo([ [ 'exchange_goods_id', '=', $id ], [ 'site_id', '=', $site_id ] ], 'market_price,stock');
|
||||
if (!empty($coupon_type_info)) {
|
||||
$info = array_merge($info, $coupon_type_info);
|
||||
} else {
|
||||
$info = [];
|
||||
}
|
||||
$info = array_merge($info, $exchange_info);
|
||||
|
||||
break;
|
||||
case 3:
|
||||
//余额红包
|
||||
$exchange_info = model("promotion_exchange")->getInfo([ [ 'exchange_goods_id', '=', $id ], [ 'site_id', '=', $site_id ] ], 'stock');
|
||||
if (!empty($exchange_info)) {
|
||||
$info = array_merge($info, $exchange_info);
|
||||
} else {
|
||||
$info = [];
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!empty($info)) {
|
||||
return $this->success($info);
|
||||
} else {
|
||||
return $this->error('', '该兑换物品已失效');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取积分兑换列表
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @param null $limit
|
||||
* @param string $alias
|
||||
* @param array $join
|
||||
* @return array
|
||||
*/
|
||||
public function getExchangeList($condition = [], $field = '*', $order = '', $limit = null, $alias = '', $join = [])
|
||||
{
|
||||
$list = model('promotion_exchange')->getList($condition, $field, $order, $alias, $join, '', $limit);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取积分兑换列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @param string $alias
|
||||
* @param array $join
|
||||
* @return array
|
||||
*/
|
||||
public function getExchangePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'create_time desc', $field = '*', $alias = '', $join = [])
|
||||
{
|
||||
$list = model('promotion_exchange')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取积分兑换列表
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @param null $limit
|
||||
* @return array
|
||||
*/
|
||||
public function getExchangeGoodsList($condition = [], $field = '*', $order = '', $limit = null)
|
||||
{
|
||||
$list = model('promotion_exchange_goods')->getList($condition, $field, $order, '', '', '', $limit);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取积分兑换列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @param string $alias
|
||||
* @param array $join
|
||||
* @return array
|
||||
*/
|
||||
public function getExchangeGoodsPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'create_time desc', $field = '*', $alias = '', $join = [])
|
||||
{
|
||||
$list = model('promotion_exchange_goods')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
|
||||
if(!empty($list['list']))
|
||||
{
|
||||
$goods_id_array = [];
|
||||
foreach ($list['list'] as $k => $v)
|
||||
{
|
||||
if($v['type'] == 1)
|
||||
{
|
||||
$goods_id_array[] = $v['type_id'];
|
||||
}
|
||||
}
|
||||
if(!empty($goods_id_array))
|
||||
{
|
||||
$goods_array = [];
|
||||
$goods_ids = implode(",", $goods_id_array);
|
||||
$goods_list = model('goods')->getList([ [ 'goods_id', 'in', $goods_ids ], ['is_delete', '=', 0] ], "goods_id, goods_name, is_delete");
|
||||
if(!empty($goods_list))
|
||||
{
|
||||
$key = array_column($goods_list, 'goods_id');
|
||||
$goods_array = array_combine($key, $goods_list);
|
||||
}
|
||||
|
||||
}
|
||||
foreach ($list[ 'list' ] as $k => $v) {
|
||||
if ($v[ 'type' ] == 1) {
|
||||
$goods_info = $goods_array[$v['type_id']] ?? [];
|
||||
if (empty($goods_info)) {
|
||||
unset($list[ 'list' ][ $k ]);
|
||||
} else {
|
||||
if ($goods_info[ 'is_delete' ] == 1) {
|
||||
unset($list[ 'list' ][ $k ]);
|
||||
} else {
|
||||
$list[ 'list' ][ $k ][ 'g_name' ] = $goods_info[ 'goods_name' ];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加库存
|
||||
* @param $param
|
||||
*/
|
||||
public function incStock($param)
|
||||
{
|
||||
$condition = array (
|
||||
[ "id", "=", $param[ "id" ] ]
|
||||
);
|
||||
$num = $param[ "num" ];
|
||||
$info = model("promotion_exchange")->getInfo($condition, "stock, name");
|
||||
if (empty($info))
|
||||
return $this->error(-1, "");
|
||||
|
||||
//编辑sku库存
|
||||
$result = model("promotion_exchange")->setInc($condition, "stock", $num);
|
||||
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 减少库存
|
||||
* @param $param
|
||||
*/
|
||||
public function decStock($param)
|
||||
{
|
||||
$condition = array (
|
||||
[ "id", "=", $param[ "id" ] ]
|
||||
);
|
||||
$num = $param[ "num" ];
|
||||
|
||||
$info = model("promotion_exchange")->getInfo($condition, "stock, name, type");
|
||||
if (empty($info))
|
||||
return $this->error();
|
||||
|
||||
if ($info[ 'type' ] == 2 && $info[ 'stock' ] == -1) {
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
if ($info[ "stock" ] < 0) {
|
||||
return $this->error('', $info[ "name" ] . "库存不足!");
|
||||
}
|
||||
|
||||
//编辑sku库存
|
||||
$result = model("promotion_exchange")->setDec($condition, "stock", $num);
|
||||
if ($result === false)
|
||||
return $this->error();
|
||||
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改标签排序
|
||||
* @param $sort
|
||||
* @param $id
|
||||
* @return array
|
||||
*/
|
||||
public function modifyExchangeSort($sort, $id)
|
||||
{
|
||||
$res = model('promotion_exchange_goods')->update([ 'sort' => $sort ], [ [ 'id', '=', $id ] ]);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 兑换商品详情
|
||||
* @param array $condition
|
||||
* @param int $type
|
||||
* @return array
|
||||
*/
|
||||
public function getExchangeDetail($condition = [], $type = 1)
|
||||
{
|
||||
$alias = 'pe';
|
||||
$field = 'peg.type,peg.id as exchange_id, pe.id,pe.type_id as sku_id,peg.type_id as goods_id,pe.pay_type,pe.point, pe.price as exchange_price, pe.limit_num,
|
||||
pe.delivery_price,pe.balance,pe.state,pe.content,pe.exchange_goods_id,pe.rule';
|
||||
$join = [
|
||||
[ 'promotion_exchange_goods peg', 'pe.exchange_goods_id = peg.id', 'inner' ]
|
||||
];
|
||||
if ($type == 1) {
|
||||
$condition[] = [ 'g.goods_state', '=', 1 ];
|
||||
$condition[] = [ 'g.is_delete', '=', 0 ];
|
||||
|
||||
$field .= ',sku.site_id,sku.sku_name,sku.sku_spec_format,sku.price,sku.promotion_type,sku.stock,sku.click_num,
|
||||
(sku.sale_num + sku.virtual_sale) as sale_num,sku.collect_num,sku.sku_image,
|
||||
sku.sku_images,sku.site_id,sku.goods_content,sku.goods_state,sku.is_virtual,
|
||||
sku.is_free_shipping,sku.goods_spec_format,sku.goods_attr_format,sku.introduction,
|
||||
sku.unit,sku.video_url,sku.evaluate,sku.goods_service_ids,g.goods_image,g.goods_stock,g.goods_name,sku.qr_id,g.stock_show,g.sale_show';
|
||||
|
||||
$join[] = [ 'goods_sku sku', 'pe.type_id = sku.sku_id', 'inner' ];
|
||||
$join[] = [ 'goods g', 'g.goods_id = sku.goods_id', 'inner' ];
|
||||
} else if ($type == 2) {
|
||||
$join[] = [ 'promotion_coupon_type pct', 'pct.coupon_type_id = peg.type_id', 'inner' ];
|
||||
$field .= ',pe.stock,pct.type as coupon_type,pct.discount_limit,pct.image,pct.coupon_name as name,pct.count, pct.lead_count
|
||||
,pct.money, pct.discount, pct.at_least, pct.validity_type,pct.fixed_term,pct.end_time, pct.image';
|
||||
// $condition[] = [ 'pct.is_show', '=', 1 ];
|
||||
// $condition[] = [ 'pct.is_forbidden', '=', 0 ];
|
||||
|
||||
} else if ($type == 3) {
|
||||
$field .= ',pe.stock,pe.name,pe.image,pe.balance';
|
||||
}
|
||||
$info = model('promotion_exchange')->getInfo($condition, $field, $alias, $join);
|
||||
if (!empty($info)) {
|
||||
if (isset($info[ 'stock' ])) {
|
||||
$info[ 'stock' ] = numberFormat($info[ 'stock' ]);
|
||||
}
|
||||
if (isset($info[ 'sale_num' ])) {
|
||||
$info[ 'sale_num' ] = numberFormat($info[ 'sale_num' ]);
|
||||
}
|
||||
}
|
||||
return $this->success($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 兑换商品详情
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getExchangeSkuList($condition = [], $type = 1)
|
||||
{
|
||||
$alias = 'pe';
|
||||
$field = 'peg.type,peg.id as exchange_id, pe.id,pe.type_id as sku_id,peg.type_id as goods_id,pe.pay_type,pe.point, pe.price as exchange_price, pe.limit_num,
|
||||
pe.delivery_price,pe.balance,pe.state,pe.exchange_goods_id,pe.rule';
|
||||
$join = [
|
||||
[ 'promotion_exchange_goods peg', 'pe.exchange_goods_id = peg.id', 'inner' ]
|
||||
];
|
||||
if ($type == 1) {
|
||||
$condition[] = [ 'g.goods_state', '=', 1 ];
|
||||
$condition[] = [ 'g.is_delete', '=', 0 ];
|
||||
|
||||
$field .= ',sku.sku_name,sku.sku_spec_format,sku.price,sku.stock,sku.sku_image,sku.sku_images,sku.goods_spec_format,g.goods_image';
|
||||
|
||||
$join[] = [ 'goods_sku sku', 'pe.type_id = sku.sku_id', 'inner' ];
|
||||
$join[] = [ 'goods g', 'g.goods_id = sku.goods_id', 'inner' ];
|
||||
} else if ($type == 2) {
|
||||
$join[] = [ 'promotion_coupon_type pct', 'pct.coupon_type_id = peg.type_id', 'inner' ];
|
||||
$field .= ',pe.stock,pct.type as coupon_type,pct.discount_limit,pct.image,pct.coupon_name as name,pct.count, pct.lead_count
|
||||
,pct.money, pct.discount, pct.at_least, pct.validity_type,pct.fixed_term,pct.end_time, pct.image';
|
||||
|
||||
} else if ($type == 3) {
|
||||
$field .= ',pe.stock,pe.name,pe.image,pe.balance';
|
||||
}
|
||||
$list = model('promotion_exchange')->getList($condition, $field, '', $alias, $join);
|
||||
foreach ($list as $k => $v) {
|
||||
if (isset($v[ 'stock' ])) {
|
||||
$list[ $k ][ 'stock' ] = numberFormat($list[ $k ][ 'stock' ]);
|
||||
}
|
||||
}
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断规格值是否禁用
|
||||
* @param $id
|
||||
* @param $site_id
|
||||
* @param string $goods_spec_format
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function getGoodsSpecFormat($id, $site_id, $goods_spec_format = '')
|
||||
{
|
||||
//获取活动参与的商品sku_ids
|
||||
$sku_ids = model('promotion_exchange')->getColumn([ [ 'exchange_goods_id', '=', $id ], [ 'site_id', '=', $site_id ] ], 'type_id');
|
||||
$goods_model = new Goods();
|
||||
$res = $goods_model->getGoodsSpecFormat($sku_ids, $goods_spec_format);
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
376
addon/pointexchange/model/Order.php
Executable file
376
addon/pointexchange/model/Order.php
Executable file
@@ -0,0 +1,376 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\pointexchange\model;
|
||||
|
||||
use addon\coupon\model\Coupon;
|
||||
use app\dict\member_account\AccountDict;
|
||||
use app\dict\order\OrderGoodsDict;
|
||||
use app\model\member\MemberAccount;
|
||||
use app\model\BaseModel;
|
||||
use app\model\order\VirtualOrder;
|
||||
use app\model\system\Pay;
|
||||
use app\model\order\OrderCreate;
|
||||
use app\model\order\Order as CommonOrder;
|
||||
use app\model\order\StoreOrder;
|
||||
use app\model\order\LocalOrder;
|
||||
use app\model\order\OrderCommon;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 积分兑换订单
|
||||
*/
|
||||
class Order extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 支付订单
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function orderPay($data)
|
||||
{
|
||||
$out_trade_no = $data[ 'out_trade_no' ];
|
||||
$order_info = model('promotion_exchange_order')->getInfo([ [ 'out_trade_no', '=', $out_trade_no ] ], '*');
|
||||
if (empty($order_info)) {
|
||||
return $this->error([], '找不到可支付的订单');
|
||||
}
|
||||
if ($order_info[ 'order_status' ] == 1) {
|
||||
return $this->error([], '当前订单已支付');
|
||||
}
|
||||
model('promotion_exchange_order')->startTrans();
|
||||
try {
|
||||
$order_data = array (
|
||||
'order_status' => 1,
|
||||
'pay_time' => time()
|
||||
);
|
||||
switch ( $order_info[ 'type' ] ) {
|
||||
case 1://商品
|
||||
//添加对应商品订单
|
||||
$order_create = new OrderCreate();
|
||||
$order_no = $order_create->createOrderNo();
|
||||
|
||||
//查询兑换的商品信息
|
||||
$exchange_info = model('promotion_exchange')->getInfo([ [ 'id', '=', $order_info[ 'exchange_id' ] ] ], 'price,type_id');
|
||||
$sku_info = model('goods_sku')->getInfo([ [ 'sku_id', '=', $exchange_info[ 'type_id' ] ] ], 'sku_id,sku_name,sku_no,sku_image,is_virtual,goods_class,goods_class_name,cost_price,goods_id,goods_name,sku_spec_format,supplier_id');
|
||||
|
||||
//订单类型
|
||||
$order_type = $this->orderType($order_info[ 'delivery_type' ], $sku_info[ 'is_virtual' ]);
|
||||
$data_order = [
|
||||
'order_no' => $order_no,
|
||||
'site_id' => $order_info[ 'site_id' ],
|
||||
'site_name' => '',
|
||||
'order_from' => $order_info[ 'order_from' ],
|
||||
'order_from_name' => $order_info[ 'order_from_name' ],
|
||||
'order_type' => $order_type[ 'order_type_id' ],
|
||||
'order_type_name' => $order_type[ 'order_type_name' ],
|
||||
'order_status_name' => $order_type[ 'order_status' ][ 'name' ],
|
||||
'order_status_action' => json_encode($order_type[ 'order_status' ], JSON_UNESCAPED_UNICODE),
|
||||
'out_trade_no' => $out_trade_no,
|
||||
'member_id' => $order_info[ 'member_id' ],
|
||||
'name' => $order_info[ 'name' ],
|
||||
'mobile' => $order_info[ 'mobile' ],
|
||||
'telephone' => $order_info[ 'telephone' ],
|
||||
'province_id' => $order_info[ 'province_id' ],
|
||||
'city_id' => $order_info[ 'city_id' ],
|
||||
'district_id' => $order_info[ 'district_id' ],
|
||||
'community_id' => $order_info[ 'community_id' ],
|
||||
'address' => $order_info[ 'address' ],
|
||||
'full_address' => $order_info[ 'full_address' ],
|
||||
'longitude' => $order_info[ 'longitude' ],
|
||||
'latitude' => $order_info[ 'latitude' ],
|
||||
'buyer_ip' => '',
|
||||
'goods_money' => $order_info[ 'exchange_price' ] * $order_info[ 'num' ],
|
||||
'delivery_money' => $order_info[ 'delivery_price' ],
|
||||
'coupon_id' => 0,
|
||||
'coupon_money' => 0,
|
||||
'adjust_money' => 0,
|
||||
'invoice_money' => 0,
|
||||
'promotion_money' => 0,
|
||||
'order_money' => $order_info[ 'order_money' ],
|
||||
'balance_money' => 0,
|
||||
'pay_money' => $order_info[ 'order_money' ],
|
||||
'create_time' => time(),
|
||||
'is_enable_refund' => $order_type[ 'order_type_id' ] == 4 ? 0 : 1,
|
||||
'order_name' => $order_info[ 'exchange_name' ],
|
||||
'goods_num' => $order_info[ 'num' ],
|
||||
'delivery_type' => $order_info[ 'delivery_type' ],
|
||||
'delivery_type_name' => $order_info[ 'delivery_type_name' ],
|
||||
'delivery_store_id' => $order_info[ 'delivery_store_id' ],
|
||||
'delivery_store_name' => $order_info[ 'delivery_store_name' ],
|
||||
'delivery_store_info' => $order_info[ 'delivery_store_info' ],
|
||||
'buyer_message' => $order_info[ 'buyer_message' ],
|
||||
|
||||
'invoice_delivery_money' => 0,
|
||||
'taxpayer_number' => '',
|
||||
'invoice_rate' => 0,
|
||||
'invoice_content' => '',
|
||||
'invoice_full_address' => '',
|
||||
'is_invoice' => 0,
|
||||
'invoice_type' => 0,
|
||||
'invoice_title' => '',
|
||||
'is_tax_invoice' => '',
|
||||
'invoice_email' => '',
|
||||
'invoice_title_type' => 0,
|
||||
|
||||
'buyer_ask_delivery_time' => $order_info[ 'buyer_ask_delivery_time' ],//定时达
|
||||
'delivery_start_time' => $order_info[ 'delivery_start_time' ],
|
||||
'delivery_end_time' => $order_info[ 'delivery_end_time' ],
|
||||
|
||||
'promotion_type' => 'pointexchange',
|
||||
'promotion_type_name' => '积分兑换',
|
||||
'store_id' => $order_info[ 'delivery_store_id' ]
|
||||
];
|
||||
$order_id = model('order')->add($data_order);
|
||||
$order_data[ 'relate_order_id' ] = $order_id;
|
||||
|
||||
$data_order_goods = [
|
||||
'order_id' => $order_id,
|
||||
'site_id' => $order_info[ 'site_id' ],
|
||||
'order_no' => $order_no,
|
||||
'member_id' => $order_info[ 'member_id' ],
|
||||
'sku_id' => $sku_info[ 'sku_id' ],
|
||||
'sku_name' => $sku_info[ 'sku_name' ],
|
||||
'sku_image' => $sku_info[ 'sku_image' ],
|
||||
'sku_no' => $sku_info[ 'sku_no' ],
|
||||
'is_virtual' => $sku_info[ 'is_virtual' ],
|
||||
'goods_class' => $sku_info[ 'goods_class' ],
|
||||
'goods_class_name' => $sku_info[ 'goods_class_name' ],
|
||||
'price' => $order_info[ 'exchange_price' ],
|
||||
'cost_price' => $sku_info[ 'cost_price' ],
|
||||
'num' => $order_info[ 'num' ],
|
||||
'goods_money' => $order_info[ 'exchange_price' ] * $order_info[ 'num' ],
|
||||
'cost_money' => $sku_info[ 'cost_price' ] * $order_info[ 'num' ],
|
||||
'goods_id' => $sku_info[ 'goods_id' ],
|
||||
'delivery_status' => OrderGoodsDict::wait_delivery,
|
||||
'delivery_status_name' => OrderGoodsDict::getDeliveryStatus(OrderGoodsDict::wait_delivery),
|
||||
'real_goods_money' => $order_info[ 'exchange_price' ] * $order_info[ 'num' ],
|
||||
'coupon_money' => 0,
|
||||
'promotion_money' => 0,
|
||||
|
||||
'goods_name' => $sku_info[ 'goods_name' ],
|
||||
'sku_spec_format' => $sku_info[ 'sku_spec_format' ],
|
||||
'store_id' => $order_info[ 'delivery_store_id' ],
|
||||
'supplier_id' => $sku_info[ 'supplier_id' ] ?? 0
|
||||
];
|
||||
model('order_goods')->add($data_order_goods);
|
||||
$order_common = new OrderCommon();
|
||||
$pay = new Pay();
|
||||
$pay_info = $pay->getPayInfo($out_trade_no);
|
||||
|
||||
$res = $order_common->orderOnlinePay($pay_info[ 'data' ]);
|
||||
if (isset($res[ 'code' ]) && $res[ 'code' ] != 0) {
|
||||
Log::write('积分兑换商品订单支付失败:' . $res[ 'message' ]);
|
||||
}
|
||||
break;
|
||||
case 2://优惠券
|
||||
$coupon_model = new Coupon();
|
||||
$res = $coupon_model->giveCoupon([ [ 'coupon_type_id' => $order_info[ 'type_id' ], 'num' => $order_info[ 'num' ] ] ], $order_info[ 'site_id' ], $order_info[ 'member_id' ], Coupon::GET_TYPE_ACTIVITY_GIVE);
|
||||
break;
|
||||
case 3://红包
|
||||
$member_account_model = new MemberAccount();
|
||||
$res = $member_account_model->addMemberAccount($order_info[ 'site_id' ], $order_info[ 'member_id' ], AccountDict::balance, $order_info[ 'balance' ], 'order', '积分兑换,', '积分兑换');
|
||||
break;
|
||||
}
|
||||
|
||||
model('promotion_exchange_order')->update($order_data, [ [ 'order_id', '=', $order_info[ 'order_id' ] ] ]);
|
||||
|
||||
//积分兑换订单支付
|
||||
event('PointExchangeOrderPay', $order_info);
|
||||
|
||||
model('promotion_exchange_order')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('promotion_exchange_order')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function orderType($type_name, $is_virtual = 0)
|
||||
{
|
||||
if ($type_name == 'express') {
|
||||
$order = new CommonOrder();
|
||||
return [
|
||||
'order_type_id' => 1,
|
||||
'order_type_name' => '普通订单',
|
||||
'order_status' => $order->order_status[ 0 ]
|
||||
];
|
||||
} elseif ($type_name == 'store') {
|
||||
$order = new StoreOrder();
|
||||
return [
|
||||
'order_type_id' => 2,
|
||||
'order_type_name' => '自提订单',
|
||||
'order_status' => $order->order_status[ 0 ]
|
||||
];
|
||||
} elseif ($type_name == 'local') {
|
||||
$order = new LocalOrder();
|
||||
return [
|
||||
'order_type_id' => 3,
|
||||
'order_type_name' => '外卖订单',
|
||||
'order_status' => $order->order_status[ 0 ]
|
||||
];
|
||||
} elseif ($is_virtual) {
|
||||
$order = new VirtualOrder();
|
||||
return [
|
||||
'order_type_id' => 4,
|
||||
'order_type_name' => '虚拟订单',
|
||||
'order_status' => $order->order_status[ 0 ]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭订单
|
||||
* @param $order_id
|
||||
* @return array|int|mixed|void
|
||||
*/
|
||||
public function closeOrder($order_id)
|
||||
{
|
||||
$order_info = model('promotion_exchange_order')->getInfo([ [ 'order_id', '=', $order_id ] ], '*');
|
||||
|
||||
if (empty($order_info)) return $this->error();
|
||||
|
||||
model('promotion_exchange_order')->startTrans();
|
||||
try {
|
||||
$data = array (
|
||||
'order_status' => -1,
|
||||
);
|
||||
$result = model('promotion_exchange_order')->update($data, [ [ 'order_id', '=', $order_id ] ]);
|
||||
|
||||
//返还积分
|
||||
$member_account_model = new MemberAccount();
|
||||
$member_account_result = $member_account_model->addMemberAccount($order_info[ 'site_id' ], $order_info[ 'member_id' ], 'point', $order_info[ 'point' ], 'pointexchangerefund', $order_id, '积分兑换关闭返还');
|
||||
|
||||
if ($member_account_result[ 'code' ] < 0) {
|
||||
model('promotion_exchange_order')->rollback();
|
||||
return $member_account_result;
|
||||
}
|
||||
|
||||
//判断库存
|
||||
$exchange_model = new Exchange();
|
||||
switch ( $order_info[ 'type' ] ) {//兑换类型
|
||||
case '1'://商品
|
||||
// $sku_info = model('goods_sku')->getInfo( [ ['sku_id','=',$order_info['type_id']] ], '');
|
||||
// if(!empty($sku_info)){
|
||||
// //库存变化
|
||||
// $goods_stock_model = new GoodsStock();
|
||||
// $stock_result = $goods_stock_model->incStock(['sku_id' => $order_info['type_id'], 'num' => $order_info['num']]);
|
||||
// if ($stock_result['code'] != 0) {
|
||||
// model('promotion_exchange_order')->rollback();
|
||||
// return $stock_result;
|
||||
// }
|
||||
// }
|
||||
break;
|
||||
case '2'://优惠券
|
||||
//返回优惠券库存
|
||||
$coupon_model = new Coupon();
|
||||
$coupon_info = $coupon_model->getCouponTypeInfo([ [ 'coupon_type_id', '=', $order_info[ 'type_id' ] ] ], 'coupon_type_id');
|
||||
if (!empty($coupon_info)) {
|
||||
$result = $coupon_model->incStock([ [ 'coupon_type_id', '=', $order_info[ 'type_id' ] ], [ 'num', '=', $order_info[ 'num' ] ] ]);
|
||||
}
|
||||
break;
|
||||
case '3'://红包
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
//返还套餐库存
|
||||
$exchange_model->incStock([ 'id' => $order_info[ 'exchange_id' ], 'num' => $order_info[ 'num' ] ]);
|
||||
|
||||
if ($order_info[ 'type' ] == 1 && $order_info[ 'order_money' ] > 0 && $order_info[ 'order_status' ] == 0) {
|
||||
//关闭支付
|
||||
$pay_model = new Pay();
|
||||
$result = $pay_model->closePay($order_info[ 'out_trade_no' ]);//关闭旧支付单据
|
||||
if ($result[ 'code' ] < 0) {
|
||||
model('promotion_exchange_order')->rollback();
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
model('promotion_exchange_order')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('promotion_exchange_order')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取积分兑换订单信息
|
||||
* @param $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getOrderInfo($condition, $field = '*')
|
||||
{
|
||||
$res = model('promotion_exchange_order')->getInfo($condition, $field);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单列表
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @param null $limit
|
||||
* @return array
|
||||
*/
|
||||
public function getOrderList($condition = [], $field = '*', $order = '', $limit = null)
|
||||
{
|
||||
$list = model('promotion_exchange_order')->getList($condition, $field, $order, '', '', '', $limit);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单总和
|
||||
* @param array $where
|
||||
* @param string $field
|
||||
* @param string $alias
|
||||
* @param null $join
|
||||
* @return array
|
||||
*/
|
||||
public function getOrderSum($where = [], $field = '', $alias = 'a', $join = null)
|
||||
{
|
||||
$data = model('promotion_exchange_order')->getSum($where, $field, $alias, $join);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取积分兑换订单分页列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getExchangePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*', $alias = '', $join = [])
|
||||
{
|
||||
$list = model('promotion_exchange_order')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发货
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function delivery($param)
|
||||
{
|
||||
$order_id = $param[ 'order_id' ];
|
||||
$delivery_code = $param[ 'delivery_code' ];
|
||||
$order_data = array (
|
||||
'delivery_status' => OrderGoodsDict::delivery,
|
||||
'delivery_status_name' => OrderGoodsDict::getDeliveryStatus(OrderGoodsDict::delivery),
|
||||
'delivery_code' => $delivery_code
|
||||
);
|
||||
$res = model('promotion_exchange_order')->update($order_data, [ [ 'order_id', '=', $order_id ] ]);
|
||||
return $this->success();
|
||||
}
|
||||
}
|
||||
314
addon/pointexchange/model/OrderCreate.php
Executable file
314
addon/pointexchange/model/OrderCreate.php
Executable file
@@ -0,0 +1,314 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\pointexchange\model;
|
||||
|
||||
use app\dict\order\OrderGoodsDict;
|
||||
use app\model\BaseModel;
|
||||
use app\model\express\Config as ExpressConfig;
|
||||
use app\model\express\Express;
|
||||
use app\model\express\Local;
|
||||
use app\model\goods\Goods;
|
||||
use app\model\member\Member;
|
||||
use app\model\member\MemberAccount;
|
||||
use app\model\member\MemberAddress;
|
||||
use app\model\order\Config;
|
||||
use app\model\order\LocalOrder;
|
||||
use app\model\order\Order as CommonOrder;
|
||||
use app\model\order\OrderCreateTool;
|
||||
use app\model\order\StoreOrder;
|
||||
use app\model\store\Store;
|
||||
use app\model\system\Cron;
|
||||
use app\model\system\Pay;
|
||||
use extend\exception\OrderException;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* 积分兑换
|
||||
*/
|
||||
class OrderCreate extends BaseModel
|
||||
{
|
||||
use OrderCreateTool;
|
||||
|
||||
|
||||
public $point = 0;
|
||||
public $balance = 0;
|
||||
public $exchange_info = [];
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->promotion_type = 'pointexchange';
|
||||
$this->promotion_type_name = '积分商城';
|
||||
$this->is_limit_start_money = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//计算
|
||||
$this->confirm();
|
||||
if ($this->error > 0) {
|
||||
return $this->error([ 'error_code' => $this->error ], $this->error_msg);
|
||||
}
|
||||
model('promotion_exchange_order')->startTrans();
|
||||
try {
|
||||
$this->order_no = $this->createOrderNo();
|
||||
$pay_model = new Pay();
|
||||
$this->out_trade_no = $pay_model->createOutTradeNo($this->member_id);
|
||||
//配送数据
|
||||
if ($this->exchange_info[ 'type' ] == 1) {
|
||||
$express_type_list = $this->config('delivery_type');
|
||||
$delivery_type_name = $express_type_list[ $this->delivery[ 'delivery_type' ] ] ?? '';
|
||||
}
|
||||
$order_id = 0;
|
||||
$delivery_time_data = $this->delivery[ 'buyer_ask_delivery_time' ] ?? [];
|
||||
$order_data = array (
|
||||
'order_no' => $this->order_no,
|
||||
'member_id' => $this->member_id,
|
||||
'out_trade_no' => $this->out_trade_no,
|
||||
'point' => $this->point,
|
||||
'exchange_price' => $this->exchange_info[ 'price' ],
|
||||
'delivery_price' => $this->delivery_money,
|
||||
'price' => $this->exchange_info[ 'price' ],
|
||||
'order_money' => $this->order_money,
|
||||
'create_time' => time(),
|
||||
'exchange_id' => $this->exchange_info[ 'id' ],
|
||||
'exchange_goods_id' => $this->exchange_info[ 'exchange_goods_id' ],
|
||||
'exchange_name' => $this->exchange_info[ 'name' ],
|
||||
'exchange_image' => $this->exchange_info[ 'image' ],
|
||||
'num' => $this->goods_num,
|
||||
'order_status' => 0,
|
||||
'type' => $this->exchange_info[ 'type' ],
|
||||
'type_name' => $this->exchange_info[ 'type_name' ],
|
||||
'name' => $this->delivery[ 'member_address' ][ 'name' ] ?? '',
|
||||
'mobile' => $this->delivery[ 'member_address' ][ 'mobile' ] ?? '',
|
||||
'telephone' => $this->delivery[ 'member_address' ][ 'telephone' ] ?? '',
|
||||
'province_id' => $this->delivery[ 'member_address' ][ 'province_id' ] ?? '',
|
||||
'city_id' => $this->delivery[ 'member_address' ][ 'city_id' ] ?? '',
|
||||
'district_id' => $this->delivery[ 'member_address' ][ 'district_id' ] ?? '',
|
||||
'community_id' => $this->delivery[ 'member_address' ][ 'community_id' ] ?? '',
|
||||
'address' => $this->delivery[ 'member_address' ][ 'address' ] ?? '',
|
||||
'full_address' => $this->delivery[ 'member_address' ][ 'full_address' ] ?? '',
|
||||
'longitude' => $this->delivery[ 'member_address' ][ 'longitude' ] ?? '',
|
||||
'latitude' => $this->delivery[ 'member_address' ][ 'latitude' ] ?? '',
|
||||
'delivery_store_id' => $this->delivery[ 'store_id' ] ?? 0,
|
||||
'delivery_store_name' => $this->delivery[ 'delivery_store_name' ] ?? '',
|
||||
'delivery_store_info' => $this->delivery[ 'delivery_store_info' ] ?? '',
|
||||
//配送时间
|
||||
'buyer_ask_delivery_time' => $delivery_time_data[ 'remark' ] ?? '',//定时达
|
||||
'delivery_start_time' => $delivery_time_data[ 'start_time' ] ?? '',//配送开始时间
|
||||
'delivery_end_time' => $delivery_time_data[ 'end_time' ] ?? '',//配送结束时间
|
||||
|
||||
'order_from' => $this->order_from,
|
||||
'order_from_name' => $this->order_from_name,
|
||||
'buyer_message' => $this->param[ 'buyer_message' ],
|
||||
'type_id' => $this->exchange_info[ 'type_id' ],
|
||||
'balance' => $this->balance,
|
||||
'site_id' => $this->site_id,
|
||||
'order_id' => $order_id,
|
||||
'delivery_type' => $this->delivery[ 'delivery_type' ] ?? '',
|
||||
'delivery_type_name' => $delivery_type_name ?? '',
|
||||
'delivery_status' => OrderGoodsDict::wait_delivery,
|
||||
'delivery_status_name' => OrderGoodsDict::getDeliveryStatus(OrderGoodsDict::wait_delivery),
|
||||
);
|
||||
|
||||
$this->order_id = model('promotion_exchange_order')->add($order_data);
|
||||
//判断库存
|
||||
$exchange_model = new Exchange();
|
||||
|
||||
//减去套餐的库存
|
||||
$exchange_result = $exchange_model->decStock([ 'id' => $this->exchange_info[ 'id' ], 'num' => $this->goods_num ]);
|
||||
if ($exchange_result[ 'code' ] < 0) {
|
||||
model('promotion_exchange_order')->rollback();
|
||||
return $exchange_result;
|
||||
}
|
||||
//扣除积分
|
||||
$member_account_model = new MemberAccount();
|
||||
$member_account_result = $member_account_model->addMemberAccount($this->site_id, $this->member_id, 'point', -$this->point, 'pointexchange', $order_id, '积分兑换扣除');
|
||||
if ($member_account_result[ 'code' ] < 0) {
|
||||
model('promotion_exchange_order')->rollback();
|
||||
return $this->error($member_account_result,'账户积分不足');
|
||||
}
|
||||
if ($this->exchange_info[ 'type' ] == 1) {
|
||||
$goods_info = $this->goods_list[ 0 ];
|
||||
$stock_result = $this->skuDecStock($goods_info, $this->store_id);
|
||||
if ($stock_result[ 'code' ] != 0) {
|
||||
model('promotion_exchange_order')->rollback();
|
||||
return $stock_result;
|
||||
}
|
||||
}
|
||||
model('promotion_exchange_order')->commit();
|
||||
// 积分兑换订单生成后操作
|
||||
event('PointExchangeOrderCreate', [ 'order_id' => $order_id, 'create_data' => get_object_vars($this) ]);
|
||||
//支付单据
|
||||
$pay_model->addPay($this->site_id, $this->out_trade_no, 'POINT', $this->order_name, $this->order_name, $this->order_money, '', 'PointexchangeOrderPayNotify', '', $this->order_id, $this->member_id);
|
||||
return $this->success($this->out_trade_no);
|
||||
} catch (\Exception $e) {
|
||||
model('promotion_exchange_order')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 待支付订单
|
||||
* @param $data
|
||||
*/
|
||||
public function payment()
|
||||
{
|
||||
$this->calculate();//计算并查询套餐信息
|
||||
if ($this->exchange_info[ 'type' ] == 1) {
|
||||
//查询配送信息
|
||||
$this->getDeliveryData();
|
||||
}
|
||||
|
||||
return get_object_vars($this);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算后的进一步计算(不存缓存,每次都是重新计算)
|
||||
* @return array
|
||||
*/
|
||||
public function confirm()
|
||||
{
|
||||
$order_key = $this->param[ 'order_key' ];
|
||||
$this->getOrderCache($order_key);
|
||||
//初始化地址
|
||||
$this->initMemberAddress();
|
||||
//初始化门店信息
|
||||
$this->initStore();
|
||||
if ($this->exchange_info[ 'type' ] == 1) {
|
||||
//配送计算
|
||||
$this->calculateDelivery();
|
||||
|
||||
if ($this->exchange_info[ 'is_free_shipping' ] == 0 && $this->exchange_info[ 'delivery_type' ] == 0) {
|
||||
//固定运费
|
||||
$this->delivery_money = $this->exchange_info[ 'delivery_price' ];
|
||||
}
|
||||
}
|
||||
|
||||
$this->order_money = $this->goods_money + $this->delivery_money;
|
||||
$this->pay_money = $this->order_money;
|
||||
//设置过的商品项信息
|
||||
return get_object_vars($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算
|
||||
* @param $data
|
||||
*/
|
||||
public function calculate()
|
||||
{
|
||||
$this->initMemberAddress();
|
||||
$this->initMemberAccount(); //初始化会员账户
|
||||
|
||||
|
||||
$id = $this->param[ 'id' ];
|
||||
$sku_id = $this->param[ 'sku_id' ];
|
||||
$num = $this->param[ 'num' ];
|
||||
$exchange_model = new Exchange();
|
||||
$exchange_info = $exchange_model->getExchangeInfo($id, '*', $sku_id)[ 'data' ] ?? [];
|
||||
if (empty($exchange_info)) throw new OrderException('找不到对应的积分兑换活动!');
|
||||
$this->exchange_info = $exchange_info;
|
||||
if ($this->exchange_info[ 'state' ] == 0) {
|
||||
$this->error = 1;
|
||||
$this->error_msg = '当前兑换活动未开启!';
|
||||
}
|
||||
|
||||
if ($this->exchange_info[ 'type' ] == 1 && $exchange_info[ 'limit_num' ] > 0) {
|
||||
// 已兑换数量
|
||||
$exchangeed_num = model('promotion_exchange_order')->getSum([ [ 'exchange_id', '=', $this->exchange_info[ 'id' ] ], [ 'order_status', '<>', '-1' ], [ 'member_id', '=', $this->member_id ] ], 'num');
|
||||
if (($exchangeed_num + $num) > $this->exchange_info[ 'limit_num' ]) {
|
||||
$this->error = 1;
|
||||
$this->error_msg = '最多可以兑换'.$this->exchange_info[ 'limit_num' ].'件';
|
||||
if($exchangeed_num > 0){
|
||||
$this->error_msg .= ',您已兑换'.$exchangeed_num.'件';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->exchange_info[ 'stock' ] <= 0) {
|
||||
if ($this->exchange_info[ 'type' ] == 2 && $this->exchange_info[ 'stock' ] < 0) {
|
||||
} else {
|
||||
$this->error = 1;
|
||||
$this->error_msg = '当前兑换库存不足!';
|
||||
}
|
||||
}
|
||||
|
||||
//兑换类型为1时 兑换物品为商品(相对优惠券和红包来说较为特殊)
|
||||
if ($this->exchange_info[ 'type' ] == 1) {
|
||||
$goods_model = new Goods();
|
||||
$goods_info = $goods_model->getGoodsSkuInfo([ [ 'sku_id', '=', $this->exchange_info[ 'sku_id' ] ], [ 'site_id', '=', $this->site_id ] ], '*')[ 'data' ] ?? [];
|
||||
if (empty($goods_info)) throw new OrderException('商品不存在!');
|
||||
$goods_info[ 'num' ] = $num;
|
||||
if ($this->exchange_info[ 'type' ] == 1) {
|
||||
if ($exchange_info[ 'is_free_shipping' ] == 1) {
|
||||
//免邮
|
||||
$goods_info[ 'is_free_shipping' ] = 1;
|
||||
} else {
|
||||
if ($this->exchange_info[ 'delivery_type' ] == 2) {
|
||||
|
||||
} else if ($this->exchange_info[ 'delivery_type' ] == 1) {
|
||||
//运费模板
|
||||
$goods_info[ 'shipping_template' ] = $this->exchange_info[ 'shipping_template' ];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
$goods_info[ 'goods_money' ] = $this->exchange_info[ 'price' ] * $num;
|
||||
$this->goods_list[] = $goods_info;
|
||||
$this->is_virtual = $goods_info[ 'is_virtual' ];
|
||||
|
||||
|
||||
}
|
||||
$point = $this->exchange_info[ 'point' ];
|
||||
$price = $this->exchange_info[ 'price' ];
|
||||
$balance = $exchange_info[ 'balance' ];
|
||||
$goods_num = $num;
|
||||
|
||||
$this->goods_money = $price * $num;
|
||||
|
||||
$this->order_money = $this->goods_money;
|
||||
$this->pay_money = $this->order_money;
|
||||
$this->order_name = $this->exchange_info[ 'name' ] . '【' . $this->exchange_info[ 'type_name' ] . '】';
|
||||
$this->point = $point * $num;
|
||||
$this->price = $price * $num;
|
||||
$this->goods_num = $goods_num;
|
||||
$this->balance = $balance * $num;
|
||||
|
||||
$this->order_key = create_no();
|
||||
$this->setOrderCache(get_object_vars($this), $this->order_key);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 增加订单自动关闭事件
|
||||
*/
|
||||
public function addOrderCronClose()
|
||||
{
|
||||
//计算订单自动关闭时间
|
||||
$config_model = new Config();
|
||||
$order_config_result = $config_model->getOrderEventTimeConfig($this->site_id);
|
||||
$order_config = $order_config_result[ 'data' ];
|
||||
$now_time = time();
|
||||
if (!empty($order_config)) {
|
||||
$execute_time = $now_time + $order_config[ 'value' ][ 'auto_close' ] * 60;//自动关闭时间
|
||||
} else {
|
||||
$execute_time = $now_time + 3600;//尚未配置 默认一天
|
||||
}
|
||||
$cron_model = new Cron();
|
||||
$cron_model->addCron(1, 0, '积分兑换订单自动关闭', 'CronExchangeOrderClose', $execute_time, $this->order_id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
155
addon/pointexchange/model/share/WchatShare.php
Executable file
155
addon/pointexchange/model/share/WchatShare.php
Executable file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\pointexchange\model\share;
|
||||
|
||||
use addon\pointexchange\model\Exchange as ExchangeModel;
|
||||
use app\model\share\WchatShareBase as BaseModel;
|
||||
use app\model\system\Config as ConfigModel;
|
||||
|
||||
/**
|
||||
* 分享
|
||||
*/
|
||||
class WchatShare extends BaseModel
|
||||
{
|
||||
protected $config = [
|
||||
[
|
||||
'title' => '积分商城',
|
||||
'config_key' => 'WCHAT_SHARE_CONFIG_POINTEXCHANGE_LIST',
|
||||
'path' => [ '/pages_promotion/point/list' ],
|
||||
'method_prefix' => 'goodsList',
|
||||
],
|
||||
[
|
||||
'title' => '积分商品',
|
||||
'config_key' => 'WCHAT_SHARE_CONFIG_POINTEXCHANGE_DETAIL',
|
||||
'path' => [ '/pages_promotion/point/detail' ],
|
||||
'method_prefix' => 'goodsDetail',
|
||||
],
|
||||
];
|
||||
|
||||
protected $sort = 6;
|
||||
|
||||
/**
|
||||
* 积分商城列表
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function goodsListShareData($param)
|
||||
{
|
||||
//跳转路径
|
||||
$link = $this->getShareLink($param);
|
||||
$config_data = $this->goodsListShareConfig($param)[ 'value' ];
|
||||
|
||||
$data = [
|
||||
'link' => $link,
|
||||
'desc' => $config_data[ 'desc' ],
|
||||
'imgUrl' => $config_data[ 'imgUrl' ],
|
||||
'title' => $config_data[ 'title' ]
|
||||
];
|
||||
return [
|
||||
'permission' => [
|
||||
'hideOptionMenu' => false,
|
||||
'hideMenuItems' => [],
|
||||
],
|
||||
'data' => $data,//分享内容
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分商城列表分享配置
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function goodsListShareConfig($param)
|
||||
{
|
||||
$site_id = $param[ 'site_id' ];
|
||||
$config = $param[ 'config' ];
|
||||
|
||||
$config_model = new ConfigModel();
|
||||
$data = $config_model->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', $config[ 'config_key' ] ] ])[ 'data' ];
|
||||
if (empty($data[ 'value' ])) {
|
||||
$data[ 'value' ] = [
|
||||
'title' => "积分商城",
|
||||
'desc' => "积分兑换更优惠哦",
|
||||
'imgUrl' => ''
|
||||
];
|
||||
}
|
||||
if (empty($data[ 'value' ][ 'imgUrl' ])) {
|
||||
$data[ 'value' ][ 'imgUrl' ] = img('addon/pointexchange/icon.png');
|
||||
}
|
||||
return [
|
||||
'value' => $data[ 'value' ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分商城详情
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function goodsDetailShareData($param)
|
||||
{
|
||||
$site_id = $param[ 'site_id' ] ?? 0;
|
||||
parse_str(parse_url($param[ 'url' ])[ 'query' ] ?? '', $query);
|
||||
|
||||
if (isset($query[ 'id' ])) {
|
||||
$id = $query[ 'id' ];
|
||||
$exchange_model = new ExchangeModel();
|
||||
$exchange_info = $exchange_model->getExchangeInfo($id, 'type, type_id');
|
||||
$exchange_info = $exchange_info[ 'data' ];
|
||||
$condition = [
|
||||
[ 'peg.id', '=', $id ],
|
||||
[ 'peg.site_id', '=', $site_id ],
|
||||
[ 'peg.state', '=', 1 ],
|
||||
];
|
||||
$exchange_detail = $exchange_model->getExchangeDetail($condition, $exchange_info[ 'type' ])[ 'data' ];
|
||||
if (!empty($exchange_detail)) {
|
||||
$image_url = '';
|
||||
$title = '';
|
||||
switch ( $exchange_detail[ 'type' ] ) {
|
||||
case 1://商品
|
||||
$title = $exchange_detail[ 'sku_name' ];
|
||||
$image_url = $exchange_detail[ 'sku_image' ];
|
||||
break;
|
||||
case 2://优惠券
|
||||
case 3://红包
|
||||
$title = $exchange_detail[ 'name' ];
|
||||
$image_url = $exchange_detail[ 'image' ];
|
||||
break;
|
||||
}
|
||||
if ($image_url) {
|
||||
$image_url = img($image_url);
|
||||
} else {
|
||||
$image_url = $this->getDefaultShareIcon();
|
||||
}
|
||||
$exchange_condition = [];
|
||||
if ($exchange_detail[ 'point' ] > 0) $exchange_condition[] = "{$exchange_detail['point']}积分";
|
||||
if ($exchange_detail[ 'exchange_price' ] > 0) $exchange_condition[] = "¥{$exchange_detail['exchange_price']}";
|
||||
$desc = "仅需" . join("+", $exchange_condition) . "即可兑换";
|
||||
$link = $this->getShareLink($param);
|
||||
|
||||
$data = [
|
||||
'title' => $title,
|
||||
'desc' => $desc,
|
||||
'link' => $link,
|
||||
'imgUrl' => $image_url,
|
||||
];
|
||||
return [
|
||||
'permission' => [
|
||||
'hideOptionMenu' => false,
|
||||
'hideMenuItems' => [],
|
||||
],
|
||||
'data' => $data,//分享内容
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
90
addon/pointexchange/model/share/WeappShare.php
Executable file
90
addon/pointexchange/model/share/WeappShare.php
Executable file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\pointexchange\model\share;
|
||||
|
||||
use app\model\share\WeappShareBase;
|
||||
use app\model\system\Config as ConfigModel;
|
||||
|
||||
/**
|
||||
* 分享
|
||||
*/
|
||||
class WeappShare extends WeappShareBase
|
||||
{
|
||||
protected $config = [
|
||||
[
|
||||
'title' => '积分商城列表',
|
||||
'config_key' => 'WEAPP_SHARE_CONFIG_POINTEXCHANGE_LIST',
|
||||
'path' => ['/pages_promotion/point/list'],
|
||||
'method_prefix' => 'pointexchangeList',
|
||||
],
|
||||
];
|
||||
|
||||
protected $sort = 13;
|
||||
|
||||
/**
|
||||
* 积分商城列表
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function pointexchangeListShareData($param)
|
||||
{
|
||||
//获取和替换配置数据
|
||||
$config_data = $this->pointexchangeListShareConfig($param);
|
||||
$title = $config_data['value']['title'];
|
||||
$image_url = $config_data['value']['imageUrl'] ? img($config_data['value']['imageUrl']) : '';
|
||||
$path = $this->getSharePath($param);
|
||||
|
||||
$data = [
|
||||
'title' => $title,
|
||||
'path' => $path,
|
||||
'imageUrl' => $image_url,
|
||||
];
|
||||
return [
|
||||
'permission' => [
|
||||
'onShareAppMessage' => true,
|
||||
'onShareTimeline' => true,
|
||||
],
|
||||
'data' => $data,//分享内容
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分商城列表
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function pointexchangeListShareConfig($param)
|
||||
{
|
||||
$site_id = $param['site_id'];
|
||||
$config = $param['config'];
|
||||
|
||||
$config_model = new ConfigModel();
|
||||
$data = $config_model->getConfig([
|
||||
['site_id', '=', $site_id],
|
||||
['app_module', '=', 'shop'],
|
||||
['config_key', '=', $config['config_key']],
|
||||
])['data'];
|
||||
if (empty($data['value'])) {
|
||||
$data['value'] = [
|
||||
'title' => '用积分兑换更有优惠哦!',
|
||||
'imageUrl' => '',
|
||||
];
|
||||
}
|
||||
$variable = [];
|
||||
|
||||
return [
|
||||
'value' => $data['value'],
|
||||
'variable' => $variable,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user