初始上传

This commit is contained in:
2026-04-04 17:27:12 +08:00
parent 4d80d28eb4
commit b7e11774ee
11191 changed files with 1588469 additions and 0 deletions

1006
addon/pintuan/model/Pintuan.php Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,513 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\pintuan\model;
use app\model\BaseModel;
use app\model\message\Message;
use app\model\order\OrderCommon;
use app\model\order\OrderRefund;
use app\model\system\Cron;
/**
* 拼团组
*/
class PintuanGroup extends BaseModel
{
/**
* 创建拼团组
* @param $pintuan_order_info
* @return array|\multitype
*/
public function addPintuanGroup($pintuan_order_info)
{
model('promotion_pintuan_group')->startTrans();
//获取拼团信息
$pintuan_model = new Pintuan();
$pintuan_id = $pintuan_order_info[ 'pintuan_id' ];
$pintuan_info = $pintuan_model->getPintuanInfo([ [ 'pintuan_id', '=', $pintuan_id ] ])[ 'data' ] ?? [];
$pintuan_type = $pintuan_info[ 'pintuan_type' ];//类型
switch ( $pintuan_type ) {
case 'ordinary'://默认拼团方式
$pintuan_num = $pintuan_info[ 'pintuan_num' ];
break;
case 'ladder'://阶梯拼团
$pintuan_num = $pintuan_order_info[ 'pintuan_num' ];
break;
}
try {
$data = [
'site_id' => $pintuan_info[ 'site_id' ],
'goods_id' => $pintuan_info[ 'goods_id' ],
'is_virtual_goods' => $pintuan_info[ 'is_virtual_goods' ],
'pintuan_id' => $pintuan_order_info[ 'pintuan_id' ],
'head_id' => $pintuan_order_info[ 'head_id' ],
'pintuan_num' => $pintuan_num,
'pintuan_count' => 1,
'create_time' => time(),
'end_time' => time() + ( $pintuan_info[ 'pintuan_time' ] * 60 ),
'status' => 2,
'is_virtual_buy' => $pintuan_info[ 'is_virtual_buy' ],
'is_single_buy' => $pintuan_info[ 'is_single_buy' ],
'is_promotion' => $pintuan_info[ 'is_promotion' ],
'buy_num' => $pintuan_info[ 'buy_num' ],
];
$res = model('promotion_pintuan_group')->add($data);
//添加拼团组关闭事件
$cron = new Cron();
$cron->addCron(1, 0, "拼团组关闭", "ClosePintuanGroup", $data[ 'end_time' ], $res);
//更新拼团开组人数及购买人数
$pintua_data = [
'group_num' => $pintuan_info[ 'group_num' ] + 1,
'order_num' => $pintuan_info[ 'order_num' ] + 1,
];
$pintuan_model->editPintuanNum($pintua_data, [ [ 'pintuan_id', '=', $pintuan_order_info[ 'pintuan_id' ] ] ]);
model('promotion_pintuan_group')->commit();
return $this->success($res);
} catch (\Exception $e) {
model('promotion_pintuan_group')->rollback();
return $this->error('', $e->getMessage());
}
}
/**
* 编辑组信息
* @param array $condition
* @param array $data
* @return array
*/
public function editPintuanGroup($condition = [], $data = [])
{
$res = model('promotion_pintuan_group')->update($data, $condition);
return $this->success($res);
}
/**
* 加入拼团组
* @param $pintuan_order_info
* @return array|\multitype
*/
public function joinPintuanGroup($pintuan_order_info)
{
model('promotion_pintuan_group')->startTrans();
//获取拼团信息
$pintuan_model = new Pintuan();
$pintuan_id = $pintuan_order_info[ 'pintuan_id' ];
$pintuan = $pintuan_model->getPintuanInfo([ [ 'pintuan_id', '=', $pintuan_id ] ]);
$pintuan_info = $pintuan[ 'data' ];
try {
$order_num = $pintuan_info[ 'order_num' ] + 1;
$success_group_num = $pintuan_info[ 'success_group_num' ];
//获取拼团组信息
$group_info = $this->getPintuanGroupInfo([ [ 'group_id', '=', $pintuan_order_info[ 'group_id' ] ] ])[ 'data' ] ?? [];
//更新拼团组当前数量及状态
$pintuan_count = $group_info[ 'pintuan_count' ] + 1;
$res = $this->editPintuanGroup([ [ 'group_id', '=', $pintuan_order_info[ 'group_id' ] ] ], [ 'pintuan_count' => $pintuan_count ]);
if ($pintuan_count == $group_info[ 'pintuan_num' ]) {//已成团
$success_group_num += 1;
//修改拼团组状态
model('promotion_pintuan_group')->update([ 'status' => 3 ], [ [ 'group_id', '=', $pintuan_order_info[ 'group_id' ] ] ]);
//查询该组所有订单
$pintuan_order_model = new PintuanOrder();
$pintuan_order = $pintuan_order_model->getPintuanOrderList([ [ 'group_id', '=', $pintuan_order_info[ 'group_id' ] ] ], 'order_id,pintuan_status');
$pintuan_order_list = $pintuan_order[ 'data' ];
$message_model = new Message();
$order_model = new OrderCommon();
if (!empty($pintuan_order_list)) {
foreach ($pintuan_order_list as $v) {
switch ( $v[ 'pintuan_status' ] ) {
case 0:
//将未支付的修改为失败
model('promotion_pintuan_order')->update([ 'pintuan_status' => 1 ], [ [ 'order_id', '=', $v[ 'order_id' ] ] ]);
//开放订单
$order_model->orderUnlock($v[ 'order_id' ]);
//关闭订单
$result = $order_model->orderClose($v[ 'order_id' ], [], '当前拼团已成团,由于您未及时支付,该订单已关闭');
if ($result[ "code" ] < 0) {
model('promotion_pintuan_group')->rollback();
return $result;
}
//更新订单营销状态名称
model('order')->update([ 'promotion_status_name' => '拼团失败' ], [ [ 'order_id', '=', $v[ 'order_id' ] ] ]);
// 发送消息
$param = [ 'keywords' => 'PINTUAN_FAIL', 'time' => time(), 'order_id' => $v[ 'order_id' ], 'site_id' => $group_info[ 'site_id' ] ];
$message_model->sendMessage($param);
break;
break;
case 2://已支付
//将已支付的修改为成功
model('promotion_pintuan_order')->update([ 'pintuan_status' => 3 ], [ [ 'order_id', '=', $v[ 'order_id' ] ] ]);
//开放订单
$order_model->orderUnlock($v[ 'order_id' ]);
//更新订单营销状态名称
model('order')->update([ 'promotion_status_name' => '拼团成功', 'is_enable_refund' => 1 ], [ [ 'order_id', '=', $v[ 'order_id' ] ] ]);
//针对虚拟订单执行收发货操作
// if ($group_info['is_virtual_goods'] == 1) {
// $order_model->orderCommonTakeDelivery($v['order_id']);
// }
$pintuan_order_model = new PintuanOrder();
$pintuan_order_model->virtualSuccessAction($v[ 'order_id' ]);
// 发送消息
$param = [ 'keywords' => 'PINTUAN_COMPLETE', 'time' => time(), 'order_id' => $v[ 'order_id' ], 'site_id' => $group_info[ 'site_id' ] ];
$message_model->sendMessage($param);
break;
}
}
}
}
//更新拼团 购买人数
$pintuan_model->editPintuanNum([ 'order_num' => $order_num, 'success_group_num' => $success_group_num ], [ [ 'pintuan_id', '=', $pintuan_order_info[ 'pintuan_id' ] ] ]);
model('promotion_pintuan_group')->commit();
return $this->success($res);
} catch (\Exception $e) {
model('promotion_pintuan_group')->rollback();
return $this->error('', $e->getMessage());
}
}
/**
* 查询拼团组信息
* @param array $condition
* @param string $field
* @return array
*/
public function getPintuanGroupInfo($condition = [], $field = '*')
{
$group_info = model('promotion_pintuan_group')->getInfo($condition, $field);
return $this->success($group_info);
}
/**
* 获取拼团组详情
* @param $condition
* @return array
*/
public function getPintuanGroupDetail($condition)
{
$field = 'pg.*,m.nickname,m.headimg,og.sku_name,og.sku_image,pp.pintuan_price';
$alias = 'pg';
$join = [
[ 'promotion_pintuan_order ppo', 'ppo.group_id = pg.group_id and ppo.member_id = pg.head_id', 'inner' ],
[ 'promotion_pintuan pp', 'pp.pintuan_id = pg.pintuan_id', 'inner' ],
[ 'order_goods og', 'og.order_id = ppo.order_id', 'inner' ],
[ 'member m', 'm.member_id = pg.head_id', 'inner' ]
];
$info = model('promotion_pintuan_group')->getInfo($condition, $field, $alias, $join);
//查询参与拼单的会员
if (!empty($info)) {
$member_list = model('promotion_pintuan_order')->getList([ [ "group_id", "=", $info[ "group_id" ] ], [ 'pintuan_status', 'not in', '0,1' ] ], "pintuan_status,member_img,nickname,member_id");
$info[ "member_list" ] = $member_list;
}
return $this->success($info);
}
/**
* 获取组列表
* @param array $condition
* @param string $field
* @return array
*/
public function getPintuanGroupList($condition = [], $field = '*')
{
$list = model('promotion_pintuan_group')->getList($condition, $field);
return $this->success($list);
}
/**
* 获取拼团组商品列表
* @param array $condition
* @return array
*/
public function getPintuanGoodsGroupList($condition = [])
{
$field = 'ppg.group_id,ppg.goods_id,ppg.pintuan_id,ppg.head_id,ppg.pintuan_num,ppg.pintuan_count,ppg.create_time,ppg.end_time,ppg.status,ppg.is_single_buy,ppg.is_promotion,ppg.buy_num,m.member_id,m.nickname,m.headimg';
$alias = 'ppg';
$join = [
[
'member m',
'ppg.head_id = m.member_id',
'inner'
]
];
$list = model('promotion_pintuan_group')->getList($condition, $field, 'ppg.create_time desc', $alias, $join);
return $this->success($list);
}
/**
* 获取拼团组分页列表
* @param array $condition
* @param number $page
* @param string $page_size
* @param string $order
*/
public function getPintuanGroupPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '')
{
$field = 'pg.*,g.goods_name,g.goods_image,m.nickname,m.headimg';
$alias = 'pg';
$join = [
[
'goods g',
'pg.goods_id = g.goods_id',
'inner'
],
[
'member m',
'm.member_id = pg.head_id',
'inner'
]
];
$list = model('promotion_pintuan_group')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
return $this->success($list);
}
/**
* 关闭拼团组
* @param $group_id
* @return array|\multitype
*/
public function cronClosePintuanGroup($group_id)
{
model('promotion_pintuan_group')->startTrans();
try {
//获取拼团组信息
$pintuan_group = model('promotion_pintuan_group')->getInfo([ [ 'group_id', '=', $group_id ] ], 'status,is_virtual_buy,is_virtual_goods');
if (!empty($pintuan_group)) {
if ($pintuan_group[ 'status' ] == 2) {
//关闭所有已支付的订单
$res = $this->closePaidGroupOrder($group_id, $pintuan_group[ 'is_virtual_buy' ], $pintuan_group[ 'is_virtual_goods' ]);
if ($res[ 'code' ] < 0) {
model('promotion_pintuan_group')->rollback();
return $res;
}
}
}
model('promotion_pintuan_group')->commit();
return $this->success();
} catch (\Exception $e) {
model('promotion_pintuan_group')->rollback();
return $this->error('', $e->getMessage());
}
}
/**
* 关闭拼团组未支付订单
* @param $group_id
* @return array|\multitype
*/
public function closeUnpaidGroupOrder($group_id)
{
//获取所有改组未支付的订单
$pintuan_order_model = new PintuanOrder();
$unpaid_order = $pintuan_order_model->getPintuanOrderList([ [ 'group_id', '=', $group_id ], [ 'pintuan_status', '=', 0 ] ], 'order_id');
$unpaid_order_list = $unpaid_order[ 'data' ];
model('promotion_pintuan_order')->startTrans();
$order_model = new OrderCommon();
try {
if (!empty($unpaid_order_list)) {
foreach ($unpaid_order_list as $v) {
//修改拼团订单状态
model('promotion_pintuan_order')->update([ 'pintuan_status' => 1 ], [ [ 'order_id', '=', $v[ 'order_id' ] ] ]);
//解除锁定
$order_model->orderUnlock($v[ 'order_id' ]);
//关闭订单
$result = $order_model->orderClose($v[ 'order_id' ], [], '拼团祖关闭,订单自动关闭');
if ($result[ "code" ] < 0) {
model('promotion_pintuan_group')->rollback();
return $result;
}
//更新订单营销状态名称
model('order')->update([ 'promotion_status_name' => '拼团失败' ], [ [ 'order_id', '=', $v[ 'order_id' ] ] ]);
}
}
model('promotion_pintuan_order')->commit();
return $this->success();
} catch (\Exception $e) {
model('promotion_pintuan_order')->rollback();
return $this->error('', $e->getMessage());
}
}
/**
* 关闭拼团组已支付订单
* @param $group_id
* @param $is_virtual_buy
* @param $is_virtual_goods
* @return array|\multitype
*/
public function closePaidGroupOrder($group_id, $is_virtual_buy, $is_virtual_goods)
{
//获取所有该组的订单
$pintuan_order_model = new PintuanOrder();
$paid_order = $pintuan_order_model->getPintuanOrderList([ [ 'group_id', '=', $group_id ] ], 'order_id,pintuan_status,site_id');
$paid_order_list = $paid_order[ 'data' ];
$order_model = new OrderCommon();
$message_model = new Message();
model('promotion_pintuan_group')->startTrans();
try {
if ($is_virtual_buy == 1) {//虚拟成团
//修改拼团组状态(成功)
$res = model('promotion_pintuan_group')->update([ 'status' => 3 ], [ [ 'group_id', '=', $group_id ] ]);
//获取拼团组信息
$pintuan_id = model('promotion_pintuan_group')->getValue([ [ 'group_id', '=', $group_id ] ], 'pintuan_id');
//更新拼团 成团组数
model('promotion_pintuan')->setInc([ [ 'pintuan_id', '=', $pintuan_id ] ], 'success_group_num');
if (!empty($paid_order_list)) {
$order_id = 0;
foreach ($paid_order_list as $v) {
switch ( $v[ 'pintuan_status' ] ) {
case 0:
//将未支付的修改为失败
model('promotion_pintuan_order')->update([ 'pintuan_status' => 1 ], [ [ 'order_id', '=', $v[ 'order_id' ] ] ]);
//解除锁定
$order_model->orderUnlock($v[ 'order_id' ]);
//关闭订单
$result = $order_model->orderClose($v[ 'order_id' ], [], '拼团祖关闭,订单自动关闭');
if ($result[ "code" ] < 0) {
model('promotion_pintuan_group')->rollback();
return $result;
}
//更新订单营销状态名称
model('order')->update([ 'promotion_status_name' => '拼团失败' ], [ [ 'order_id', '=', $v[ 'order_id' ] ] ]);
// 发送消息
$param = [ 'keywords' => 'PINTUAN_FAIL', 'time' => time(), 'order_id' => $v[ 'order_id' ], 'site_id' => $v[ 'site_id' ] ];
$message_model->sendMessage($param);
break;
case 2://已支付
$order_id = $v[ 'order_id' ];
//解除锁定
$order_model->orderUnlock($v[ 'order_id' ]);
//将已支付的修改为成功
model('promotion_pintuan_order')->update([ 'pintuan_status' => 3 ], [ [ 'order_id', '=', $v[ 'order_id' ] ] ]);
//更新订单营销状态名称
model('order')->update([ 'promotion_status_name' => '拼团成功', 'is_enable_refund' => 1 ], [ [ 'order_id', '=', $v[ 'order_id' ] ] ]);
//针对虚拟订单执行收发货操作
// if ($is_virtual_goods == 1) {
// $Virtual_model = new VirtualOrder();
// $Virtual_model->orderTakeDelivery($v['order_id']);
// }
$pintuan_order_model = new PintuanOrder();
$pintuan_order_model->virtualSuccessAction($v[ 'order_id' ]);
// 发送消息
$param = [ 'keywords' => 'PINTUAN_COMPLETE', 'time' => time(), 'order_id' => $v[ 'order_id' ], 'site_id' => $v[ 'site_id' ] ];
$message_model->sendMessage($param);
break;
}
}
}
} else {//未开启虚拟成团
//修改拼团组状态为失败
$res = model('promotion_pintuan_group')->update([ 'status' => 1 ], [ [ 'group_id', '=', $group_id ] ]);
if (!empty($paid_order_list)) {
foreach ($paid_order_list as $v) {
switch ( $v[ 'pintuan_status' ] ) {
case 0:
//将未支付的修改为失败
model('promotion_pintuan_order')->update([ 'pintuan_status' => 1 ], [ [ 'order_id', '=', $v[ 'order_id' ] ] ]);
//解除锁定
$order_model->orderUnlock($v[ 'order_id' ]);
//关闭订单
$result = $order_model->orderClose($v[ 'order_id' ], [], '拼团失败,订单自动关闭');
if ($result[ "code" ] < 0) {
model('promotion_pintuan_group')->rollback();
return $result;
}
//更新订单营销状态名称
model('order')->update([ 'promotion_status_name' => '拼团失败' ], [ [ 'order_id', '=', $v[ 'order_id' ] ] ]);
// 发送消息
$param = [ 'keywords' => 'PINTUAN_FAIL', 'time' => time(), 'order_id' => $v[ 'order_id' ], 'site_id' => $v[ 'site_id' ] ];
$message_model->sendMessage($param);
break;
case 2:
//关闭拼团订单
model('promotion_pintuan_order')->update([ 'pintuan_status' => 1 ], [ [ 'order_id', '=', $v[ 'order_id' ] ] ]);
//解除锁定
$order_model->orderUnlock($v[ 'order_id' ]);
//主动退款
$order_refund_model = new OrderRefund();
$refund_result = $order_refund_model->activeRefund($v[ 'order_id' ], "拼团订单关闭", '拼团订单关闭');
if ($refund_result[ "code" ] < 0) {
model('promotion_pintuan_group')->rollback();
return $refund_result;
}
//关闭订单
// $result = $order_model->orderClose($v['order_id'], [], '拼团失败,订单自动关闭');
// if ($result["code"] < 0) {
// model('promotion_pintuan_group')->rollback();
// return $result;
// }
//更新订单营销状态名称
model('order')->update([ 'promotion_status_name' => '拼团失败' ], [ [ 'order_id', '=', $v[ 'order_id' ] ] ]);
// 发送消息
$param = [ 'keywords' => 'PINTUAN_FAIL', 'time' => time(), 'order_id' => $v[ 'order_id' ], 'site_id' => $v[ 'site_id' ] ];
$message_model->sendMessage($param);
break;
}
}
}
}
model('promotion_pintuan_group')->commit();
return $this->success($res);
} catch (\Exception $e) {
model('promotion_pintuan_group')->rollback();
return $this->error('', $e->getMessage());
}
}
}

View File

@@ -0,0 +1,310 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\pintuan\model;
use app\model\BaseModel;
use app\model\order\OrderCommon;
use app\model\order\VirtualOrder;
/**
* 拼团订单
*/
class PintuanOrder extends BaseModel
{
/**
* 开团/参团
* @param $order
* @param int $group_id
* @param $pintuan_id
* @return array|\multitype
*/
public function addPintuanOrder($order, $group_id, $pintuan_id)
{
$site_id = $order['site_id'];
$order_id = $order['order_id'];
$order_no = $order['order_no'];
$order_type = $order['order_type']['order_type_id'];
$member_id = $order['member_id'];
$member_info = $order['member_account'];
//获取拼团信息
$pintuan_info = $order['pintuan_info'];
//判断拼团活动状态
if ($pintuan_info['status'] != 1) {
return $this->error('', '该拼团活动已结束');//该拼团活动已结束
}
$order_extend = $order['extend'] ?? [];
if (!empty($order_extend)) {
$pintuan_num = $order_extend['pintuan_num'];
}
//判断是开团还是拼团
$pintuan_order_data = array(
'pintuan_id' => $pintuan_id,
'order_id' => $order_id,
'order_no' => $order_no,
'order_type' => $order_type,
'pintuan_status' => 0,
'site_id' => $site_id,
'member_id' => $member_id,
'member_img' => $member_info['headimg'],
'nickname' => $member_info['nickname'],
'pintuan_num' => $pintuan_num ?? 0//阶梯规格
);
if ($group_id) {//拼团
//拼团组信息
$pintuan_group_info = $order['pintuan_group_info'];
$result = $this->isCanJoinGroup($group_id, $member_id);
if ($result['code'] < 0) {
return $result;
}
$pintuan_order_data['group_id'] = $group_id;
$pintuan_order_data['head_id'] = $pintuan_group_info['head_id'];
} else {//开团
$pintuan_order_data['group_id'] = 0;
$pintuan_order_data['head_id'] = $member_id;
}
$res = model('promotion_pintuan_order')->add($pintuan_order_data);
return $this->success($res);
}
/**
* 判断是否可以参团
* @param $group_id
* @param $member_id
* @return array
*/
public function isCanJoinGroup($group_id, $member_id)
{
if ($group_id > 0) {
$pintuan_group_model = new PintuanGroup();
$pintuan_group = $pintuan_group_model->getPintuanGroupInfo(
[['group_id', '=', $group_id]], 'group_id,head_id,pintuan_num,pintuan_count,status'
);
$pintuan_group_info = $pintuan_group['data'];
if ($pintuan_group_info['head_id'] == $member_id) {
return $this->error('', '抱歉,您不能参与自己的团');
}
if ($pintuan_group_info['status'] != 2) {
return $this->error('', '该拼团组已失效');
}
if ($pintuan_group_info['pintuan_num'] == $pintuan_group_info['pintuan_count']) {
return $this->error('', '该拼团组已满员,请参加别的拼团或自己开团');
}
//判断是否已参团
$count = model('promotion_pintuan_order')->getCount(
[
['po.group_id', '=', $group_id],
['po.pintuan_status', 'in', '0,2'],
['po.member_id', '=', $member_id],
[' o.order_status', '<>', OrderCommon::ORDER_CLOSE],
],
'po.pintuan_id', 'po',
[
['order o', 'o.order_id = po.order_id', 'left']
]
);
if ($count > 0) {
return $this->error('', '请不要重复参团');
}
}
return $this->success();
}
/**
* @param $order
* @return array
*/
public function orderPay($order)
{
model('promotion_pintuan_order')->startTrans();
try {
//禁止拼团订单在未成团中申请退款
model('order')->update(['is_enable_refund' => 0], [['order_id', '=', $order['order_id']]]);
//支付操作查询拼团订单如果group_id=0,创建组else检测成团
//获取拼团订单信息
$pintuan_order = $this->getPintuanOrderInfo([['order_id', '=', $order['order_id']]]);
$pintuan_order_info = $pintuan_order['data'];
$order_common_model = new OrderCommon();
$local_result = $order_common_model->orderLock($order['order_id']);
if (!$local_result) return $this->error();
$pintuan_group_model = new PintuanGroup();
if ($pintuan_order_info['group_id'] == 0) {
//开团
//创建组
$group_id = $pintuan_group_model->addPintuanGroup($pintuan_order_info);
//更新拼团订单组信息
$pintuan_order_data['group_id'] = $group_id['data'];
$pintuan_order_data['pintuan_status'] = 2;
$res = model('promotion_pintuan_order')->update($pintuan_order_data, [['order_id', '=', $order['order_id']]]);
//更新订单营销状态名称
model('order')->update(['promotion_status_name' => '拼团中'], [['order_id', '=', $order['order_id']]]);
} else {//参团
//更新拼团订单信息
$pintuan_order_data['pintuan_status'] = 2;
$res = model('promotion_pintuan_order')->update($pintuan_order_data, [['order_id', '=', $order['order_id']]]);
//更新订单营销状态名称
model('order')->update(['promotion_status_name' => '拼团中'], [['order_id', '=', $order['order_id']]]);
//加入组
$pintuan_group_model->joinPintuanGroup($pintuan_order_info);
}
model('promotion_pintuan_order')->commit();
return $this->success($res);
} catch ( \Exception $e ) {
model('promotion_pintuan_order')->rollback();
return $this->error('', $e->getMessage());
}
}
/**
* 获取拼团订单信息
* @param array $condition
* @param string $field
* @return array
*/
public function getPintuanOrderInfo($condition = [], $field = '*', $alias = '', $join = '')
{
$order_info = model('promotion_pintuan_order')->getInfo($condition, $field, $alias, $join);
return $this->success($order_info);
}
/**
* 获取订单信息
* @param array $condition
* @param string $field
* @param string $order
* @param null $limit
* @return array
*/
public function getPintuanOrderList($condition = [], $field = '*', $order = '', $limit = null, $group_by = '')
{
$list = model('promotion_pintuan_order')->getList($condition, $field, $order, '', '', $group_by, $limit);
return $this->success($list);
}
/**
* 获取订单分页列表
* @param array $condition
* @param int $page
* @param int $page_size
* @param string $order
* @return array
*/
public function getPintuanOrderPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '')
{
$field = 'ppo.*,ppgs.id as pintuan_goods_id,
ppg.pintuan_num,ppg.pintuan_count,ppg.is_promotion,ppg.end_time as group_end_time,
o.site_name,o.pay_time,o.pay_money,o.order_status_name,o.name,o.order_money,o.mobile,o.address,o.full_address,o.order_from_name,o.pay_type_name,
og.sku_name,og.sku_image';
$alias = 'ppo';
$join = [
['order o', 'o.order_id = ppo.order_id', 'left'],
['order_goods og', 'og.order_id = ppo.order_id', 'left'],
['promotion_pintuan_group ppg', 'ppo.group_id = ppg.group_id', 'left'],
['promotion_pintuan_goods ppgs', 'og.sku_id = ppgs.sku_id and ppgs.pintuan_id=ppo.pintuan_id', 'inner']
];
$list = model('promotion_pintuan_order')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
return $this->success($list);
}
/**
* 拼团订单详情
* @param $order_id
* @param $member_id
*/
public function getPintuanOrderDetail($id, $member_id, $site_id)
{
$field = 'ppo.*,ppgs.id as pintuan_goods_id,
ppg.pintuan_num,ppg.pintuan_count,ppg.is_promotion,ppg.end_time as group_end_time,ppgs.pintuan_price,
pp.group_num,pp.order_num,pp.status,
gs.discount_price,
o.site_name,o.pay_time,o.pay_money,o.order_status_name,o.name,o.mobile,o.address,o.full_address,o.order_from_name,o.pay_type_name,o.order_type,o.order_money,
og.sku_name,og.sku_image';
$alias = 'ppo';
$join = [
['order o', 'o.order_id = ppo.order_id', 'left'],
['order_goods og', 'og.order_id = ppo.order_id', 'left'],
['promotion_pintuan_group ppg', 'ppo.group_id = ppg.group_id', 'left'],
['promotion_pintuan pp', 'pp.pintuan_id = ppo.pintuan_id', 'left'],
['goods_sku gs', 'gs.sku_id = og.sku_id', 'left'],
['promotion_pintuan_goods ppgs', 'og.sku_id = ppgs.sku_id and ppgs.pintuan_id=ppo.pintuan_id', 'left']
];
$condition = array(
["ppo.id", "=", $id],
["ppo.member_id", "=", $member_id],
["ppo.site_id", "=", $site_id],
);
$info = model('promotion_pintuan_order')->getInfo($condition, $field, $alias, $join);
//查询参与拼单的会员
if (!empty($info)) {
$member_list = model('promotion_pintuan_order')->getList([["group_id", "=", $info["group_id"]], ['pintuan_status', 'in', '2,3']], "member_img,nickname,member_id");
$info["member_list"] = $member_list;
}
return $this->success($info);
}
/**
* 获取拼团订单数量
* @param array $condition
* @param string $field
* @return array
*/
public function getPintuanOrderCount($condition = [], $field = '*', $alias = '', $join = '', $group = '')
{
$order_info = model('promotion_pintuan_order')->getCount($condition, $field, $alias, $join, $group);
return $this->success($order_info);
}
/**
* 拼团成功
* @param $params
*/
public function pintuanOrderSuccess($params)
{
}
/**
* 拼团订单关闭
* @param $condition
* @return array
*/
public function pintuanOrderClose($condition)
{
//将未支付的修改为失败
model('promotion_pintuan_order')->update(['pintuan_status' => 1], $condition);
return $this->success();
}
/**
* 虚拟商品成功后操作
* @param $order_id
*/
public function virtualSuccessAction($order_id)
{
$order_info = model('order')->getInfo([['order_id', '=', $order_id]]);
$order_type = $order_info['order_type'];
if ($order_type == 4) {//虚拟订单
$virtual_order_model = new VirtualOrder();
$virtual_order_model->toSend(['order_id' => $order_id]);
}
}
}

View File

@@ -0,0 +1,309 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\pintuan\model;
use app\model\BaseModel;
use app\model\order\OrderCreate;
use app\model\order\OrderCreateTool;
use extend\exception\OrderException;
use app\model\system\Pay;
/**
* 订单创建(拼团)
*/
class PintuanOrderCreate extends BaseModel
{
use OrderCreateTool;
public $group_id = 0;
public $pintuan_info = [];
public $pintuan_id = 0;
public $pintuan_group_info = [];
public $extend = [];
public function __construct()
{
$this->promotion_type = 'pintuan';
$this->promotion_type_name = '拼团';
}
/**
* 订单创建
*/
public function create()
{
//计算
$this->confirm();
if ($this->error > 0) {
return $this->error([ 'error_code' => $this->error ], $this->error_msg);
}
//订单创建数据
$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);
$order_insert_data[ 'promotion_status_name' ] = '待参团';
$order_insert_data[ 'extend' ] = empty($this->param[ 'extend' ]) ? '' : json_encode($this->param[ 'extend' ]);
model('order')->startTrans();
//循环生成多个订单
try {
$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);
//同步生成拼团
$pintuan_order_model = new PintuanOrder();
$result = $pintuan_order_model->addPintuanOrder($this->getOrderObjectData(), $this->group_id, $this->pintuan_id);
if ($result[ 'code' ] != 0) {
model('order')->rollback();
return $result;
}
//扣除余额(统一扣除)
$this->useBalance();
//批量库存处理(卡密商品支付后在扣出库存)
$this->batchDecOrderGoodsStock();
model('order')->commit();
//订单创建后事件
$this->orderCreateAfter();
//支付单据
$pay = new Pay();
$pay->addPay($this->site_id, $this->out_trade_no, $this->pay_type, $this->order_name, $this->order_name, $this->pay_money, '', 'OrderPayNotify', '/pages_promotion/pintuan/share?id=' . $result[ 'data' ], $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 calculate()
{
//要提前赋值,商品计算要用到
$this->group_id = $this->param[ 'group_id' ];
//初始化会员地址
$this->initMemberAddress();
//初始化会员账户
$this->initMemberAccount();
//商品列表信息
$this->getOrderGoodsCalculate();
//查询拼团信息
$pintuan_model = new Pintuan();
$this->pintuan_info = $pintuan_model->getPintuanInfo([ [ 'pintuan_id', '=', $this->pintuan_id ], [ 'site_id', '=', $this->site_id ] ])[ 'data' ] ?? [];
if (empty($this->pintuan_info)) throw new OrderException('找不到有效的拼团活动!');
//判断购买数是否超过限购
if ($this->pintuan_info[ 'buy_num' ] < $this->param[ 'num' ] && $this->pintuan_info[ 'buy_num' ] > 0) {
$this->error = 1;
$this->error_msg = '该商品限制购买不能大于' . $this->pintuan_info[ 'buy_num' ] . '件!';
}
//判断是否可参团
$pintuan_order = new PintuanOrder();
$result = $pintuan_order->isCanJoinGroup($this->group_id, $this->member_id);
if ($result[ 'code' ] < 0) throw new OrderException($result[ 'message' ]);
//查询拼团组信息
$pintuan_model = new PintuanGroup();
$this->pintuan_group_info = $pintuan_model->getPintuanGroupInfo([ [ 'group_id', '=', $this->group_id ], [ 'site_id', '=', $this->site_id ] ])[ 'data' ] ?? [];
$this->shopOrderCalculate();
//获取发票相关
$this->getInovice();
$this->order_key = create_no();
$this->setOrderCache(get_object_vars($this), $this->order_key);
return true;
}
/**
* 待付款订单
*/
public function orderPayment()
{
//计算
$this->calculate();
//查询配送信息
$this->getDeliveryData();
//订单初始项
event('OrderPayment', [ 'order_object' => $this ]);
return get_object_vars($this);
}
/**
* 获取商品的计算信息
*/
public function getOrderGoodsCalculate()
{
$this->getPintuanGoodsInfo();
return true;
}
/**
* 获取拼团商品列表信息
*/
public function getPintuanGoodsInfo()
{
$id = $this->param[ 'id' ];
$num = $this->param[ 'num' ];
//组装商品列表
$field = 'nppg.id,nppg.sku_id,nppg.pintuan_id,nppg.pintuan_price,nppg.promotion_price,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, ns.site_name, ngs.goods_state, ngs.is_virtual, ngs.support_trade_type,ngs.supplier_id,ngs.form_id,
ngs.is_free_shipping, ngs.shipping_template, ngs.goods_class, ngs.goods_class_name,ngs.goods_id,ngs.sku_spec_format,ngs.goods_name,g.goods_image,
nppg.pintuan_price_2,nppg.pintuan_price_3';
$alias = 'nppg';
$join = [
[
'goods_sku ngs',
'nppg.sku_id = ngs.sku_id',
'inner'
],
[
'site ns',
'ngs.site_id = ns.site_id',
'inner'
],
[ 'goods g', 'ngs.goods_id = g.goods_id', 'inner' ],
];
$info = model('promotion_pintuan_goods')->getInfo([ [ 'nppg.id', '=', $id ], [ 'nppg.site_id', '=', $this->site_id ] ], $field, $alias, $join);
if (!$info) throw new OrderException('商品不存在!');
$pintuan_model = new Pintuan();
$this->pintuan_id = $info[ 'pintuan_id' ];
$pintuan_info = $pintuan_model->getPintuanInfo([ [ 'pintuan_id', '=', $this->pintuan_id ], [ 'site_id', '=', $this->site_id ] ])[ 'data' ] ?? [];
//判断是否是虚拟订单
if ($info[ 'is_virtual' ]) {
$this->is_virtual = 1;
} else {
$this->is_virtual = 0;
}
$info[ 'num' ] = $num;
$pintuan_type = $pintuan_info[ 'pintuan_type' ];
switch ($pintuan_type) {
case 'ordinary'://默认拼团方式
//判断是否是开团 团长
if ($this->group_id > 0) {
$price = $info[ 'pintuan_price' ];//参团价
} else {
$price = $info[ 'promotion_price' ];//开团价
}
break;
case 'ladder'://阶梯拼团
$pintuan_num = $pintuan_info[ 'pintuan_num' ];
$pintuan_num_2 = $pintuan_info[ 'pintuan_num_2' ];
$pintuan_num_3 = $pintuan_info[ 'pintuan_num_3' ];
$this->extend = $this->param[ 'extend' ] ?? [];
$price = $info[ 'pintuan_price' ];//一级参团价
if (empty($this->extend)) {
$group_model = new PintuanGroup();
$pintuan_group_condition = array (
[ 'site_id', '=', $this->site_id ],
[ 'group_id', '=', $this->group_id ]
);
$group_info = $group_model->getPintuanGroupInfo($pintuan_group_condition)[ 'data' ] ?? [];
if (empty($group_info)) {
break;
}
$pintuan_ladder = $group_info[ 'pintuan_num' ];
} else {
$pintuan_ladder = $this->extend[ 'pintuan_num' ];
}
switch ($pintuan_ladder) {
case $pintuan_num:
$price = $info[ 'pintuan_price' ];//一级参团价
break;
case $pintuan_num_2:
$price = $info[ 'pintuan_price_2' ];//二级参团价
break;
case $pintuan_num_3:
$price = $info[ 'pintuan_price_3' ];//三级参团价
break;
}
break;
}
$goods_money = $price * $info[ 'num' ];
$info[ 'price' ] = $price;
$info[ 'goods_money' ] = $goods_money;
$info[ 'real_goods_money' ] = $goods_money;//真实商品金额
$info[ 'coupon_money' ] = 0;//优惠券金额
$info[ 'promotion_money' ] = 0;//优惠金额
$this->site_name = $info[ 'site_name' ];
$this->goods_money = $goods_money;
$this->goods_list_str = $info[ 'sku_id' ] . ':' . $info[ 'num' ];
$this->order_name = string_split('', ',', $info[ 'sku_name' ]);
$this->goods_num = $info[ 'num' ];
$this->goods_list[] = $info;
return true;
}
/**
* 获取店铺订单计算
*/
public function shopOrderCalculate()
{
//重新计算订单总额
$this->getOrderMoney();
//理论上是多余的操作
if ($this->order_money < 0) {
$this->order_money = 0;
}
//总结计算
$this->pay_money = $this->order_money;
return true;
}
}

655
addon/pintuan/model/Poster.php Executable file
View File

@@ -0,0 +1,655 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\pintuan\model;
use addon\postertemplate\model\PosterTemplate;
use app\model\BaseModel;
use app\model\system\Site;
use app\model\upload\Upload;
use app\model\web\Config;
use extend\Poster as PosterExtend;
/**
* 海报生成类
*/
class Poster extends BaseModel
{
/**
* 商品海报
*/
public function goods($app_type, $page, $qrcode_param, $promotion_type, $site_id)
{
try {
$pintuan_id = $qrcode_param[ 'id' ];
$goods_info = $this->getGoodsInfo($pintuan_id);
if (empty($goods_info)) return $this->error('未获取到商品信息');
$qrcode_info = $this->getGoodsQrcode($app_type, $page, $qrcode_param, $promotion_type, $site_id);
if ($qrcode_info[ 'code' ] < 0) return $qrcode_info;
//判断海报是否存在或停用
$template_info = $this->getTemplateInfo($goods_info[ 'template_id' ]);
$site_model = new Site();
$condition = array (
[ "site_id", "=", $site_id ]
);
$site_info = $site_model->getSiteInfo($condition);
$member_info = [];
if (!empty($qrcode_param[ 'source_member' ])) {
$member_info = $this->getMemberInfo($qrcode_param[ 'source_member' ]);
}
$upload_config_model = new Config();
$upload_config_result = $upload_config_model->getDefaultImg($site_id);
$goods_pintuan_price = $goods_info[ 'pintuan_price' ];
$goods_img = $goods_info[ 'sku_image' ];
$goods_name = $goods_info[ 'sku_name' ];
$group_id = $qrcode_param[ 'group_id' ] ?? 0;
$group_info = model('promotion_pintuan_group')->getInfo([ [ 'group_id', '=', $group_id ] ]);
if (!empty($group_info)) {
$pintuan_num = $group_info[ 'pintuan_num' ];
// if($pintuan_num > 0){
// $pintuan_num_name = $pintuan_num.'人团';
$pintuan_order_info = model('promotion_pintuan_order')->getInfo([ [ 'group_id', '=', $group_id ] ]);
if (!empty($pintuan_order_info)) {
$order_goods_info = model('order_goods')->getInfo([ [ 'order_id', '=', $pintuan_order_info[ 'order_id' ] ] ]);
if (!empty($order_goods_info)) {
$sku_id = $order_goods_info[ 'sku_id' ];
$pintuan_id = $qrcode_param[ 'id' ] ?? 0;
$pintuan_info = model('promotion_pintuan')->getInfo([ [ 'pintuan_id', '=', $pintuan_id ] ]);
if (!empty($pintuan_info)) {
$pintuan_type = $pintuan_info[ 'pintuan_type' ];
$pintuan_goods_info = model('promotion_pintuan_goods')->getInfo([ [ 'pintuan_id', '=', $pintuan_id ], [ 'sku_id', '=', $sku_id ] ]);
if ($pintuan_type == 'ladder') {
$sku_info = model('goods_sku')->getInfo([ [ 'sku_id', '=', $sku_id ] ], 'sku_image,sku_name');
if (!empty($sku_info)) {
$goods_img = $sku_info[ 'sku_image' ];
$goods_name = $sku_info[ 'sku_name' ];
}
if (!empty($pintuan_goods_info)) {
switch ( $pintuan_num ) {
case $pintuan_info[ 'pintuan_num' ]:
$goods_pintuan_price = $pintuan_goods_info[ 'pintuan_price' ];//一级参团价
break;
case $pintuan_info[ 'pintuan_num_2' ]:
$goods_pintuan_price = $pintuan_goods_info[ 'pintuan_price_2' ];//二级参团价
break;
case $pintuan_info[ 'pintuan_num_3' ]:
$goods_pintuan_price = $pintuan_goods_info[ 'pintuan_price_3' ];//三级参团价
break;
default:
break;
}
}
} else {
// $goods_pintuan_price = $pintuan_goods_info[ 'pintuan_price' ];
}
}
}
}
// }
}
if (empty($goods_info[ 'template_id' ]) || empty($template_info) || $template_info[ 'template_status' ] == 0) {
$poster_width = 720;
$poster_height = 1280;
$poster = new PosterExtend($poster_width, $poster_height);
$option = [
[
'action' => 'imageCopy', // 背景图
'data' => [
img('upload/poster/bg/promotion_pintuan.png'),
0,
0,
720,
1280,
'square',
0,
1
]
],
[
'action' => 'imageCopy', // 商品图
'data' => [
$goods_info['sku_image'],
86,
174,
548,
548,
'square',
5,
1
]
],
[
'action' => 'imageCopy', // 二维码
'data' => [
$qrcode_info['data']['path'],
273,
916,
175,
175,
'square',
0,
1
]
],
[
'action' => 'imageText', // 写入商品价格
'data' => [
'原价 ¥ '. $goods_info['price'] .' 参团价 ¥ ' . $goods_pintuan_price,
18,
[51, 51, 51],
86,
828,
548,
1,
false,
1
]
],
[
'action' => 'imageText', // 写入商品名称
'data' => [
$goods_info['sku_name'],
25,
[34, 34, 34],
86,
780,
548,
1,
true,
1
]
]
];
if (!empty($member_info)) {
$member_option = [
[
'action' => 'imageCircularCopy', // 写入用户头像
'data' => [
!empty($member_info['headimg']) ? $member_info['headimg'] : $upload_config_result[ 'data' ][ 'value' ][ 'head' ],
86,
40,
101,
101
]
],
[
'action' => 'imageText', // 写入分享人昵称
'data' => [
$member_info['nickname'],
24,
[51, 51, 51],
210,
85,
420,
1,
0,
1
]
]
];
$option = array_merge($option, $member_option);
}
} else {
$condition = [
[ 'template_id', '=', $goods_info[ 'template_id' ] ],
[ 'site_id', '=', $site_id ]
];
$poster_template_model = new PosterTemplate();
$poster_data = $poster_template_model->getPosterTemplateInfo($condition);
$poster_data[ 'data' ][ 'template_json' ] = json_decode($poster_data[ 'data' ][ 'template_json' ], true);
$poster_width = 720;
$poster_height = 1280;
$poster = new PosterExtend($poster_width, $poster_height);
$fontRate = 0.725; // 20px 等于 14.5磅,换算比率 1px = 0.725磅
if (!empty($poster_data[ 'data' ][ 'background' ])) {
list($width, $height, $type, $attr) = getimagesize(img($poster_data[ 'data' ][ 'background' ]));
$back_ground = [
'action' => 'imageCopy', // 写入背景图
'data' => [
img($poster_data[ 'data' ][ 'background' ]),
0,
0,
$poster_width,
$poster_height,
'square',
0,
1
]
];
} else {
$back_ground = [
'action' => 'setBackground', // 设背景色
'data' => [ 255, 255, 255 ]
];
}
$option = [
$back_ground,
[
'action' => 'imageText', // 写入店铺名称
'data' => [
$site_info[ 'data' ][ 'site_name' ],
$poster_data[ 'data' ][ 'template_json' ][ 'store_name_font_size' ] * $fontRate * 2,
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'store_name_color' ]),
$poster_data[ 'data' ][ 'template_json' ][ 'store_name_left' ] * 2,
( $poster_data[ 'data' ][ 'template_json' ][ 'store_name_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'store_name_font_size' ] ) * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'store_name_width' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'store_name_height' ] * 2,
true,
$poster_data[ 'data' ][ 'template_json' ][ 'store_name_is_show' ]
]
],
[
'action' => 'imageCopy', // 店铺logo
'data' => [
!empty($site_info[ 'data' ][ 'logo_square' ]) ? $site_info[ 'data' ][ 'logo_square' ] : getUrl() . '/app/shop/view/public/img/shop_logo.png',
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_left' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_top' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_width' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_height' ] * 2,
'square',
1,
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_is_show' ]
]
],
[
'action' => 'imageCopy', // 写入商品图
'data' => [
img($goods_img, 'mid'),
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_left' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_top' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_width' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_height' ] * 2,
!empty($poster_data[ 'data' ][ 'template_json' ][ 'goods_img_shape' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_shape' ] : 'square',
0,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_is_show' ]
]
],
[
'action' => 'imageText', // 写入商品名称
'data' => [
$goods_name,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_name_font_size' ] * $fontRate * 2,
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_name_color' ]),
$poster_data[ 'data' ][ 'template_json' ][ 'goods_name_left' ] * 2,
( $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_font_size' ] ) * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_name_width' ] * 2,
1,//文本行数 $poster_data['data']['template_json']['goods_name_height']*2,
true,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_name_is_show' ]
]
],
[
'action' => 'imageCopy', // 写入商品二维码
'data' => [
$qrcode_info[ 'data' ][ 'path' ],
$poster_data[ 'data' ][ 'qrcode_left' ] * 2,
$poster_data[ 'data' ][ 'qrcode_top' ] * 2,
$poster_data[ 'data' ][ 'qrcode_width' ] * 2,
$poster_data[ 'data' ][ 'qrcode_height' ] * 2,
'square',
0,
1
]
],
[
'action' => 'imageText', // 写入商品价格
'data' => [
'¥' . $goods_pintuan_price,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_font_size' ] * $fontRate * 2,
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_price_color' ]),
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_left' ] * 2,
( $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_font_size' ] ) * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_width' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_height' ] * 2,
true,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_is_show' ]
]
],
];
if ($goods_info['price'] ==0 ){
$line = '一一一';
}else{
$line = '一一一一';
}
$market_price = [
[
'action' => 'imageText', // 写入商品划线价格
'data' => [
'¥' . $goods_info[ 'price' ],
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] * $fontRate * 2,
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_color' ]),
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_left' ] * 2,
( $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] ) * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_width' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_height' ] * 2,
true,
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_is_show' ] ?? 0
]
],
[
'action' => 'imageText', // 写入线
'data' => [
$line,
$poster_data['data']['template_json']['goods_market_price_font_size']*$fontRate*2,
hex2rgb($poster_data['data']['template_json']['goods_market_price_color']),
$poster_data['data']['template_json']['goods_market_price_left']*2-5,
($poster_data['data']['template_json']['goods_market_price_top']+$poster_data['data']['template_json']['goods_market_price_font_size'])*2,
$poster_data['data']['template_json']['goods_market_price_width']*2,
$poster_data['data']['template_json']['goods_market_price_height']*2,
true,
$poster_data['data']['template_json']['goods_market_price_is_show']
]
],
];
$option = array_merge($option, $market_price);
if (!empty($member_info)) {
$member_option = [
[
'action' => 'imageCopy', // 写入用户头像
'data' => [
!empty($member_info[ 'headimg' ]) ? $member_info[ 'headimg' ] : $upload_config_result[ 'data' ][ 'value' ][ 'head' ],
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_left' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_top' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_width' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_height' ] * 2,
!empty($poster_data[ 'data' ][ 'template_json' ][ 'headimg_shape' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'headimg_shape' ] : 'square',
0,
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_is_show' ]
]
],
[
'action' => 'imageText', // 写入分享人昵称
'data' => [
$member_info[ 'nickname' ],
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_font_size' ] * $fontRate * 2,
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'nickname_color' ]),
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_left' ] * 2,
( $poster_data[ 'data' ][ 'template_json' ][ 'nickname_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'nickname_font_size' ] ) * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_width' ] * 2,
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_height' ] * 2,
0,
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_is_show' ]
]
],
];
$ground = [
[
'action' => 'setBackground',
'data' => [ 255, 255, 255 ]
]
];
$option = array_merge($ground, $option, $member_option);
}
}
$option_res = $poster->create($option);
if (is_array($option_res)) return $option_res;
$res = $option_res->jpeg('upload/poster/goods', 'goods_' . $promotion_type . '_' . $goods_info[ 'pintuan_id' ] . '_' . $qrcode_param[ 'source_member' ] . '_' . time() . '_' . $app_type);
if ($res[ 'code' ] == 0) {
$upload = new Upload($site_id);
$cloud_res = $upload->fileCloud($res[ 'data' ][ 'path' ]);
if ($cloud_res[ 'code' ] >= 0) {
return $this->success([ "path" => $cloud_res[ 'data' ] ]);
} else {
return $this->error();
}
}
return $res;
} catch (\Exception $e) {
return $this->error($e->getMessage() . $e->getFile() . $e->getLine());
}
}
/**
* 获取用户信息
* @param unknown $member_id
*/
private function getMemberInfo($member_id)
{
$info = model('member')->getInfo([ 'member_id' => $member_id ], 'nickname,headimg');
return $info;
}
/**
* 获取商品信息
* @param unknown
*/
private function getGoodsInfo($id, $group_id = 0)
{
$alias = 'nppg';
$join = [
[ 'goods_sku ngs', 'nppg.sku_id = ngs.sku_id', 'inner' ],
[ 'promotion_pintuan pp', 'pp.pintuan_id = nppg.pintuan_id', 'left' ]
];
$field = 'ngs.sku_name,ngs.introduction,ngs.sku_image,ngs.sku_id,nppg.pintuan_price,nppg.pintuan_id,ngs.template_id,ngs.price,nppg.pintuan_price_2,nppg.pintuan_price_3,pp.pintuan_num,pp.pintuan_num_2,pp.pintuan_num_3';
$info = model('promotion_pintuan_goods')->getInfo([ 'nppg.pintuan_id' => $id ], $field, $alias, $join);
// 按参团人数获取拼团价
if (!empty($group_id)) {
$group_info = model('promotion_pintuan_group')->getInfo([ [ 'group_id', '=', $group_id ] ], 'pintuan_num');
if (!empty($group_info)) {
if ($info[ 'pintuan_num_2' ] == $group_info[ 'pintuan_num' ]) $info[ 'pintuan_price' ] = $info[ 'pintuan_price_2' ];
else if ($info[ 'pintuan_num_3' ] == $group_info[ 'pintuan_num' ]) $info[ 'pintuan_price' ] = $info[ 'pintuan_price_3' ];
$info[ 'pintuan_num' ] = $group_info[ 'pintuan_num' ];
}
}
return $info;
}
/**
* 获取商品二维码
* @param unknown $app_type 请求类型
* @param unknown $page uniapp页面路径
* @param unknown $qrcode_param 二维码携带参数
* @param string $promotion_type 活动类型 null为无活动
*/
private function getGoodsQrcode($app_type, $page, $qrcode_param, $promotion_type, $site_id)
{
$res = event('Qrcode', [
'site_id' => $site_id,
'app_type' => $app_type,
'type' => 'create',
'data' => $qrcode_param,
'page' => $page,
'qrcode_path' => 'upload/qrcode/goods',
'qrcode_name' => 'goods_' . $promotion_type . '_' . $qrcode_param[ 'id' ] . '_' . $qrcode_param[ 'source_member' ] . '_' . $site_id,
], true);
return $res;
}
/**
* 获取海报信息
* @param unknown $template_id
*/
private function getTemplateInfo($template_id)
{
$info = model('poster_template')->getInfo([ 'template_id' => $template_id ], 'template_id,template_status');
return $info;
}
/**
* 分享图片
* @param $page
* @param $qrcode_param
* @param $site_id
* @return array
*/
public function shareImg($page, $qrcode_param, $site_id)
{
try {
$goods_info = $this->getGoodsInfo($qrcode_param[ 'id' ], $qrcode_param[ 'group_id' ] ?? 0);
if (empty($goods_info)) return $this->error('未获取到商品信息');
$file_path = 'upload/share_img/pintuan_' . $goods_info[ 'pintuan_id' ] . '/sku_' . $goods_info[ 'sku_id' ] . '_' . $goods_info[ 'pintuan_num' ] . '.jpg';
if (file_exists($file_path)) return $this->success([ 'path' => $file_path ]);
$poster_width = 600;
$poster_height = 480;
$poster = new PosterExtend($poster_width, $poster_height);
$option = [
[
'action' => 'setBackground', // 设背景色
'data' => [ 255, 255, 255 ]
],
[
'action' => 'imageCopy', // 商品图
'data' => [
img($goods_info[ 'sku_image' ], 'mid'),
30,
145,
200,
200,
'square',
50,
1
]
],
[
'action' => 'imageText', // 写入商品名称
'data' => [
$goods_info[ 'sku_name' ],
22,
[ 51, 51, 51 ],
250,
190,
330,
2,
false,
1
]
],
[
'action' => 'imageText', // 写入商品价格
'data' => [
'拼团价:¥',
15,
[ 255, 0, 0 ],
250,
300,
300,
2,
false,
1
]
],
[
'action' => 'imageText', // 写入商品价格
'data' => [
$goods_info[ 'pintuan_price' ],
30,
[ 255, 0, 0 ],
345,
300,
300,
2,
false,
1,
PUBLIC_PATH . 'static/font/custom.ttf'
]
],
[
'action' => 'imageText', // 写入商品原价
'data' => [
'原 价:¥',
15,
[ 153, 153, 153 ],
250,
340,
300,
2,
false,
1
]
],
[
'action' => 'imageText', // 写入商品原价
'data' => [
$goods_info[ 'price' ],
16,
[ 153, 153, 153 ],
345,
338,
300,
2,
false,
1,
PUBLIC_PATH . 'static/font/custom.ttf',
]
],
// 划线(两条线)
[
'action' => 'imageline',
'data' => [
325,
330,
325 + imagettfbbox(16, 0, PUBLIC_PATH . 'static/font/custom.ttf', '¥ ' . $goods_info[ 'price' ])[ 2 ],
330,
[ 153, 153, 153 ],
]
],
[
'action' => 'imageline',
'data' => [
325,
331,
325 + imagettfbbox(16, 0, PUBLIC_PATH . 'static/font/custom.ttf', '¥ ' . $goods_info[ 'price' ])[ 2 ],
331,
[ 153, 153, 153 ],
]
],
[
'action' => 'imageCopy', // 背景图
'data' => [
img('upload/share_img/bg/pintuan_1.png'),
0,
0,
600,
480,
'square',
0,
1
]
],
];
$option_res = $poster->create($option);
if (is_array($option_res)) {
return $option_res;
}
$res = $option_res->jpeg('upload/share_img/pintuan_' . $goods_info[ 'pintuan_id' ],
'sku_' . $goods_info[ 'sku_id' ] . '_' . $goods_info[ 'pintuan_num' ]);
return $res;
} catch (\Exception $e) {
return $this->error($e->getMessage());
}
}
/**
* 删除分享图片
* @param int $pintuan_id
*/
public function clearShareImg(int $pintuan_id)
{
$dir = 'upload/share_img/pintuan_' . $pintuan_id;
@deleteDir($dir);
}
}

View File

@@ -0,0 +1,134 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\pintuan\model\share;
use addon\pintuan\model\Pintuan;
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_PINTUAN_PROMOTE',
'path' => [ '/pages_promotion/pintuan/detail' ],
'method_prefix' => 'goodsDetail',
],
[
'title' => '拼团列表',
'config_key' => 'WCHAT_SHARE_CONFIG_PINTUAN_LIST_PROMOTE',
'path' => [ '/pages_promotion/pintuan/list' ],
'method_prefix' => 'goodsList',
],
];
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' => "拼实惠\n团惊喜",
'imgUrl' => ''
];
}
if (empty($data[ 'value' ][ 'imgUrl' ])) {
$data[ 'value' ][ 'imgUrl' ] = img('addon/pintuan/icon.png');
}
return [
'value' => $data[ 'value' ],
];
}
/**
* 拼团分享数据
* @param $param
* @return array
*/
protected function goodsDetailShareData($param)
{
$url = $param[ 'url' ];
$parse_res = parse_url($url);
parse_str($parse_res[ 'query' ] ?? '', $query);
if (isset($query[ 'pintuan_id' ]) || isset($query[ 'id' ])) {
$pintuan_id = $query['pintuan_id'] ?? $query['id'];
$goods = new Pintuan();
$sku_info = $goods->getPintuanGoodsDetail([ [ 'ppg.pintuan_id', '=', $pintuan_id ] ])[ 'data' ];
if (!empty($sku_info)) {
$config_model = new \app\model\share\WchatShare();
$config_data = $config_model->goodsDetailShareConfig($param);
$title = str_replace('{goods_name}', $sku_info[ 'sku_name' ], $config_data[ 'value' ][ 'title' ]);
$desc = str_replace('{price}', $sku_info[ 'pintuan_price' ], $config_data[ 'value' ][ 'desc' ]);
$link = $this->getShareLink($param);
$image_url = $sku_info[ 'sku_image' ];
$data = [
'title' => $title,
'desc' => $desc,
'link' => $link,
'imgUrl' => $image_url,
];
return [
'permission' => [
'hideOptionMenu' => false,
'hideMenuItems' => [],
],
'data' => $data,//分享内容
];
}
}
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\pintuan\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_PINTUAN_LIST',
'path' => [ '/pages_promotion/pintuan/list' ],
'method_prefix' => 'pintuanList',
],
];
protected $sort = 7;
/**
* 拼团列表
* @param $param
* @return array
*/
protected function pintuanListShareData($param)
{
//获取和替换配置数据
$config_data = $this->pintuanListShareConfig($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 pintuanListShareConfig($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,
];
}
}