初始上传

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

152
addon/jielong/model/Cart.php Executable file
View File

@@ -0,0 +1,152 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\jielong\model;
use app\model\BaseModel;
/**
* 购物车
*/
class Cart extends BaseModel
{
/**
* 添加购物车
* @param $data
* @return array
*/
public function addCart($data)
{
$cart_info = model('promotion_jielong_cart')->getInfo([ [ 'sku_id', '=', $data[ 'sku_id' ] ], [ 'member_id', '=', $data[ 'member_id' ] ], [ 'jielong_id', '=', $data[ 'jielong_id' ] ] ], 'cart_id, num');
if (!empty($cart_info)) {
$res = model('promotion_jielong_cart')->update([ 'num' => $cart_info[ 'num' ] + $data[ 'num' ] ], [ [ 'cart_id', '=', $cart_info[ 'cart_id' ] ] ]);
} else {
$res = model('promotion_jielong_cart')->add($data);
}
return $this->success($res);
}
/**
* 获取购物车商品信息
* @param unknown $data
*/
public function getCartSkuInfo($condition, $fields, $alias, $join)
{
$res_info = model('promotion_jielong_cart')->getInfo($condition, $fields, $alias, $join);
return $this->success($res_info);
}
/**
* 更新购物车商品数量
* @param unknown $data
*/
public function editCart($data)
{
$res = model('promotion_jielong_cart')->update([ 'num' => $data[ 'num' ] ], [ [ 'cart_id', '=', $data[ 'cart_id' ] ], [ 'member_id', '=', $data[ 'member_id' ] ] ]);
return $this->success($res);
}
/**
* 删除购物车商品项(可以多项)
* @param $data
* @return array
*/
public function deleteCart($data)
{
$res = model('promotion_jielong_cart')->delete([ [ 'cart_id', 'in', explode(',', $data[ 'cart_id' ]) ], [ 'member_id', '=', $data[ 'member_id' ] ] ]);
return $this->success($res);
}
/**
* 清空购物车
* @param unknown $data
*/
public function clearCart($data)
{
$res = model('promotion_jielong_cart')->delete([ [ 'member_id', '=', $data[ 'member_id' ] ], [ 'jielong_id', '=', $data[ 'jielong_id' ] ] ]);
return $this->success($res);
}
/**
* 获取会员购物车
* @param unknown $member_id
* @param unknown $site_id
*/
public function getCart($member_id, $site_id, $jielong_id)
{
$field = 'pjc.cart_id, pjc.site_id, pjc.member_id, pjc.sku_id, pjc.num,pjc.jielong_id, ngs.sku_name,
ngs.sku_no, ngs.sku_spec_format,ngs.price,ngs.market_price,
ngs.discount_price, ngs.promotion_type, ngs.start_time, ngs.end_time, ngs.stock,
ngs.sku_image, ngs.sku_images, ngs.goods_state, ngs.goods_stock_alarm, ngs.is_virtual, ngs.goods_name,
ngs.virtual_indate, ngs.is_free_shipping, ngs.shipping_template, ngs.unit, ngs.introduction,ngs.sku_spec_format, ngs.keywords, ngs.max_buy, ngs.min_buy, ngs.max_buy, ns.site_name, ngs.is_limit, ngs.limit_type';
$alias = 'pjc';
$join = [
[
'goods_sku ngs',
'pjc.sku_id = ngs.sku_id',
'inner'
],
[
'site ns',
'pjc.site_id = ns.site_id',
'inner'
],
];
$list = model('promotion_jielong_cart')->getList([ [ 'pjc.member_id', '=', $member_id ], [ 'pjc.site_id', '=', $site_id ], [ 'ngs.is_delete', '=', 0 ], [ 'pjc.jielong_id', '=', $jielong_id ] ], $field, 'pjc.cart_id desc', $alias, $join);
return $this->success($list);
}
/**
* 获取购物车数量
* @param unknown $member_id
*/
public function getCartCount($member_id, $jielong_id)
{
$list = model('promotion_jielong_cart')->getCount([ [ 'member_id', '=', $member_id ], [ 'jielong_id', '=', $jielong_id ] ]);
return $this->success($list);
}
/**
* 获取购物车商品数量
* @param $condition
* @return array
*/
public function getCartSumCopy($condition, $field, $alias = 'a', $join = null)
{
$sum = model('promotion_jielong_cart')->getSum($condition, $field, $alias, $join);
return $this->success($sum);
}
public function getCartSum($condition)
{
$sum = model('promotion_jielong_cart')->getCount($condition);
return $this->success($sum);
}
/**
* 获取购物车商品选择数量
* @param $condition
* @return array
*/
public function getCartList($condition = [], $field = 'cart_id,site_id,member_id,sku_id,num,jielong_id', $order = 'cart_id desc')
{
$alias = 'gc';
$join = [
[
'goods_sku gs',
'gc.sku_id = gs.sku_id',
'left'
]
];
$list = model('promotion_jielong_cart')->getList($condition, $field, $order, $alias, $join);
return $this->success($list);
}
}

474
addon/jielong/model/Jielong.php Executable file
View File

@@ -0,0 +1,474 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\jielong\model;
use app\model\BaseModel;
use app\model\goods\Goods;
use app\model\system\Cron;
/**
* 接龙活动
*/
class Jielong extends BaseModel
{
private $status = [
0 => '未开始',
1 => '进行中',
2 => '已结束',
// 3 => '已关闭'
];
/**
* 获取接龙活动状态
* @return array
*/
public function getJielongStatus()
{
return $this->success($this->status);
}
/**
* 添加接龙
* @param $jielong_data
* @param $goods
* @param $sku_list
* @return array
*/
public function addJielong($jielong_data, $goods)
{
if (empty($goods[ 'goods_ids' ])) {
return $this->error('', '该活动至少需要一个商品参与');
}
$jielong_data[ 'create_time' ] = time();
if (time() > $jielong_data[ 'end_time' ]) {
return $this->error('', '当前时间不能大于结束时间');
}
if ($jielong_data[ 'start_time' ] <= time()) {
$jielong_data[ 'status' ] = 1;
$jielong_data[ 'status_name' ] = $this->status[ 1 ];
} else {
$jielong_data[ 'status' ] = 0;
$jielong_data[ 'status_name' ] = $this->status[ 0 ];
}
model("promotion_jielong")->startTrans();
try {
//添加接龙活动
$jielong_data[ 'goods_ids' ] = $goods[ 'goods_ids' ];
$goods[ 'goods_ids' ] = explode(",", $goods[ 'goods_ids' ]);
$jielong_id = model("promotion_jielong")->add($jielong_data);
$list_data = [];
foreach ($goods[ 'goods_ids' ] as $goods_id) {
$list_data[] = [
'site_id' => $jielong_data[ 'site_id' ],
'jielong_id' => $jielong_id,
'goods_id' => $goods_id,
'sale_num' => 0
];
if ($jielong_data[ 'status' ] == 1) {
$goods = new Goods();
$goods->modifyPromotionAddon($goods_id, [ 'jielong' => $jielong_id ]);
}
}
model('promotion_jielong_goods')->addList($list_data);
$cron = new Cron();
if ($jielong_data[ 'status' ] == 1) {
$cron->addCron(1, 0, "接龙活动关闭", "CloseJielong", $jielong_data[ 'end_time' ], $jielong_id);
} else {
$cron->addCron(1, 0, "接龙活动开启", "OpenJielong", $jielong_data[ 'start_time' ], $jielong_id);
$cron->addCron(1, 0, "接龙活动关闭", "CloseJielong", $jielong_data[ 'end_time' ], $jielong_id);
}
model('promotion_jielong')->commit();
return $this->success();
} catch (\Exception $e) {
model('promotion_jielong')->rollback();
return $this->error('', $e->getMessage());
}
}
/**
* 编辑接龙
* @param $jielong_data
* @param $goods
* @param $sku_list
* @return array
*/
public function editJielong($jielong_data, $goods, $sku_list)
{
if (empty($goods)) {
return $this->error('', '至少需要保留一个商品参与');
}
$jielong_info = model("promotion_jielong")->getInfo([ [ 'jielong_id', '=', $jielong_data[ 'jielong_id' ] ], [ 'site_id', '=', $jielong_data[ 'site_id' ] ] ], 'status,end_time,goods_ids');
if (empty($jielong_info)) {
return $this->error('', '该接龙活动不存在');
}
$cron = new Cron();
if (time() > $jielong_data[ 'end_time' ]) {
return $this->error('', '当前时间不能大于结束时间');
}
$jielong_data[ 'status' ] = 0;
if ($jielong_info[ 'status' ] == 1) {
$jielong_data[ 'status' ] = 1;
$jielong_data[ 'status_name' ] = $this->status[ 1 ];
if ($jielong_data[ 'end_time' ] < $jielong_info[ 'end_time' ]) {
return $this->error('', '进行中活动只能延长结束时间,不能缩短时间');
}
} elseif ($jielong_info[ 'status' ] == 0) {
if ($jielong_data[ 'start_time' ] <= time()) {
$jielong_data[ 'status' ] = 1;
$jielong_data[ 'status_name' ] = $this->status[ 1 ];
} else {
$jielong_data[ 'status' ] = 0;
$jielong_data[ 'status_name' ] = $this->status[ 0 ];
}
}
$goods_ids = $goods;
$goods = explode(",", $goods);
model('promotion_jielong')->startTrans();
try {
if ($goods_ids != $jielong_info[ 'goods_ids' ]) {
model("promotion_jielong_goods")->delete([ [ "jielong_id", "=", $jielong_data[ 'jielong_id' ] ], [ "site_id", "=", $jielong_data[ 'site_id' ] ] ]);
$list_data = [];
foreach ($goods as $v) {
$list_data[] = [
'site_id' => $jielong_data[ 'site_id' ],
'jielong_id' => $jielong_data[ 'jielong_id' ],
'goods_id' => $v,
'sale_num' => 0
];
}
model('promotion_jielong_goods')->addList($list_data);
}
model("promotion_jielong")->update(
array_merge($jielong_data, [
'update_time' => time(),
'goods_ids' => $goods_ids
]),
[ [ 'jielong_id', '=', $jielong_data[ 'jielong_id' ] ] ]
);
if ($jielong_data[ 'status' ] == 1) {
$goods_model = new Goods();
foreach ($goods as $goods_id) {
$goods_model->modifyPromotionAddon($goods_id, [ 'jielong' => $jielong_data[ 'jielong_id' ] ]);
}
$cron->deleteCron([ [ 'event', '=', 'OpenJielong' ], [ 'relate_id', '=', $jielong_data[ 'jielong_id' ] ] ]);
$cron->deleteCron([ [ 'event', '=', 'CloseJielong' ], [ 'relate_id', '=', $jielong_data[ 'jielong_id' ] ] ]);
$cron->addCron(1, 0, "接龙活动关闭", "CloseJielong", $jielong_data[ 'end_time' ], $jielong_data[ 'jielong_id' ]);
} else {
$cron->deleteCron([ [ 'event', '=', 'OpenJielong' ], [ 'relate_id', '=', $jielong_data[ 'jielong_id' ] ] ]);
$cron->deleteCron([ [ 'event', '=', 'CloseJielong' ], [ 'relate_id', '=', $jielong_data[ 'jielong_id' ] ] ]);
$cron->addCron(1, 0, "接龙活动开启", "OpenJielong", $jielong_data[ 'start_time' ], $jielong_data[ 'jielong_id' ]);
$cron->addCron(1, 0, "接龙活动关闭", "CloseJielong", $jielong_data[ 'end_time' ], $jielong_data[ 'jielong_id' ]);
}
model('promotion_jielong')->commit();
return $this->success();
} catch (\Exception $e) {
model('promotion_jielong')->rollback();
return $this->error('', $e->getMessage());
}
}
/**
* 删除接龙活动
* @param $jielong_id
* @param $site_id
* @return array|\multitype
*/
public function deleteJielong($jielong_id, $site_id)
{
//接龙信息
$jielong_info = model('promotion_jielong')->getInfo([ [ 'jielong_id', '=', $jielong_id ], [ 'site_id', '=', $site_id ] ], 'status');
if ($jielong_info) {
if ($jielong_info[ 'status' ] != 1) {
$res = model('promotion_jielong')->update([ 'is_delete' => 1 ], [ [ 'jielong_id', '=', $jielong_id ], [ 'site_id', '=', $site_id ] ]);
if ($res) {
// model('promotion_jielong_goods')->delete([['jielong_id', '=', $jielong_id], ['site_id', '=', $site_id]]);
$cron = new Cron();
$cron->deleteCron([ [ 'event', '=', 'OpenJielong' ], [ 'relate_id', '=', $jielong_id ] ]);
$cron->deleteCron([ [ 'event', '=', 'CloseJielong' ], [ 'relate_id', '=', $jielong_id ] ]);
}
return $this->success($res);
} else {
return $this->error('', '接龙活动进行中,请先关闭该活动');
}
} else {
return $this->error('', '接龙活动不存在');
}
}
/**
* 关闭接龙活动
* @param $jielong_id
* @param $site_id
* @return array
*/
public function finishJielong($jielong_id, $site_id)
{
//接龙信息
$jielong_info = model('promotion_jielong')->getInfo([ [ 'jielong_id', '=', $jielong_id ], [ 'site_id', '=', $site_id ] ], 'status,goods_ids');
if (!empty($jielong_info)) {
if ($jielong_info[ 'status' ] != 2) {
$res = model('promotion_jielong')->update([ 'status' => 2, 'status_name' => $this->status[ 2 ] ], [ [ 'jielong_id', '=', $jielong_id ], [ 'site_id', '=', $site_id ], [ 'status', '=', 1 ] ]);
$cron = new Cron();
$cron->deleteCron([ [ 'event', '=', 'OpenJielong' ], [ 'relate_id', '=', $jielong_id ] ]);
$cron->deleteCron([ [ 'event', '=', 'CloseJielong' ], [ 'relate_id', '=', $jielong_id ] ]);
$goods = new Goods();
$arr_ids = explode(',', $jielong_info[ 'goods_ids' ]);
foreach ($arr_ids as $goods_id) {
$goods->modifyPromotionAddon($goods_id, [ 'jielong' => $jielong_id ], true);
}
return $this->success($res);
} else {
$this->error('', '该接龙活动已关闭');
}
} else {
$this->error('', '该接龙活动不存在');
}
}
/**
* 获取接龙详细信息
* @param $jielong_id
* @param $site_id
* @return array
*/
public function getJielongDetail($jielong_id, $site_id)
{
//接龙信息
$jielong_info = model("promotion_jielong")->getInfo([ [ 'jielong_id', '=', $jielong_id ], [ 'site_id', '=', $site_id ] ], '*');
if (!empty($jielong_info)) {
//商品信息
$arr_ids = explode(',', $jielong_info[ 'goods_ids' ]);
$goods_list = model('goods')->getList([ [ 'goods_id', 'in', $arr_ids ] ], 'goods_id,goods_class_name,goods_image,goods_name,goods_stock,is_virtual,price');
if (!empty($goods_list)) {
foreach ($goods_list as $k => $v) {
$goods_list[ $k ][ 'goods_stock' ] = numberFormat($goods_list[ $k ][ 'goods_stock' ]);
}
}
$jielong_info[ 'sku_list' ] = $goods_list;
$jielong_info[ 'sku_list_count' ] = count($jielong_info[ 'sku_list' ]);
}
return $this->success($jielong_info);
}
/**
* 获取接龙活动分页列表
* @param array $condition
* @param number $page
* @param string $page_size
* @param string $order
* @param string $field
*/
public function getJielongPageList($condition, $page, $page_size, $order, $site_id)
{
$field = '*';
$list = model('promotion_jielong')->pageList($condition, $field, $order, $page, $page_size);
foreach ($list[ 'list' ] as &$v) {
$v[ 'goods_num' ] = model('promotion_jielong_goods')->getCount([ [ 'jielong_id', '=', $v[ 'jielong_id' ] ], [ 'site_id', '=', $site_id ] ], 'id');
$v[ 'order_num' ] = model('promotion_jielong_order')->getCount([ [ 'jielong_id', '=', $v[ 'jielong_id' ] ], [ 'site_id', '=', $site_id ] ], 'id');
}
return $this->success($list);
}
/**
* 获取社群接龙活动分页列表
* @param array $condition
* @param number $page
* @param string $page_size
* @param string $order
* @param string $field
*/
public function getJielongActivityPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'jielong_id desc', $field = '*')
{
$list = model('promotion_jielong')->pageList($condition, $field, $order, $page, $page_size);
return $this->success($list);
}
/**
* 获取社群接龙活动详情
* @param array $condition
* @param number $page
* @param string $page_size
* @param string $order
* @param string $field
*/
public function getJielongActivityDetail($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'jielong_id desc', $field = '*', $jielog_id = 0)
{
$alias = 'pjg';
$field = 'pjg.*,g.goods_image,g.goods_name,g.goods_spec_format,g.sku_id,g.goods_stock,gs.price,gs.market_price,gs.discount_price,g.introduction,g.min_buy,g.max_buy,g.is_limit,g.limit_type';
$join = [
[ 'goods g', 'pjg.goods_id = g.goods_id', 'inner' ],
[ 'goods_sku gs', 'g.sku_id = gs.sku_id', 'inner' ]
];
//接龙活动中商品信息
$list = model('promotion_jielong_goods')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
//已抢件数,购买人数
$order_ids = model('promotion_jielong_order')->getColumn([ [ 'jielong_id', '=', $jielog_id ], [ 'order_status', 'not in', [ 0, -1 ] ] ], 'relate_order_id');
foreach ($list[ 'list' ] as $k => $v) {
$sku_ids = model('goods_sku')->getColumn([ [ 'goods_id', '=', $v[ 'goods_id' ] ] ], 'sku_id');
$where = [
[ 'order_id', 'in', $order_ids ],
[ 'sku_id', 'in', $sku_ids ]
];
//已抢件数
$list[ 'list' ][ $k ][ 'buy_num' ] = intval(model('order_goods')->getSum($where, 'num'));
$member_ids = model('order_goods')->getColumn($where, 'member_id', '', 'order_goods_id desc');
$member_ids = array_unique($member_ids);
//购买会员数
$list[ 'list' ][ $k ][ 'member_num' ] = count($member_ids);
//已购买会员头像,取3个
$new_ids = array_slice($member_ids, 0, 3);
$head = [];
foreach ($new_ids as $kk => $vv) {
$member_info = model('member')->getInfo([ [ 'member_id', '=', $vv ] ], 'headimg');
$head[] = $member_info[ 'headimg' ];
}
$list[ 'list' ][ $k ][ 'member_headimg' ] = $head;
}
//接龙活动信息
$list[ 'info' ] = model('promotion_jielong')->getInfo([ [ 'jielong_id', '=', $jielog_id ] ], '*');
return $this->success($list);
}
/**
* 获取社群接龙商品加车数量
*/
public function getCartNum($jielong_id, $goods_id, $member_id, $site_id)
{
$sku_ids = model('goods_sku')->getColumn([ [ 'goods_id', '=', $goods_id ] ], 'sku_id');
$where = [
[ 'sku_id', 'in', $sku_ids ],
[ 'jielong_id', '=', $jielong_id ],
[ 'member_id', '=', $member_id ],
[ 'site_id', '=', $site_id ]
];
$num = model('promotion_jielong_cart')->getSum($where, 'num');
return intval($num);
}
/**
* 获取社群接龙购买分页列表
*/
public function getJielongBuyPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS)
{
$alias = 'o';
$join = [
[ 'promotion_jielong_order pjo', 'o.order_id = pjo.relate_order_id', 'inner' ],
[ 'member m', 'o.member_id = m.member_id', 'inner' ]
];
$order = 'o.pay_time desc';
$field = 'pjo.relate_order_id,o.member_id,o.order_name,o.pay_time,m.headimg,m.nickname';
$list = model('order')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
return $this->success($list);
}
/**
* 开启接龙活动
* @param $jielong_id
* @return array|\multitype
*/
public function cronOpenJielong($jielong_id)
{
$jielong_info = model('promotion_jielong')->getInfo([ [ 'jielong_id', '=', $jielong_id ] ], 'status,goods_ids');
if (!empty($jielong_info)) {
if ($jielong_info[ 'status' ] == 0) {
$res = model('promotion_jielong')->update([ 'status' => 1, 'status_name' => $this->status[ 1 ] ], [ [ 'jielong_id', '=', $jielong_id ] ]);
$goods = new Goods();
$arr_ids = explode(',', $jielong_info[ 'goods_ids' ]);
foreach ($arr_ids as $goods_id) {
$goods->modifyPromotionAddon($goods_id, [ 'jielong' => $jielong_id ]);
}
return $this->success($res);
} else {
return $this->error("", "接龙活动已开启或者关闭");
}
} else {
return $this->error("", "接龙活动不存在");
}
}
/**
* 关闭接龙活动
* @param $jielong_id
* @return array|\multitype
*/
public function cronCloseJielong($jielong_id)
{
$jielong_info = model('promotion_jielong')->getInfo([ [ 'jielong_id', '=', $jielong_id ] ], 'status,goods_ids');
if (!empty($jielong_info)) {
if ($jielong_info[ 'status' ] == 1) {
$res = model('promotion_jielong')->update([ 'status' => 2, 'status_name' => $this->status[ 2 ] ], [ [ 'jielong_id', '=', $jielong_id ] ]);
$goods = new Goods();
$arr_ids = explode(',', $jielong_info[ 'goods_ids' ]);
foreach ($arr_ids as $goods_id) {
$goods->modifyPromotionAddon($goods_id, [ 'jielong' => $jielong_id ], true);
}
return $this->success($res);
} else {
return $this->error("", "该活动已结束");
}
} else {
return $this->error("", "接龙活动不存在");
}
}
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\jielong\model;
use app\model\BaseModel;
/**
* 商品接龙
*/
class JielongOrder extends BaseModel
{
/**
* 获取接龙订单信息
* @param array $condition
* @param string $field
* @return array
*/
public function getJielongOrderInfo($condition = [], $field = '*')
{
$info = model('promotion_jielong_order')->getInfo($condition, $field);
$order_goods_list = model('order_goods')->getList([ 'order_id' => $info[ 'relate_order_id' ] ], 'sku_name,price,num,goods_money');
foreach ($order_goods_list as $k => $v) {
$order_goods_list[ $k ][ 'num' ] = numberFormat($order_goods_list[ $k ][ 'num' ]);
}
$info[ 'order_goods_list' ] = $order_goods_list;
return $this->success($info);
}
/**
* 获取接龙订单分页列表
* @param array $condition
* @param int $page
* @param int $page_size
* @param string $order
* @param string $field
* @return array
*/
public function getJielongOrderPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'id desc', $field = '*')
{
$join = [
[
'order o',
'o.order_id = pjo.relate_order_id',
'left'
]
];
$field = 'pjo.*,o.order_status_name';
$list = model('promotion_jielong_order')->pageList($condition, $field, $order, $page, $page_size, 'pjo', $join);
//获取关联订单商品
foreach ($list[ 'list' ] as $k => $v) {
$order_goods_list = model('order_goods')->getList([ 'order_id' => $v[ 'relate_order_id' ] ], 'sku_image,sku_name,price,num');
foreach ($order_goods_list as $ck => $cv) {
$order_goods_list[ $ck ][ 'num' ] = numberFormat($order_goods_list[ $ck ][ 'num' ]);
}
$list[ 'list' ][ $k ][ 'order_goods_list' ] = $order_goods_list;
}
return $this->success($list);
}
}

View File

@@ -0,0 +1,230 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\jielong\model;
use addon\store\model\StoreGoodsSku;
use addon\store\model\StoreOrder;
use app\model\BaseModel;
use app\model\order\LocalOrder;
use app\model\order\Order;
use app\model\order\VirtualOrder;
/**
* 商品接龙
*/
class JielongOrderCommon extends BaseModel
{
// 订单待付款
const ORDER_CREATE = 0;
//订单完成(尾款已支付)
const ORDER_PAY = 1;
// 订单已关闭
const ORDER_CLOSE = -1;
/**
* 基础订单状态(不同类型的订单可以不使用这些状态,但是不能冲突)
* @var unknown
*/
public $order_status = [
self::ORDER_CREATE => [
'status' => self::ORDER_CREATE,
'name' => '待付款',
'is_allow_refund' => 0,
'icon' => 'public/uniapp/order/order-icon-send.png',
'action' => [
[
'action' => 'orderClose',
'title' => '关闭订单',
'color' => ''
],
[
'action' => 'offlinePayDeposit',
'title' => '线下支付定金',
'color' => ''
],
],
'member_action' => [
[
'action' => 'orderClose',
'title' => '关闭订单',
'color' => ''
],
[
'action' => 'orderPayDeposit',
'title' => '支付定金',
'color' => ''
],
],
'color' => ''
],
self::ORDER_PAY => [
'status' => self::ORDER_PAY,
'name' => '已完成',
'is_allow_refund' => 0,
'icon' => 'public/uniapp/order/order-icon-send.png',
'action' => [],
'member_action' => [],
'color' => ''
],
self::ORDER_CLOSE => [
'status' => self::ORDER_CLOSE,
'name' => '已关闭',
'is_allow_refund' => 0,
'icon' => 'public/uniapp/order/order-icon-close.png',
'action' => [
[
'action' => 'deleteOrder',
'title' => '删除订单',
'color' => ''
],
],
'member_action' => [
[
'action' => 'deleteOrder',
'title' => '删除订单',
'color' => ''
],
],
'color' => ''
],
];
/**
* 订单状态
* @return array
*/
public function getOrderStatus()
{
return $this->success($this->order_status);
}
/**
* 会员接龙订单分页列表
* @param array $condition
* @param int $page
* @param int $page_size
* @param string $order
* @param string $field
* @return array
*/
public function getMemberOrderPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
{
$order_list = model('promotion_jielong_order')->pageList($condition, $field, $order, $page, $page_size);
if (!empty($order_list[ 'list' ])) {
foreach ($order_list[ 'list' ] as $k => $v) {
$order_goods_list = model('order_goods')->getList([
'order_id' => $v[ 'relate_order_id' ]
]);
foreach ($order_goods_list as $ck => $cv) {
$order_goods_list[ $ck ][ 'num' ] = numberFormat($order_goods_list[ $ck ][ 'num' ]);
}
$order_list[ 'list' ][ $k ][ 'order_goods' ] = $order_goods_list;
$action = empty($v[ "order_status_action" ]) ? [] : json_decode($v[ "order_status_action" ], true);
$member_action = $action[ "member_action" ] ?? [];
$order_list[ 'list' ][ $k ][ 'action' ] = $member_action;
}
}
return $this->success($order_list);
}
/**
* 会员订单详情
* @param $id
* @param $member_id
*/
public function getMemberOrderDetail($id, $member_id, $site_id)
{
$order_info = model('promotion_jielong_order')->getInfo([ [ 'id', "=", $id ], [ "member_id", "=", $member_id ], [ "site_id", "=", $site_id ] ]);
if (empty($order_info))
return $this->error([], "当前订单不是本账号的订单!");
$action = empty($order_info[ "order_status_action" ]) ? [] : json_decode($order_info[ "order_status_action" ], true);
$member_action = $action[ "member_action" ] ?? [];
$order_info[ 'action' ] = $member_action;
$order_goods_list = model('order_goods')->getList([ [ 'order_id', "=", $order_info[ 'relate_order_id' ] ], [ "member_id", "=", $member_id ] ]);
foreach ($order_goods_list as $k => $v) {
$refund_action = empty($v[ "refund_status_action" ]) ? [] : json_decode($v[ "refund_status_action" ], true);
$refund_action = $refund_action[ "member_action" ] ?? [];
$order_goods_list[ $k ][ "refund_action" ] = $refund_action;
$order_goods_list[ $k ][ 'num' ] = numberFormat($order_goods_list[ $k ][ 'num' ]);
}
$order_info[ 'order_goods' ] = $order_goods_list;
$order_info[ 'order_id' ] = $order_info[ 'relate_order_id' ];
switch ( $order_info[ 'order_type' ] ) {
case 1:
$order_model = new Order();
break;
case 2:
$order_model = new StoreOrder();
break;
case 3:
$order_model = new LocalOrder();
break;
case 4:
$order_model = new VirtualOrder();
break;
}
$temp_info = $order_model->orderDetail($order_info);
$order_info = array_merge($order_info, $temp_info);
return $this->success($order_info);
}
//获取接龙订单id
public function getJielongOrderId($id)
{
$info = model('promotion_jielong_order')->getInfo([ [ 'id', "=", $id ] ], 'relate_order_id');
return $info[ 'relate_order_id' ];
}
/**
* 订单关闭增加门店商品库存
* @param $data
* @return array
*/
public function incStoreGoodsStock($data)
{
$store_goods_sku_model = new StoreGoodsSku();
$stock_result = $store_goods_sku_model->incStock([ "store_id" => $data[ "delivery_store_id" ], "sku_id" => $data[ "sku_id" ], 'stock' => $data[ "num" ] ]);
if ($stock_result[ "code" ] < 0) {
return $stock_result;
}
}
/*********************************************** 订单异步回调 end *****************************************************************/
/**
* 订单删除
* @param $condition
* @return array
*/
public function deleteOrder($condition)
{
$info = model('promotion_jielong_order')->getInfo($condition, 'order_status');
if (empty($info)) {
return $this->error('', '订单不存在');
}
if ($info[ 'order_status' ] != self::ORDER_CLOSE) {
return $this->error('', '抱歉,只有已关闭的订单才可以删除');
}
$res = model('promotion_jielong_order')->delete($condition);
if ($res) {
return $this->success($res);
} else {
return $this->error();
}
}
}

802
addon/jielong/model/Poster.php Executable file
View File

@@ -0,0 +1,802 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\jielong\model;
use app\model\BaseModel;
use app\model\system\Config as ConfigModel;
use app\model\system\Site;
use app\model\upload\Upload;
use extend\Poster as PosterExtend;
/**
* 海报生成类
*/
class Poster extends BaseModel
{
/**
* 接龙海报 用户端
*/
public function goods($app_type, $page, $qrcode_param, $promotion_type, $site_id)
{
//根据不同的app_type 生成不同的分享地址 二维码
try {
$goods_info = $this->getGoodsInfo($qrcode_param[ 'jielong_id' ], $site_id);
if (empty($goods_info)) return $this->error('未获取到商品信息');
$weapp_status = 0;
//判断是否绑定小程序
if ($app_type == 'weapp') {
$config = new ConfigModel();
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WEAPP_CONFIG' ] ]);
if (!empty($res[ 'data' ])) {
if (empty($res[ 'data' ][ 'value' ][ 'qrcode' ])) {
return $this->success([ "status" => 2 ]);
} else {
$weapp_status = 1;
}
} else {
return $this->success([ "status" => 2 ]);
}
}
$qrcode_info = $this->getGoodsQrcode($app_type, $page, $qrcode_param, $promotion_type, $site_id);
if ($qrcode_info[ 'code' ] < 0) return $qrcode_info;
if (!empty($qrcode_param[ 'source_member' ])) {
$member_info = $this->getMemberInfo($qrcode_param[ 'source_member' ]);
}
//平台配置信息
$site_model = new Site();
$site_info = $site_model->getSiteInfo([ [ "site_id", "=", $site_id ] ]);
$site_name = $site_info[ 'data' ][ 'site_name' ];
$jielong_info = $goods_info[ 'jielong_info' ];
$goods_info = $goods_info[ 'list' ];
$poster = new PosterExtend(600, 960);
$option = [
[
'action' => 'imageCopy', // 背景图
'data' => [
'upload/poster/bg/jielong.png',
0,
0,
600,
960,
'square',
true,
1
]
],
[
'action' => 'imageCopy', // 二维码/太阳码
'data' => [
$qrcode_info[ 'data' ][ 'path' ],
$weapp_status ? 383 : 413, //x
$weapp_status ? 740 : 770, //y
$weapp_status ? 165 : 135,
$weapp_status ? 165 : 135,
'square',
0,
1
]
],
[
'action' => 'imageText', // 接龙时间
'data' => [
$jielong_info[ 'jielong_time' ],
18,
[ 255, 95, 75 ],
60,
845,
500,
1,
true
]
],
[
'action' => 'imageText', // 接龙状态
'data' => [
$jielong_info[ 'jielong_status_name' ],
18,
[ 18, 18, 18 ],
270,
845,
500,
1,
true
]
],
[
'action' => 'imageCircularCopy', // 写入店铺头像
'data' => [
!empty($site_info[ 'data' ][ 'logo_square' ]) ? $site_info[ 'data' ][ 'logo_square' ] : 'public/uniapp/shop_img.png',
30,
40,
80,
80
]
],
[
'action' => 'imageText', // 写入店铺名称
'data' => [
!empty($site_name) ? $site_name : '单商户v5',
22,
[ 255, 255, 255 ],
130,
80,
440,
1
]
],
[
'action' => 'imageText', // 写入接龙语
'data' => [
'"这个接龙不错,快和我一起参与吧!"',
18,
[ 255, 255, 255 ],
130,
115,
440,
1
]
]
];
$goods_option = [];
$y = 0;
foreach ($goods_info as &$v) {
array_push($goods_option,
[
'action' => 'imageCopy', // 商品图
'data' => [
$v[ 'goods_image' ],
60,
190 + $y,//y
140,
140,
'square',
30,
1
]
],
[
'action' => 'imageText', // 写入商品名称
'data' => [
$v[ 'goods_name' ],
16,
[ 89, 89, 89 ],
218,
225 + $y,//y
330,
2,
true
]
],
[
'action' => 'imageText', // 写入商品促销语
'data' => [
$v[ 'introduction' ],
12,
[ 205, 205, 205 ],
218,
287 + $y,//y
330,
1,
true
]
],
[
'action' => 'imageText', // 写入商品售价
'data' => [
'¥ ' . $v[ 'discount_price' ],
20,
[ 255, 95, 75 ],
218,
326 + $y,//y
500,
1,
true
]
],
[
'action' => 'imageText', // 写入商品原价
'data' => [
'¥ ' . $v[ 'market_price' ],
16,
[ 205, 205, 205 ],
340,
326 + $y,//y
500,
1,
true,
!empty($v[ 'is_market_price' ]) ? 1 : 0,
]
],
[
'action' => 'imageCopy', // 删除线
'data' => [
'upload/poster/bg/del_line.png',
337,
283 + $y,//y
85,
64,
'square',
true,
!empty($v[ 'is_market_price' ]) ? 1 : 0,
]
]
);
$y += 180;
}
$option = array_merge($option, $goods_option);
$option_res = $poster->create($option);
if (is_array($option_res)) return $option_res;
$res = $option_res->jpeg('upload/poster/jielong', 'goods_' . $promotion_type . '_' . $qrcode_param[ 'jielong_id' ] . '_' . time() . '_' . $app_type);
if ($res[ 'code' ] == 0) {
$upload = new Upload($site_id);
$cloud_res = $upload->fileCloud($res[ 'data' ][ 'path' ]);
if ($cloud_res[ 'code' ] >= 0) {
if ($app_type == 'weapp') {
return $this->success([ "poster_path" => $cloud_res[ 'data' ] . '?code=' . uniqid(), "qrcode_path" => $qrcode_info[ 'data' ][ 'path' ], "status" => $weapp_status ]);
} else {
return $this->success([ "poster_path" => $cloud_res[ 'data' ] . '?code=' . uniqid(), "qrcode_path" => $qrcode_info[ 'data' ][ 'path' ], "qrcode_url" => $qrcode_info[ 'data' ][ 'url' ] ]);
}
} else {
return $this->error();
}
}
return $res;
} catch (\Exception $e) {
return $this->error($e->getMessage() . $e->getFile() . $e->getLine());
}
}
/**
* 接龙海报 管理端
*/
public function goodsShop($app_type, $page, $qrcode_param, $promotion_type, $site_id)
{
//根据不同的app_type 生成不同的分享地址 二维码
try {
$goods_info = $this->getGoodsInfo($qrcode_param[ 'jielong_id' ], $site_id);
if (empty($goods_info)) return $this->error('未获取到商品信息');
//判断是否绑定小程序
$config = new ConfigModel();
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WEAPP_CONFIG' ] ]);
$status = 0;
if (!empty($res[ 'data' ])) {
if (!empty($res[ 'data' ][ 'value' ][ 'qrcode' ])) {
$status = 1;
}
}
//平台配置信息
$site_model = new Site();
$site_info = $site_model->getSiteInfo([ [ "site_id", "=", $site_id ] ]);
$site_name = $site_info[ 'data' ][ 'site_name' ];
$h5_qrcode_info = $this->getGoodsQrcode('h5', $page, $qrcode_param, $promotion_type, $site_id);
if ($h5_qrcode_info[ 'code' ] < 0) return $h5_qrcode_info;
$jielong_info = $goods_info[ 'jielong_info' ];
$goods_info = $goods_info[ 'list' ];
$poster = new PosterExtend(600, 960);
$poster_2 = new PosterExtend(600, 960);
$option = [
[
'action' => 'imageCopy', // 背景图
'data' => [
'upload/poster/bg/jielong.png',
0,
0,
600,
960,
'square',
true,
1
]
],
[
'action' => 'imageCopy', // 二维码
'data' => [
$h5_qrcode_info[ 'data' ][ 'path' ],
413, //x
770, //y
135,
135,
'square',
0,
1
]
],
[
'action' => 'imageText', // 接龙时间
'data' => [
$jielong_info[ 'jielong_time' ],
18,
[ 255, 95, 75 ],
60,
845,
500,
1,
true
]
],
[
'action' => 'imageText', // 接龙状态
'data' => [
$jielong_info[ 'jielong_status_name' ],
18,
[ 18, 18, 18 ],
270,
845,
500,
1,
true
]
],
[
'action' => 'imageCircularCopy', // 写入店铺头像
'data' => [
!empty($site_info[ 'data' ][ 'logo_square' ]) ? $site_info[ 'data' ][ 'logo_square' ] : 'public/uniapp/shop_img.png',
30,
40,
80,
80
]
],
[
'action' => 'imageText', // 写入店铺名称
'data' => [
!empty($site_name) ? $site_name : '单商户v5',
22,
[ 255, 255, 255 ],
130,
80,
440,
1
]
],
[
'action' => 'imageText', // 写入接龙语
'data' => [
'"这个接龙不错,快和我一起参与吧!"',
18,
[ 255, 255, 255 ],
130,
115,
440,
1
]
]
];
$goods_option = [];
$y = 0;
foreach ($goods_info as &$v) {
array_push($goods_option,
[
'action' => 'imageCopy', // 商品图
'data' => [
$v[ 'goods_image' ],
60,
190 + $y,//y
140,
140,
'square',
30,
1
]
],
[
'action' => 'imageText', // 写入商品名称
'data' => [
$v[ 'goods_name' ],
16,
[ 89, 89, 89 ],
218,
225 + $y,//y
330,
2,
true
]
],
[
'action' => 'imageText', // 写入商品促销语
'data' => [
$v[ 'introduction' ],
12,
[ 205, 205, 205 ],
218,
287 + $y,//y
330,
1,
true
]
],
[
'action' => 'imageText', // 写入商品售价
'data' => [
'¥ ' . $v[ 'discount_price' ],
20,
[ 255, 95, 75 ],
218,
326 + $y,//y
500,
1,
true
]
],
[
'action' => 'imageText', // 写入商品原价
'data' => [
'¥ ' . $v[ 'market_price' ],
16,
[ 205, 205, 205 ],
340,
326 + $y,//y
500,
1,
true,
!empty($v[ 'is_market_price' ]) ? 1 : 0,
]
],
[
'action' => 'imageCopy', // 删除线
'data' => [
'upload/poster/bg/del_line.png',
337,
283 + $y,//y
85,
64,
'square',
true,
!empty($v[ 'is_market_price' ]) ? 1 : 0,
]
]
);
$y += 180;
}
$option = array_merge($option, $goods_option);
$option_res = $poster->create($option);
if (is_array($option_res)) return $option_res;
$res = $option_res->jpeg('upload/poster/jielong', 'goods_' . $promotion_type . '_' . $qrcode_param[ 'jielong_id' ] . rand(0, 99999) . '_' . 'h5');
if ($status) {
$weapp_qrcode_info = $this->getGoodsQrcode('weapp', $page, $qrcode_param, $promotion_type, $site_id);
if ($weapp_qrcode_info[ 'code' ] < 0) return $weapp_qrcode_info;
$option_2 = [
[
'action' => 'imageCopy', // 背景图
'data' => [
'upload/poster/bg/jielong.png',
0,
0,
600,
960,
'square',
true,
1
]
],
[
'action' => 'imageCopy', //太阳码
'data' => [
$weapp_qrcode_info[ 'data' ][ 'path' ],
383, //x
740, //y
165,
165,
'square',
0,
1
]
],
[
'action' => 'imageText', // 接龙时间
'data' => [
$jielong_info[ 'jielong_time' ],
18,
[ 255, 95, 75 ],
60,
845,
500,
1,
true
]
],
[
'action' => 'imageText', // 接龙状态
'data' => [
$jielong_info[ 'jielong_status_name' ],
18,
[ 18, 18, 18 ],
270,
845,
500,
1,
true
]
],
[
'action' => 'imageCircularCopy', // 写入店铺头像
'data' => [
'public/uniapp/shop_img.png',
30,
40,
80,
80
]
],
[
'action' => 'imageText', // 写入店铺名称
'data' => [
!empty($site_name) ? $site_name : '单商户v5',
22,
[ 255, 255, 255 ],
130,
80,
440,
1
]
],
[
'action' => 'imageText', // 写入接龙语
'data' => [
'"这个接龙不错,快和我一起参与吧!"',
18,
[ 255, 255, 255 ],
130,
115,
440,
1
]
]
];
$goods_option_2 = [];
$y_2 = 0;
foreach ($goods_info as &$v) {
array_push($goods_option_2,
[
'action' => 'imageCopy', // 商品图
'data' => [
$v[ 'goods_image' ],
60,
190 + $y_2,//y
140,
140,
'square',
30,
1
]
],
[
'action' => 'imageText', // 写入商品名称
'data' => [
$v[ 'goods_name' ],
16,
[ 89, 89, 89 ],
218,
225 + $y_2,//y
330,
2,
true
]
],
[
'action' => 'imageText', // 写入商品促销语
'data' => [
$v[ 'introduction' ],
12,
[ 205, 205, 205 ],
218,
287 + $y_2,//y
330,
1,
true
]
],
[
'action' => 'imageText', // 写入商品售价
'data' => [
'¥ ' . $v[ 'discount_price' ],
20,
[ 255, 95, 75 ],
218,
326 + $y_2,//y
500,
1,
true
]
],
[
'action' => 'imageText', // 写入商品原价
'data' => [
'¥ ' . $v[ 'market_price' ],
16,
[ 205, 205, 205 ],
340,
326 + $y_2,//y
500,
1,
true,
!empty($v[ 'is_market_price' ]) ? 1 : 0,
]
],
[
'action' => 'imageCopy', // 删除线
'data' => [
'upload/poster/bg/del_line.png',
337,
283 + $y_2,//y
85,
64,
'square',
true,
!empty($v[ 'is_market_price' ]) ? 1 : 0,
]
]
);
$y_2 += 180;
}
$option_2 = array_merge($option_2, $goods_option_2);
$option_res_2 = $poster_2->create($option_2);
if (is_array($option_res_2)) return $option_res_2;
$res_2 = $option_res_2->jpeg('upload/poster/jielong', 'goods_' . $promotion_type . '_' . $qrcode_param[ 'jielong_id' ] . rand(0, 999999) . '_' . 'weapp');
}
//if中的三元运算用法 true or 1==1 均可
if ($res[ 'code' ] == 0 && ( $status ? $res_2[ 'code' ] == 0 : true )) {
$upload = new Upload($site_id);
$cloud_res = $upload->fileCloud($res[ 'data' ][ 'path' ]);
if ($status) {
$cloud_res_2 = $upload->fileCloud($res_2[ 'data' ][ 'path' ]);
}
if ($cloud_res[ 'code' ] >= 0 && ( $status ? $cloud_res_2[ 'code' ] >= 0 : 1 == 1 )) {
$data = [
'h5_poster_path' => $cloud_res[ 'data' ],
'h5_qrcode_path' => $h5_qrcode_info[ 'data' ][ 'path' ],
'h5_qrcode_url' => $h5_qrcode_info[ 'data' ][ 'url' ],
'weapp_poster_path' => $status ? $cloud_res_2[ 'data' ] : '',
'weapp_qrcode_path' => $status ? $weapp_qrcode_info[ 'data' ][ 'path' ] : '',
'status' => $status,
'code' => uniqid()
];
return $this->success($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 $jielong_id
*/
private function getGoodsInfo($jielong_id, $site_id)
{
$condition = [
[ 'pjg.jielong_id', '=', $jielong_id ],
[ 'g.goods_state', '=', 1 ],
[ 'g.is_delete', '=', 0 ],
[ 'g.site_id', '=', $site_id ]
];
$alias = 'pjg';
$join = [
[ 'goods g', 'pjg.goods_id = g.goods_id', 'inner' ],
[ 'goods_sku gs', 'g.sku_id = gs.sku_id', 'inner' ]
];
$field = 'g.goods_image,g.goods_name,g.goods_stock,gs.price,gs.market_price,gs.discount_price,g.introduction';
//接龙活动中商品信息
$list = model('promotion_jielong_goods')->pageList($condition, $field, 'id asc', 1, 3, $alias, $join);
$info = model('promotion_jielong')->getInfo([ 'jielong_id' => $jielong_id ], 'status,start_time,end_time');
if ($info[ 'status' ] == 0) {
$list[ 'jielong_info' ][ 'jielong_status_name' ] = '开始';
$list[ 'jielong_info' ][ 'jielong_time' ] = date("m月-d日 H:i:s", $info[ 'start_time' ]);
} else {
$list[ 'jielong_info' ][ 'jielong_status_name' ] = '结束';
$list[ 'jielong_info' ][ 'jielong_time' ] = date("m月d日 H:i:s", $info[ 'end_time' ]);
}
//获取第一张图片
foreach ($list[ 'list' ] as &$v) {
$v[ 'goods_image' ] = explode(',', $v[ 'goods_image' ])[ 0 ];
$v[ 'introduction' ] = $v[ 'introduction' ] ?: '精选好物,等你来抢';
$v[ 'is_market_price' ] = 1;
if ($v[ 'market_price' ] == 0) {
$v[ 'is_market_price' ] = 0;
}
//判断是否是全路径
// if (!preg_match('/(http:\/\/)|(https:\/\/)/i', $v['goods_image'])) {
// $v['goods_image'] = __ROOT__.'/'.$v['goods_image'];
// }
}
return $list;
}
/**
* 获取商品二维码
* @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' => [ 'jielong_id' => $qrcode_param[ 'jielong_id' ] ],
'page' => $page,
'qrcode_path' => 'upload/qrcode/jielong',
// 'qrcode_name' => 'goods_' . $promotion_type . '_' . $qrcode_param['jielong_id'] . '_' . $qrcode_param['source_member'] . '_' . $site_id,
'qrcode_name' => 'goods_' . $promotion_type . '_' . $qrcode_param[ 'jielong_id' ] . '_' . $site_id,
], true);
return $res;
}
/**
* 获取接龙推广
* @param $page
* @param $qrcode_param
* @param $promotion_type
* @param $site_id
* @return array
*/
public function getSolitaireQrcode($page, $qrcode_param, $promotion_type, $app_type, $site_id)
{
$params = [
'site_id' => $site_id,
'data' => [ 'jielong_id' => $qrcode_param[ 'jielong_id' ] ],
'page' => $page,
'promotion_type' => $promotion_type,
'app_type' => $app_type,
'h5_path' => $page . '?jielong_id=' . $qrcode_param[ 'jielong_id' ],
'qrcode_path' => 'upload/qrcode/jielong',
'qrcode_name' => 'goods_' . $promotion_type . '_' . $qrcode_param[ 'jielong_id' ] . '_' . $site_id,
];
$solitaire = event('PromotionQrcode', $params, true);
return $this->success($solitaire);
}
}

View File

@@ -0,0 +1,83 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\jielong\model\share;
use addon\jielong\model\Jielong as JielongModel;
use app\model\share\WchatShareBase as BaseModel;
/**
* 分享
*/
class WchatShare extends BaseModel
{
protected $config = [
[
'title' => '接龙分享',
'config_key' => 'WCHAT_SHARE_CONFIG_JIELONG_PROMOTE',
'path' => [ '/pages_promotion/jielong/jielong' ],
'method_prefix' => 'goodsDetail',
],
];
protected $sort = 4;
/**
* 接龙分享
* @param $param
* @return array
*/
protected function goodsDetailShareData($param)
{
$site_id = $param[ 'site_id' ] ?? 0;
$member_id = $param[ 'member_id' ] ?? 0;
$url = $param[ 'url' ];
$parse_res = parse_url($url);
parse_str($parse_res[ 'query' ] ?? '', $query);
if (isset($query[ 'jielong_id' ]) || isset($query[ 'id' ])) {
$jielong_id = $query['id'] ?? $query['jielong_id'];
$condition = [
[ 'pjg.jielong_id', '=', $jielong_id ],
[ 'g.goods_state', '=', 1 ],
[ 'g.is_delete', '=', 0 ],
[ 'g.site_id', '=', $site_id ]
];
$jielong_model = new JielongModel();
$sku_info = $jielong_model->getJielongActivityDetail($condition, 1, PAGE_LIST_ROWS, '', '', $jielong_id)[ 'data' ];
if (!empty($sku_info)) {
$config_method = preg_replace('/Data$/', 'Config', __FUNCTION__);
$config_model = new \app\model\share\WchatShare();
$config_data = $config_model->$config_method($param);
$title = str_replace('{goods_name}', $sku_info[ 'info' ][ 'jielong_name' ], $config_data[ 'value' ][ 'title' ]);
$desc = str_replace('{price}', $sku_info[ 'list' ][ 0 ][ 'price' ], $config_data[ 'value' ][ 'desc' ]);
$desc = str_replace('\n', '\r\n', $desc);
$link = $parse_res[ 'scheme' ] . '://' . $parse_res[ 'host' ] . $parse_res[ 'path' ] . '?jielong_id=' . $jielong_id;
if (!empty($member_id)) $link .= '&source_member=' . $member_id;
$image_url = $sku_info[ 'list' ][ 0 ][ 'goods_image' ];
$data = [
'title' => $title,
'desc' => $desc,
'link' => $link,
'imgUrl' => $image_url,
];
return [
'permission' => [
'hideOptionMenu' => false,
'hideMenuItems' => [],
],
'data' => $data,//分享内容
];
}
}
}
}