初始上传
This commit is contained in:
548
addon/groupbuy/model/Groupbuy.php
Executable file
548
addon/groupbuy/model/Groupbuy.php
Executable file
@@ -0,0 +1,548 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\groupbuy\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use app\model\goods\Goods;
|
||||
use app\model\system\Config as ConfigModel;
|
||||
use app\model\system\Cron;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 团购活动
|
||||
*/
|
||||
class Groupbuy extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 添加团购
|
||||
* @param $groupbuy_data
|
||||
* @param $goods_list
|
||||
* @param $goods_ids
|
||||
* @return array
|
||||
*/
|
||||
public function addGroupbuy($groupbuy_data, $goods_list, $goods_ids)
|
||||
{
|
||||
//查询该商品是否存在团购
|
||||
$count = model('promotion_groupbuy')->getCount(
|
||||
[
|
||||
['site_id', '=', $groupbuy_data['site_id']],
|
||||
['status', 'in', '1,2'],
|
||||
['goods_id', 'in', $goods_ids],
|
||||
['', 'exp', Db::raw('not ( (`start_time` > ' . $groupbuy_data['end_time'] . ' and `start_time` > ' . $groupbuy_data['start_time'] . ' ) or (`end_time` < ' . $groupbuy_data['start_time'] . ' and `end_time` < ' . $groupbuy_data['end_time'] . '))')]
|
||||
]
|
||||
);
|
||||
if ($count > 0) {
|
||||
return $this->error('', '当前时间段内有商品存在团购活动');
|
||||
}
|
||||
|
||||
// 当前时间
|
||||
$time = time();
|
||||
if ($time > $groupbuy_data['end_time']) {
|
||||
return $this->error('', '当前时间不能大于结束时间');
|
||||
}
|
||||
if ($time > $groupbuy_data['start_time'] && $time < $groupbuy_data['end_time']) {
|
||||
$groupbuy_data['status'] = 2;
|
||||
} else {
|
||||
$groupbuy_data['status'] = 1;
|
||||
}
|
||||
|
||||
model('promotion_groupbuy')->startTrans();
|
||||
try {
|
||||
|
||||
$groupbuy_data['create_time'] = $time;
|
||||
foreach ($goods_list as $v) {
|
||||
|
||||
$groupbuy_id = model('promotion_groupbuy')->add(array_merge($v, $groupbuy_data));
|
||||
$cron = new Cron();
|
||||
if ($groupbuy_data['status'] == 2) {
|
||||
$goods = new Goods();
|
||||
$goods->modifyPromotionAddon($v['goods_id'], ['groupbuy' => $groupbuy_id]);
|
||||
$cron->addCron(1, 0, '团购活动关闭', 'CloseGroupbuy', $groupbuy_data['end_time'], $groupbuy_id);
|
||||
} else {
|
||||
$cron->addCron(1, 0, '团购活动开启', 'OpenGroupbuy', $groupbuy_data['start_time'], $groupbuy_id);
|
||||
$cron->addCron(1, 0, '团购活动关闭', 'CloseGroupbuy', $groupbuy_data['end_time'], $groupbuy_id);
|
||||
}
|
||||
}
|
||||
model('promotion_groupbuy')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('promotion_groupbuy')->rollback();
|
||||
return $this->error();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑团购
|
||||
* @param $groupbuy_id
|
||||
* @param $site_id
|
||||
* @param $groupbuy_data
|
||||
* @return array|\multitype
|
||||
*/
|
||||
public function editGroupbuy($groupbuy_id, $site_id, $groupbuy_data)
|
||||
{
|
||||
//查询该商品是否存在团购
|
||||
$count = model('promotion_groupbuy')->getCount(
|
||||
[
|
||||
['site_id', '=', $site_id],
|
||||
['status', 'in', '1,2'],
|
||||
['groupbuy_id', '<>', $groupbuy_id],
|
||||
['goods_id', '=', $groupbuy_data['goods_id']],
|
||||
['', 'exp', Db::raw('not ( (`start_time` > ' . $groupbuy_data['end_time'] . ' and `start_time` > ' . $groupbuy_data['start_time'] . ' ) or (`end_time` < ' . $groupbuy_data['start_time'] . ' and `end_time` < ' . $groupbuy_data['end_time'] . '))')]
|
||||
]
|
||||
);
|
||||
if ($count > 0) {
|
||||
return $this->error('', '当前时间段内该商品存在团购活动');
|
||||
}
|
||||
// 当前时间
|
||||
$time = time();
|
||||
if ($time > $groupbuy_data['end_time']) {
|
||||
return $this->error('', '当前时间不能大于结束时间');
|
||||
}
|
||||
if ($time > $groupbuy_data['start_time'] && $time < $groupbuy_data['end_time']) {
|
||||
$groupbuy_data['status'] = 2;
|
||||
} else {
|
||||
$groupbuy_data['status'] = 1;
|
||||
}
|
||||
|
||||
$groupbuy_data['modify_time'] = time();
|
||||
|
||||
$res = model('promotion_groupbuy')->update($groupbuy_data, [['groupbuy_id', '=', $groupbuy_id], ['site_id', '=', $site_id]]);
|
||||
|
||||
$cron = new Cron();
|
||||
if ($groupbuy_data['status'] == 2) {
|
||||
//活动商品启动
|
||||
$this->cronOpenGroupbuy($groupbuy_id);
|
||||
$cron->deleteCron([['event', '=', 'OpenGroupbuy'], ['relate_id', '=', $groupbuy_id]]);
|
||||
$cron->deleteCron([['event', '=', 'CloseGroupbuy'], ['relate_id', '=', $groupbuy_id]]);
|
||||
|
||||
$cron->addCron(1, 0, '团购活动关闭', 'CloseGroupbuy', $groupbuy_data['end_time'], $groupbuy_id);
|
||||
} else {
|
||||
$cron->deleteCron([['event', '=', 'OpenGroupbuy'], ['relate_id', '=', $groupbuy_id]]);
|
||||
$cron->deleteCron([['event', '=', 'CloseGroupbuy'], ['relate_id', '=', $groupbuy_id]]);
|
||||
|
||||
$cron->addCron(1, 0, '团购活动开启', 'OpenGroupbuy', $groupbuy_data['start_time'], $groupbuy_id);
|
||||
$cron->addCron(1, 0, '团购活动关闭', 'CloseGroupbuy', $groupbuy_data['end_time'], $groupbuy_id);
|
||||
}
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除团购活动
|
||||
* @param $groupbuy_id
|
||||
* @param $site_id
|
||||
* @return array|\multitype
|
||||
*/
|
||||
public function deleteGroupbuy($groupbuy_id, $site_id)
|
||||
{
|
||||
//团购信息
|
||||
$groupbuy_info = model('promotion_groupbuy')->getInfo([['groupbuy_id', '=', $groupbuy_id], ['site_id', '=', $site_id]], 'groupbuy_id,status,goods_id');
|
||||
if ($groupbuy_info) {
|
||||
if (in_array($groupbuy_info['status'], [1, 3])) {
|
||||
$res = model('promotion_groupbuy')->delete([['groupbuy_id', '=', $groupbuy_id]]);
|
||||
if ($res) {
|
||||
$cron = new Cron();
|
||||
$cron->deleteCron([['event', '=', 'OpenGroupbuy'], ['relate_id', '=', $groupbuy_id]]);
|
||||
$cron->deleteCron([['event', '=', 'CloseGroupbuy'], ['relate_id', '=', $groupbuy_id]]);
|
||||
}
|
||||
return $this->success($res);
|
||||
} else {
|
||||
return $this->error('', '团购活动进行中或已结束');
|
||||
}
|
||||
} else {
|
||||
return $this->error('', '团购活动不存在');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束团购活动
|
||||
* @param $groupbuy_id
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function finishGroupbuy($groupbuy_id, $site_id)
|
||||
{
|
||||
//团购信息
|
||||
$groupbuy_info = model('promotion_groupbuy')->getInfo([['groupbuy_id', '=', $groupbuy_id], ['site_id', '=', $site_id]], 'groupbuy_id,status,goods_id');
|
||||
if (!empty($groupbuy_info)) {
|
||||
$goods = new Goods();
|
||||
$goods->modifyPromotionAddon($groupbuy_info['goods_id'], ['groupbuy' => $groupbuy_id], true);
|
||||
if ($groupbuy_info['status'] != 3) {
|
||||
$res = model('promotion_groupbuy')->update(['status' => 3], [['groupbuy_id', '=', $groupbuy_id]]);
|
||||
if ($res) {
|
||||
$cron = new Cron();
|
||||
$cron->deleteCron([['event', '=', 'OpenGroupbuy'], ['relate_id', '=', $groupbuy_id]]);
|
||||
$cron->deleteCron([['event', '=', 'CloseGroupbuy'], ['relate_id', '=', $groupbuy_id]]);
|
||||
}
|
||||
return $this->success($res);
|
||||
} else {
|
||||
$this->error('', '该团购活动已结束');
|
||||
}
|
||||
} else {
|
||||
$this->error('', '该团购活动不存在');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取团购信息
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getGroupbuyInfo($condition = [], $field = 'pg.groupbuy_id,pg.site_id,pg.goods_id,pg.groupbuy_price,pg.buy_num,pg.create_time,pg.start_time,pg.end_time,pg.sell_num,pg.status,pg.rule,g.goods_name,g.goods_image,g.price,g.goods_stock')
|
||||
{
|
||||
$alias = 'pg';
|
||||
$join = [
|
||||
['goods g', 'g.goods_id = pg.goods_id', 'inner']
|
||||
];
|
||||
$groupbuy_info = model('promotion_groupbuy')->getInfo($condition, $field, $alias, $join);
|
||||
if (!empty($groupbuy_info)) {
|
||||
if (isset($groupbuy_info['goods_stock'])) {
|
||||
$groupbuy_info['goods_stock'] = numberFormat($groupbuy_info['goods_stock']);
|
||||
}
|
||||
}
|
||||
return $this->success($groupbuy_info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 团购商品详情
|
||||
* @param array $condition
|
||||
* @return array
|
||||
*/
|
||||
public function getGroupbuyGoodsDetail($condition = [])
|
||||
{
|
||||
$alias = 'pg';
|
||||
|
||||
$field = 'g.fenxiao_type,sku.fenxiao_price,g.is_fenxiao,pg.groupbuy_id,pg.groupbuy_price,pg.buy_num,pg.start_time,pg.end_time,pg.sell_num,pg.status,pg.rule,
|
||||
sku.sku_id,sku.site_id,sku.sku_name,sku.price,sku.sku_spec_format,
|
||||
sku.promotion_type,sku.stock,sku.click_num,(g.sale_num + g.virtual_sale) as sale_num,sku.collect_num,sku.sku_image,sku.sku_images,sku.goods_id,sku.site_id,sku.goods_content,
|
||||
sku.goods_state,sku.is_virtual,sku.is_free_shipping,sku.goods_spec_format,sku.goods_attr_format,sku.introduction,sku.unit,sku.video_url,g.evaluate,sku.goods_id,
|
||||
sku.goods_service_ids,sku.support_trade_type,g.goods_image,g.goods_stock,g.goods_name,sku.qr_id,g.stock_show,g.sale_show,g.label_name,g.category_id';
|
||||
$join = [
|
||||
['goods_sku sku', 'pg.goods_id = sku.goods_id', 'inner'],
|
||||
['goods g', 'g.goods_id = sku.goods_id', 'inner'],
|
||||
];
|
||||
|
||||
$goods_info = model('promotion_groupbuy')->getInfo($condition, $field, $alias, $join);
|
||||
if (!empty($goods_info)) {
|
||||
$goods_info['sale_num'] = numberFormat($goods_info['sale_num']);
|
||||
$goods_info['stock'] = numberFormat($goods_info['stock']);
|
||||
$goods_info['goods_stock'] = numberFormat($goods_info['goods_stock']);
|
||||
}
|
||||
return $this->success($goods_info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 团购商品
|
||||
* @param array $condition
|
||||
* @return array
|
||||
*/
|
||||
public function getGroupbuyGoodsSkuList($condition = [], $limit = null)
|
||||
{
|
||||
$alias = 'pg';
|
||||
|
||||
$field = 'pg.groupbuy_id,pg.groupbuy_price,pg.buy_num,pg.start_time,pg.end_time,pg.sell_num,pg.status,g.goods_id,g.goods_name,g.goods_stock,
|
||||
sku.sku_id,sku.sku_name,sku.price,sku.sku_spec_format,sku.stock,sku.sku_image,sku.sku_images,sku.goods_spec_format,g.goods_image';
|
||||
$join = [
|
||||
['goods_sku sku', 'pg.goods_id = sku.goods_id', 'inner'],
|
||||
['goods g', 'g.goods_id = sku.goods_id', 'inner'],
|
||||
];
|
||||
|
||||
$list = model('promotion_groupbuy')->getList($condition, $field, 'pg.groupbuy_id asc', $alias, $join, '', $limit);
|
||||
foreach ($list as $k => $v) {
|
||||
$list[$k]['stock'] = numberFormat($list[$k]['stock']);
|
||||
$list[$k]['goods_stock'] = numberFormat($list[$k]['goods_stock']);
|
||||
}
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取团购列表
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @param string $limit
|
||||
*/
|
||||
public function getGroupbuyList($condition = [], $field = '*', $order = '', $limit = null)
|
||||
{
|
||||
$list = model('promotion_groupbuy')->getList($condition, $field, $order, '', '', '', $limit);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取团购分页列表
|
||||
* @param array $condition
|
||||
* @param number $page
|
||||
* @param string $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
*/
|
||||
public function getGroupbuyPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '')
|
||||
{
|
||||
|
||||
$field = 'pg.groupbuy_id,pg.site_id,pg.goods_id,pg.groupbuy_price,pg.buy_num,pg.create_time,
|
||||
pg.start_time,pg.end_time,pg.sell_num,pg.status,
|
||||
g.goods_name,g.goods_image,g.price,g.goods_stock,g.recommend_way';
|
||||
$alias = 'pg';
|
||||
$join = [
|
||||
['goods g', 'g.goods_id = pg.goods_id', 'inner'],
|
||||
];
|
||||
$res = model('promotion_groupbuy')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
|
||||
foreach ($res['list'] as $k => $v) {
|
||||
$res['list'][$k]['goods_stock'] = numberFormat($res['list'][$k]['goods_stock']);
|
||||
}
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取团购商品分页列表
|
||||
* @param array $condition
|
||||
* @param number $page
|
||||
* @param string $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
*/
|
||||
public function getGroupbuyGoodsPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'pg.groupbuy_id desc', $field = '')
|
||||
{
|
||||
if (empty($field)) {
|
||||
$field = 'pg.groupbuy_id,pg.groupbuy_price,pg.sell_num,pg.site_id,pg.buy_num,
|
||||
sku.sku_id,sku.price,sku.sku_name,sku.sku_image,g.goods_id,g.goods_name,g.goods_image,g.goods_stock,g.recommend_way';
|
||||
}
|
||||
$alias = 'pg';
|
||||
$join = [
|
||||
['goods g', 'pg.goods_id = g.goods_id', 'inner'],
|
||||
['goods_sku sku', 'g.sku_id = sku.sku_id', 'inner']
|
||||
];
|
||||
$res = model('promotion_groupbuy')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
|
||||
foreach ($res['list'] as $k => $v) {
|
||||
if (isset($v['goods_stock'])) {
|
||||
$res['list'][$k]['goods_stock'] = numberFormat($res['list'][$k]['goods_stock']);
|
||||
}
|
||||
}
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取团购商品列表
|
||||
* @param array $condition
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
*/
|
||||
public function getGroupbuyGoodsList($condition = [], $field = '', $order = 'pg.groupbuy_id desc', $limit = null)
|
||||
{
|
||||
if (empty($field)) {
|
||||
$field = 'pg.groupbuy_id,pg.groupbuy_price,pg.sell_num,pg.site_id,pg.buy_num,
|
||||
sku.sku_id,sku.price,sku.sku_name,sku.sku_image,g.goods_id,g.goods_name,g.goods_image,g.goods_stock,g.recommend_way';
|
||||
}
|
||||
$alias = 'pg';
|
||||
$join = [
|
||||
['goods g', 'pg.goods_id = g.goods_id', 'inner'],
|
||||
['goods_sku sku', 'g.sku_id = sku.sku_id', 'inner']
|
||||
];
|
||||
$list = model('promotion_groupbuy')->getList($condition, $field, $order, $alias, $join, '', $limit);
|
||||
foreach ($list as $k => $v) {
|
||||
if (isset($v['goods_stock'])) {
|
||||
$list[$k]['goods_stock'] = numberFormat($list[$k]['goods_stock']);
|
||||
}
|
||||
}
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启团购活动
|
||||
* @param $groupbuy_id
|
||||
* @return array|\multitype
|
||||
*/
|
||||
public function cronOpenGroupbuy($groupbuy_id)
|
||||
{
|
||||
$groupbuy_info = model('promotion_groupbuy')->getInfo([['groupbuy_id', '=', $groupbuy_id]], 'start_time,status,goods_id');
|
||||
if (!empty($groupbuy_info)) {
|
||||
$goods = new Goods();
|
||||
$goods->modifyPromotionAddon($groupbuy_info['goods_id'], ['groupbuy' => $groupbuy_id]);
|
||||
if ($groupbuy_info['start_time'] <= time() && $groupbuy_info['status'] == 1) {
|
||||
$res = model('promotion_groupbuy')->update(['status' => 2], [['groupbuy_id', '=', $groupbuy_id]]);
|
||||
return $this->success($res);
|
||||
} else {
|
||||
return $this->error('', '团购活动已开启或者关闭');
|
||||
}
|
||||
} else {
|
||||
return $this->error('', '团购活动不存在');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭团购活动
|
||||
* @param $groupbuy_id
|
||||
* @return array|\multitype
|
||||
*/
|
||||
public function cronCloseGroupbuy($groupbuy_id)
|
||||
{
|
||||
$groupbuy_info = model('promotion_groupbuy')->getInfo([['groupbuy_id', '=', $groupbuy_id]], 'start_time,status,goods_id');
|
||||
if (!empty($groupbuy_info)) {
|
||||
$goods = new Goods();
|
||||
$goods->modifyPromotionAddon($groupbuy_info['goods_id'], ['groupbuy' => $groupbuy_id], true);
|
||||
if ($groupbuy_info['status'] != 3) {
|
||||
$res = model('promotion_groupbuy')->update(['status' => 3], [['groupbuy_id', '=', $groupbuy_id]]);
|
||||
return $this->success($res);
|
||||
} else {
|
||||
return $this->error('', '该活动已结束');
|
||||
}
|
||||
} else {
|
||||
return $this->error('', '团购活动不存在');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单支付
|
||||
* @param $param
|
||||
* @return mixed
|
||||
*/
|
||||
public function orderPay($param)
|
||||
{
|
||||
$order_goods = model('order_goods')->getInfo([['order_id', '=', $param['order_id']]], 'goods_id,num');
|
||||
if (!empty($order_goods)) {
|
||||
|
||||
//获取团购id
|
||||
$groupbuy_id = model('promotion_groupbuy')->getValue(
|
||||
[['goods_id', '=', $order_goods['goods_id']], ['status', '=', 2]],
|
||||
'groupbuy_id'
|
||||
);
|
||||
if ($groupbuy_id != 0) {
|
||||
//增加销售量
|
||||
model('promotion_groupbuy')->setInc([['groupbuy_id', '=', $groupbuy_id]], 'sell_num', $order_goods['num']);
|
||||
}
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成团购二维码
|
||||
* @param $groupbuy_id
|
||||
* @param string $app_type all为全部
|
||||
* @param string $type 类型 create创建 get获取
|
||||
* @return mixed|array
|
||||
*/
|
||||
public function qrcode($groupbuy_id, $name, $site_id, $type = 'create')
|
||||
{
|
||||
$data = [
|
||||
'site_id' => $site_id,
|
||||
'app_type' => 'all', // all为全部
|
||||
'type' => $type, // 类型 create创建 get获取
|
||||
'data' => [
|
||||
'groupbuy_id' => $groupbuy_id
|
||||
],
|
||||
'page' => '/pages_promotion/groupbuy/detail',
|
||||
'qrcode_path' => 'upload/qrcode/groupbuy',
|
||||
'qrcode_name' => 'groupbuy_qrcode_' . $groupbuy_id
|
||||
];
|
||||
|
||||
event('Qrcode', $data, true);
|
||||
$app_type_list = config('app_type');
|
||||
$path = [];
|
||||
foreach ($app_type_list as $k => $v) {
|
||||
switch ($k) {
|
||||
case 'h5':
|
||||
$wap_domain = getH5Domain();
|
||||
$path[$k]['status'] = 1;
|
||||
$path[$k]['url'] = $wap_domain . $data['page'] . '?id=' . $groupbuy_id;
|
||||
$path[$k]['img'] = 'upload/qrcode/groupbuy/groupbuy_qrcode_' . $groupbuy_id . '_' . $k . '.png';
|
||||
break;
|
||||
case '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'])) {
|
||||
$path[$k]['status'] = 2;
|
||||
$path[$k]['message'] = '未配置微信小程序';
|
||||
} else {
|
||||
$path[$k]['status'] = 1;
|
||||
$path[$k]['img'] = $res['data']['value']['qrcode'];
|
||||
}
|
||||
|
||||
} else {
|
||||
$path[$k]['status'] = 2;
|
||||
$path[$k]['message'] = '未配置微信小程序';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'wechat' :
|
||||
$config = new ConfigModel();
|
||||
$res = $config->getConfig([['site_id', '=', $site_id], ['app_module', '=', 'shop'], ['config_key', '=', 'WECHAT_CONFIG']]);
|
||||
if (!empty($res['data'])) {
|
||||
if (empty($res['data']['value']['qrcode'])) {
|
||||
$path[$k]['status'] = 2;
|
||||
$path[$k]['message'] = '未配置微信公众号';
|
||||
} else {
|
||||
$path[$k]['status'] = 1;
|
||||
$path[$k]['img'] = $res['data']['value']['qrcode'];
|
||||
}
|
||||
} else {
|
||||
$path[$k]['status'] = 2;
|
||||
$path[$k]['message'] = '未配置微信公众号';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$return = [
|
||||
'path' => $path,
|
||||
'name' => $name,
|
||||
];
|
||||
|
||||
return $this->success($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品用到的分类
|
||||
* @param $condition
|
||||
* @return array
|
||||
*/
|
||||
public function getGoodsCategoryIds($condition)
|
||||
{
|
||||
$cache_name = 'shop_groupbuy_goods_category_' . md5(json_encode($condition));
|
||||
$cache_time = 60;
|
||||
$cache_res = Cache::get($cache_name);
|
||||
if (empty($cache_res) || time() - $cache_res['time'] > $cache_time) {
|
||||
$list = Db::name('promotion_groupbuy')
|
||||
->alias('pg')
|
||||
->join('goods g', 'pg.goods_id = g.goods_id', 'inner')
|
||||
->where($condition)
|
||||
->group('g.category_id')
|
||||
->column('g.category_id');
|
||||
$category_ids = trim(join('0', $list), ',');
|
||||
$category_id_arr = array_unique(explode(',', $category_ids));
|
||||
Cache::set($cache_name, ['time' => time(), 'data' => $category_id_arr]);
|
||||
} else {
|
||||
$category_id_arr = $cache_res['data'];
|
||||
}
|
||||
return $this->success($category_id_arr);
|
||||
}
|
||||
|
||||
public function urlQrcode($page, $qrcode_param, $promotion_type, $app_type, $site_id)
|
||||
{
|
||||
$params = [
|
||||
'site_id' => $site_id,
|
||||
'data' => $qrcode_param,
|
||||
'page' => $page,
|
||||
'promotion_type' => $promotion_type,
|
||||
'app_type' => $app_type,
|
||||
'h5_path' => $page . '?id=' . $qrcode_param['id'],
|
||||
'qrcode_path' => 'upload/qrcode/groupbuy',
|
||||
'qrcode_name' => 'groupbuy_qrcode_' . $promotion_type . '_' . $qrcode_param['id'] . '_' . $site_id
|
||||
];
|
||||
|
||||
$solitaire = event('PromotionQrcode', $params, true);
|
||||
return $this->success($solitaire);
|
||||
}
|
||||
}
|
||||
248
addon/groupbuy/model/GroupbuyOrderCreate.php
Executable file
248
addon/groupbuy/model/GroupbuyOrderCreate.php
Executable file
@@ -0,0 +1,248 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\groupbuy\model;
|
||||
|
||||
use addon\store\model\StoreGoodsSku;
|
||||
use app\model\BaseModel;
|
||||
use app\model\order\OrderCreate;
|
||||
use app\model\order\OrderCreateTool;
|
||||
use app\model\store\Store;
|
||||
use extend\exception\OrderException;
|
||||
use think\facade\Cache;
|
||||
use app\model\express\Express;
|
||||
use app\model\system\Pay;
|
||||
use app\model\express\Config as ExpressConfig;
|
||||
use app\model\order\Config;
|
||||
use app\model\express\Local;
|
||||
|
||||
/**
|
||||
* 订单创建(团购)
|
||||
*/
|
||||
class GroupbuyOrderCreate extends BaseModel
|
||||
{
|
||||
|
||||
use OrderCreateTool;
|
||||
public $groupbuy_info = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->promotion_type = 'groupbuy';
|
||||
$this->promotion_type_name = '团购';
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单创建
|
||||
* @param unknown $data
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//计算
|
||||
$this->confirm();
|
||||
|
||||
if ($this->error > 0) {
|
||||
return $this->error([ 'error_code' => $this->error ], $this->error_msg);
|
||||
}
|
||||
model('order')->startTrans();
|
||||
//循环生成多个订单
|
||||
try {
|
||||
|
||||
$order_insert_data = $this->getOrderInsertData([ 'discount' ], 'invert');
|
||||
$order_insert_data[ 'store_id' ] = $this->store_id;
|
||||
$order_insert_data[ 'create_time' ] = time();
|
||||
$order_insert_data[ 'is_enable_refund' ] = 0;
|
||||
//订单类型以及状态
|
||||
$this->orderType();
|
||||
$order_insert_data[ 'order_type' ] = $this->order_type[ 'order_type_id' ];
|
||||
$order_insert_data[ 'order_type_name' ] = $this->order_type[ 'order_type_name' ];
|
||||
$order_insert_data[ 'order_status_name' ] = $this->order_type[ 'order_status' ][ 'name' ];
|
||||
$order_insert_data[ 'order_status_action' ] = json_encode($this->order_type[ 'order_status' ], JSON_UNESCAPED_UNICODE);
|
||||
$this->order_id = model('order')->add($order_insert_data);
|
||||
$order_goods_insert_data = [];
|
||||
//订单项目表
|
||||
foreach ($this->goods_list as $order_goods_v) {
|
||||
$order_goods_insert_data[] = $this->getOrderGoodsInsertData($order_goods_v);
|
||||
}
|
||||
model('order_goods')->addList($order_goods_insert_data);
|
||||
//使用余额
|
||||
$this->useBalance();
|
||||
//批量扣除库存
|
||||
$this->batchDecOrderGoodsStock();
|
||||
model('order')->commit();
|
||||
//订单创建后事件
|
||||
$this->orderCreateAfter();
|
||||
//生成整体支付单据
|
||||
$pay_model = new Pay();
|
||||
$pay_model->addPay($this->site_id, $this->out_trade_no, $this->pay_type, $this->order_name, $this->order_name, $this->pay_money, '', 'OrderPayNotify', '', $this->order_id, $this->member_id);
|
||||
return $this->success($this->out_trade_no);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
model('order')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单计算
|
||||
* @param unknown $data
|
||||
*/
|
||||
public function calculate()
|
||||
{
|
||||
$this->initMemberAddress();//初始化买家地址
|
||||
$this->initMemberAccount();//初始化会员账户
|
||||
//查询团购信息
|
||||
$groupbuy_model = new Groupbuy();
|
||||
$groupbuy_id = $this->param[ 'groupbuy_id' ];
|
||||
$this->groupbuy_info = $groupbuy_model->getGroupbuyInfo(
|
||||
[
|
||||
[ 'pg.groupbuy_id', '=', $groupbuy_id ],
|
||||
[ 'pg.site_id', '=', $this->site_id ],
|
||||
[ 'g.goods_state', '=', 1 ],
|
||||
[ 'g.is_delete', '=', 0 ]
|
||||
]
|
||||
)[ 'data' ] ?? [];
|
||||
if (!$this->groupbuy_info) throw new OrderException('该团购不存在');
|
||||
//商品列表信息
|
||||
$this->getOrderGoodsCalculate();
|
||||
//判断活动是否过期或开启
|
||||
if ($this->groupbuy_info[ 'status' ] != 2) {
|
||||
$this->error = 1;
|
||||
$this->error_msg = '当前商品团购活动未开启或已过期!';
|
||||
}
|
||||
//判断购买数是否超过限购
|
||||
if ($this->groupbuy_info[ 'buy_num' ] > $this->param[ 'num' ]) {
|
||||
$this->error = 1;
|
||||
$this->error_msg = '该商品限制购买不能少于' . $this->groupbuy_info[ 'buy_num' ] . '件!';
|
||||
}
|
||||
//计算
|
||||
$this->shopOrderCalculate();
|
||||
|
||||
//获取发票相关
|
||||
$this->getInovice();
|
||||
|
||||
$this->order_key = create_no();
|
||||
$this->setOrderCache(get_object_vars($this), $this->order_key);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 待付款订单
|
||||
* @param unknown $data
|
||||
*/
|
||||
public function orderPayment()
|
||||
{
|
||||
//计算
|
||||
$this->calculate();
|
||||
//查询配送信息
|
||||
$this->getDeliveryData();
|
||||
//订单初始项
|
||||
event('OrderPayment', [ 'order_object' => $this ]);
|
||||
return get_object_vars($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算后的进一步计算(不存缓存,每次都是重新计算)
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品的计算信息
|
||||
* @param unknown $data
|
||||
*/
|
||||
public function getOrderGoodsCalculate()
|
||||
{
|
||||
$this->getGroupbuyGoodsInfo();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取团购商品列表信息
|
||||
* @param unknown $bl_id
|
||||
*/
|
||||
public function getGroupbuyGoodsInfo()
|
||||
{
|
||||
//组装商品列表
|
||||
$field = 'ngs.sku_id,ngs.sku_name, ngs.sku_no,ngs.price, ngs.discount_price, ngs.cost_price, ngs.stock, ngs.weight, ngs.volume, ngs.sku_image, ngs.site_id, ngs.goods_state, ngs.is_virtual,ngs.supplier_id,ngs.form_id,
|
||||
ngs.is_free_shipping, ngs.shipping_template, ngs.goods_class, ngs.goods_class_name,ngs.goods_id, ns.site_name,ngs.sku_spec_format,ngs.goods_name,g.goods_image,ngs.support_trade_type';
|
||||
$join = [
|
||||
[
|
||||
'site ns',
|
||||
'ngs.site_id = ns.site_id',
|
||||
'inner'
|
||||
],
|
||||
[ 'goods g', 'ngs.goods_id = g.goods_id', 'inner' ],
|
||||
];
|
||||
$info = model('goods_sku')->getInfo([ [ 'ngs.sku_id', '=', $this->param[ 'sku_id' ] ], [ 'ngs.site_id', '=', $this->site_id ] ], $field, 'ngs', $join);
|
||||
if (!empty($info)) {
|
||||
//判断是否是虚拟订单
|
||||
if ($info[ 'is_virtual' ]) {
|
||||
$this->is_virtual = 1;
|
||||
} else {
|
||||
$this->is_virtual = 0;
|
||||
}
|
||||
$info[ 'num' ] = $this->param[ 'num' ];
|
||||
$price = $this->groupbuy_info[ 'groupbuy_price' ];
|
||||
$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;//优惠金额
|
||||
$info[ 'stock' ] = numberFormat($info[ 'stock' ]);
|
||||
$this->goods_list[] = $info;
|
||||
|
||||
$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' ];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺订单计算
|
||||
*/
|
||||
public function shopOrderCalculate()
|
||||
{
|
||||
//重新计算订单总额
|
||||
$this->getOrderMoney();
|
||||
//理论上是多余的操作
|
||||
if ($this->order_money < 0) {
|
||||
$this->order_money = 0;
|
||||
}
|
||||
//总结计算
|
||||
$this->pay_money = $this->order_money;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
464
addon/groupbuy/model/Poster.php
Executable file
464
addon/groupbuy/model/Poster.php
Executable file
@@ -0,0 +1,464 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\groupbuy\model;
|
||||
|
||||
use addon\postertemplate\model\PosterTemplate as PosterTemplateModel;
|
||||
use app\model\BaseModel;
|
||||
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)
|
||||
{
|
||||
try {
|
||||
$goods_info = $this->getGoodsInfo($qrcode_param['id']);
|
||||
$img_arr = explode(",", $goods_info['goods_image']);
|
||||
|
||||
if (empty($goods_info)) return $this->error('未获取到商品信息');
|
||||
//判断海报是否存在或停用
|
||||
$template_info = $this->getTemplateInfo($goods_info['template_id']);
|
||||
$qrcode_info = $this->getGoodsQrcode($app_type, $page, $qrcode_param, $promotion_type, $site_id);
|
||||
if ($qrcode_info['code'] < 0) return $qrcode_info;
|
||||
|
||||
$site_model = new Site();
|
||||
$condition = array (
|
||||
[ "site_id", "=", $site_id ]
|
||||
);
|
||||
$site_info = $site_model->getSiteInfo($condition);
|
||||
|
||||
if (!empty($qrcode_param['source_member'])) {
|
||||
$member_info = $this->getMemberInfo($qrcode_param['source_member']);
|
||||
}
|
||||
|
||||
if(empty($goods_info['template_id']) || empty($template_info) || $template_info['template_status']==0){
|
||||
$poster_width = 720;
|
||||
$poster_height = 1150;
|
||||
|
||||
$poster = new PosterExtend($poster_width, $poster_height);
|
||||
|
||||
$option = [
|
||||
[
|
||||
'action' => 'setBackground', // 设背景色
|
||||
'data' => [255, 255, 255]
|
||||
],
|
||||
[
|
||||
'action' => 'imageCopy', // 写入商品图
|
||||
'data' => [
|
||||
$img_arr[0],
|
||||
50,
|
||||
165,
|
||||
620,
|
||||
620,
|
||||
'square',
|
||||
true,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入商品名称
|
||||
'data' => [
|
||||
$goods_info['goods_name'],
|
||||
22,
|
||||
[35, 35, 35],
|
||||
50,
|
||||
915,
|
||||
360,
|
||||
2,
|
||||
true,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageCopy', // 写入商品二维码
|
||||
'data' => [
|
||||
$qrcode_info['data']['path'],
|
||||
435,
|
||||
825,
|
||||
240,
|
||||
240,
|
||||
'square',
|
||||
0,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入提示
|
||||
'data' => [
|
||||
'长按识别二维码',
|
||||
19,
|
||||
[102, 102, 102],
|
||||
465,
|
||||
1110,
|
||||
490,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入商品价格单位
|
||||
'data' => [
|
||||
'团购价:¥',
|
||||
22,
|
||||
[255, 0, 0],
|
||||
50,
|
||||
860,
|
||||
490,
|
||||
2,
|
||||
true,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入商品价格
|
||||
'data' => [
|
||||
$goods_info['groupbuy_price'],
|
||||
30,
|
||||
[255, 0, 0],
|
||||
188,
|
||||
862,
|
||||
490,
|
||||
2,
|
||||
true,
|
||||
1
|
||||
]
|
||||
],
|
||||
];
|
||||
if (isset($member_info) && !empty($member_info)) {
|
||||
$member_option = [
|
||||
[
|
||||
'action' => 'imageCircularCopy', // 写入用户头像
|
||||
'data' => [
|
||||
!empty($member_info['headimg']) ? $member_info['headimg'] : 'public/static/img/default_img/head.png',
|
||||
50,
|
||||
30,
|
||||
100,
|
||||
100
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入分享人昵称
|
||||
'data' => [
|
||||
$member_info['nickname'],
|
||||
22,
|
||||
[10, 10, 10],
|
||||
170,
|
||||
80,
|
||||
580,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入分享人昵称
|
||||
'data' => [
|
||||
'分享给你一个商品',
|
||||
18,
|
||||
[102, 102, 102],
|
||||
170,
|
||||
115,
|
||||
580,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
]
|
||||
]
|
||||
];
|
||||
$option = array_merge($option, $member_option);
|
||||
}
|
||||
}else{
|
||||
$condition = [
|
||||
['template_id', '=', $goods_info['template_id']],
|
||||
['site_id', '=', $site_id]
|
||||
];
|
||||
$poster_template_model = new PosterTemplateModel();
|
||||
$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]
|
||||
];
|
||||
}
|
||||
$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,
|
||||
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',
|
||||
true,
|
||||
$poster_data['data']['template_json']['store_logo_is_show']
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageCopy', // 写入商品图
|
||||
'data' => [
|
||||
$img_arr[0],
|
||||
$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_info['goods_name'],
|
||||
$poster_data['data']['template_json']['goods_name_font_size']*$fontRate,
|
||||
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_market_price_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_info['groupbuy_price'],
|
||||
$poster_data['data']['template_json']['goods_price_font_size']*$fontRate,
|
||||
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_market_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,
|
||||
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'] : 'public/static/img/default_img/head.png',
|
||||
$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,
|
||||
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']
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
$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 . '_' . $qrcode_param['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 $sku_id
|
||||
*/
|
||||
private function getGoodsInfo($groupbuy_id)
|
||||
{
|
||||
$field = 'pg.*,g.goods_name,g.goods_image,g.template_id,g.price';
|
||||
$alias = 'pg';
|
||||
$join = [
|
||||
['goods g','g.goods_id = pg.goods_id','inner']
|
||||
];
|
||||
$condition = [
|
||||
['pg.groupbuy_id','=',$groupbuy_id],['g.goods_state','=',1],['g.is_delete','=',0]
|
||||
];
|
||||
$info = model('promotion_groupbuy')->getInfo($condition,$field,$alias,$join);
|
||||
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;
|
||||
}
|
||||
}
|
||||
133
addon/groupbuy/model/share/WchatShare.php
Executable file
133
addon/groupbuy/model/share/WchatShare.php
Executable file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\groupbuy\model\share;
|
||||
|
||||
use addon\groupbuy\model\Groupbuy;
|
||||
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_GROUPBUY_LIST_PROMOTE',
|
||||
'path' => [ '/pages_promotion/groupbuy/list' ],
|
||||
'method_prefix' => 'goodsList',
|
||||
],
|
||||
[
|
||||
'title' => '团购详情',
|
||||
'config_key' => 'WCHAT_SHARE_CONFIG_GROUPBUY_PROMOTE',
|
||||
'path' => [ '/pages_promotion/groupbuy/detail' ],
|
||||
'method_prefix' => 'goodsDetail',
|
||||
],
|
||||
];
|
||||
|
||||
protected $sort = 4;
|
||||
|
||||
/**
|
||||
* 团购列表
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function goodsListShareData($param)
|
||||
{
|
||||
//跳转路径
|
||||
$link = $this->getShareLink($param);
|
||||
$config_data = $this->goodsListShareConfig($param)[ 'value' ];
|
||||
|
||||
$data = [
|
||||
'link' => $link,
|
||||
'desc' => $config_data[ 'desc' ],
|
||||
'imgUrl' => $config_data[ 'imgUrl' ],
|
||||
'title' => $config_data[ 'title' ]
|
||||
];
|
||||
return [
|
||||
'permission' => [
|
||||
'hideOptionMenu' => false,
|
||||
'hideMenuItems' => [],
|
||||
],
|
||||
'data' => $data,//分享内容
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 团购列表分享配置
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function goodsListShareConfig($param)
|
||||
{
|
||||
$site_id = $param[ 'site_id' ];
|
||||
$config = $param[ 'config' ];
|
||||
|
||||
$config_model = new ConfigModel();
|
||||
$data = $config_model->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', $config[ 'config_key' ] ] ])[ 'data' ];
|
||||
if (empty($data[ 'value' ])) {
|
||||
$data[ 'value' ] = [
|
||||
'title' => "团购列表",
|
||||
'desc' => "团购实惠更多",
|
||||
'imgUrl' => ''
|
||||
];
|
||||
}
|
||||
if (empty($data[ 'value' ][ 'imgUrl' ])) {
|
||||
$data[ 'value' ][ 'imgUrl' ] = img('addon/groupbuy/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[ 'groupbuy_id' ]) || isset($query[ 'id' ])) {
|
||||
$groupbuy_id = $query['id'] ?? $query['groupbuy_id'];
|
||||
$goods = new Groupbuy();
|
||||
$sku_info = $goods->getGroupbuyInfo([ [ 'groupbuy_id', '=', $groupbuy_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[ 'goods_name' ], $config_data[ 'value' ][ 'title' ]);
|
||||
$desc = str_replace('{price}', $sku_info[ 'groupbuy_price' ], $config_data[ 'value' ][ 'desc' ]);
|
||||
$link = $this->getShareLink($param);
|
||||
$image_url = $sku_info[ 'goods_image' ];
|
||||
|
||||
$data = [
|
||||
'title' => $title,
|
||||
'desc' => $desc,
|
||||
'link' => $link,
|
||||
'imgUrl' => $image_url,
|
||||
];
|
||||
return [
|
||||
'permission' => [
|
||||
'hideOptionMenu' => false,
|
||||
'hideMenuItems' => [],
|
||||
],
|
||||
'data' => $data,//分享内容
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
89
addon/groupbuy/model/share/WeappShare.php
Executable file
89
addon/groupbuy/model/share/WeappShare.php
Executable file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\groupbuy\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_GROUPBUY_LIST',
|
||||
'path' => [ '/pages_promotion/groupbuy/list' ],
|
||||
'method_prefix' => 'groupbuyList',
|
||||
],
|
||||
];
|
||||
|
||||
protected $sort = 5;
|
||||
|
||||
/**
|
||||
* 团购专区列表
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function groupbuyListShareData($param)
|
||||
{
|
||||
//获取和替换配置数据
|
||||
$config_data = $this->groupbuyListShareConfig($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 groupbuyListShareConfig($param)
|
||||
{
|
||||
$site_id = $param[ 'site_id' ];
|
||||
$config = $param[ 'config' ];
|
||||
|
||||
$config_model = new ConfigModel();
|
||||
$data = $config_model->getConfig([
|
||||
[ 'site_id', '=', $site_id ],
|
||||
[ 'app_module', '=', 'shop' ],
|
||||
[ 'config_key', '=', $config[ 'config_key' ] ],
|
||||
])[ 'data' ];
|
||||
if (empty($data[ 'value' ])) {
|
||||
$data[ 'value' ] = [
|
||||
'title' => '跟我一起来团购吧!',
|
||||
'imageUrl' => '',
|
||||
];
|
||||
}
|
||||
$variable = [];
|
||||
|
||||
return [
|
||||
'value' => $data[ 'value' ],
|
||||
'variable' => $variable,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user