初始上传
This commit is contained in:
1352
addon/bargain/model/Bargain.php
Executable file
1352
addon/bargain/model/Bargain.php
Executable file
File diff suppressed because it is too large
Load Diff
265
addon/bargain/model/BargainOrderCreate.php
Executable file
265
addon/bargain/model/BargainOrderCreate.php
Executable file
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\bargain\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use app\model\order\OrderCommon;
|
||||
use app\model\order\OrderCreateTool;
|
||||
use app\model\system\Pay;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 订单创建(砍价)
|
||||
*/
|
||||
class BargainOrderCreate extends BaseModel
|
||||
{
|
||||
|
||||
use OrderCreateTool;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->promotion_type = 'bargain';
|
||||
$this->promotion_type_name = '砍价';
|
||||
}
|
||||
|
||||
public $bargain_info = [];
|
||||
|
||||
/**
|
||||
* 订单创建
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$this->confirm();
|
||||
//校验错误
|
||||
$error_result = $this->checkError();
|
||||
if ($error_result !== true) {
|
||||
return $error_result;
|
||||
}
|
||||
$bargain_model = new Bargain();
|
||||
$pay = new Pay();
|
||||
$is_fenxiao = $this->bargain_info[ 'is_fenxiao' ];
|
||||
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);
|
||||
$order_insert_data[ 'is_fenxiao' ] = $is_fenxiao;
|
||||
|
||||
$this->order_id = model('order')->add($order_insert_data);
|
||||
//订单项目表
|
||||
$order_goods_insert_data = [];
|
||||
foreach ($this->goods_list as $order_goods_v) {
|
||||
$order_goods_v[ 'is_fenxiao' ] = $is_fenxiao;
|
||||
$order_goods_insert_data[] = $this->getOrderGoodsInsertData($order_goods_v);
|
||||
}
|
||||
model('order_goods')->addList($order_goods_insert_data);
|
||||
|
||||
//扣除余额(统一扣除)
|
||||
$this->useBalance();
|
||||
|
||||
// 砍价绑定订单id
|
||||
$bargain_data = [ 'order_id' => $this->order_id ];
|
||||
$bargain_data[ 'status' ] = 2;
|
||||
//未砍到低价都为砍价失败
|
||||
if ($this->bargain_info[ 'curr_price' ] == $this->bargain_info[ 'floor_price' ]) {
|
||||
$bargain_data[ 'status' ] = 1;
|
||||
}
|
||||
model('promotion_bargain_launch')->update($bargain_data, [ [ 'launch_id', '=', $this->bargain_info[ 'launch_id' ] ] ]);
|
||||
|
||||
//批量库存处理(卡密商品支付后在扣出库存)
|
||||
$this->batchDecOrderGoodsStock();
|
||||
|
||||
//扣除商品库存
|
||||
foreach ($this->goods_list as $v) {
|
||||
//活动库存
|
||||
$bargain_stock_result = $bargain_model->decStock([ 'bargain_id' => $this->bargain_info[ 'bargain_id' ], 'sku_id' => $v[ 'sku_id' ], 'num' => $v[ 'num' ] ]);
|
||||
if ($bargain_stock_result[ 'code' ] < 0) {
|
||||
model('order')->rollback();
|
||||
return $bargain_stock_result;
|
||||
}
|
||||
}
|
||||
model('order')->commit();
|
||||
//订单创建后事件
|
||||
$this->orderCreateAfter();
|
||||
//生成整体支付单据
|
||||
$pay->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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单计算
|
||||
*/
|
||||
public function calculate()
|
||||
{
|
||||
$this->initMemberAddress(); //初始化地址
|
||||
$this->initMemberAccount(); //初始化会员账户
|
||||
//商品列表信息
|
||||
$this->getOrderGoodsCalculate();
|
||||
//优惠以及附属计算
|
||||
$this->shopOrderCalculate();
|
||||
//获取发票相关
|
||||
$this->getInovice();
|
||||
//定义缓存,并返回key值
|
||||
$this->order_key = create_no();
|
||||
$this->setOrderCache(get_object_vars($this), $this->order_key);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品的计算信息
|
||||
* @return true
|
||||
*/
|
||||
public function getOrderGoodsCalculate()
|
||||
{
|
||||
//查询砍价信息
|
||||
$bargain_model = new Bargain();
|
||||
$launch_id = $this->param[ 'id' ];
|
||||
$this->bargain_info = $bargain_model->getBargainLaunchDetail([ [ 'launch_id', '=', $launch_id ], [ 'site_id', '=', $this->site_id ] ])[ 'data' ] ?? [];
|
||||
if (empty($this->bargain_info)) throw new Exception('找不到您的砍价记录');
|
||||
//判断砍价是否成功
|
||||
if ($this->bargain_info[ 'buy_type' ] == 1 && $this->bargain_info[ 'status' ] != 1) {
|
||||
$this->error = 1;
|
||||
$this->error_msg = '该商品您尚未砍价成功!';
|
||||
}
|
||||
//判断砍价是否已经下单了
|
||||
$bargain_order_id = $this->bargain_info[ 'order_id' ] ?? 0;
|
||||
if (!$bargain_order_id) {
|
||||
$bargain_order_info = model('order')->getInfo([ [ 'order_id', '=', $bargain_order_id ] ], 'order_status');
|
||||
if ($bargain_order_info && $bargain_order_info[ 'order_status' ] != OrderCommon::ORDER_CLOSE) {
|
||||
$this->error = 1;
|
||||
$this->error_msg = '本次砍价您已下单过了!';
|
||||
}
|
||||
}
|
||||
|
||||
$this->getBargainGoodsInfo();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取砍价商品列表信息
|
||||
* @return true
|
||||
*/
|
||||
public function getBargainGoodsInfo()
|
||||
{
|
||||
//组装商品列表
|
||||
$field = 'sku_id,sku_name, sku_no,
|
||||
price, discount_price, cost_price, stock, weight, volume, sku_image,
|
||||
ngs.site_id, goods_state, is_virtual, support_trade_type,ngs.supplier_id,ngs.form_id,
|
||||
is_free_shipping, shipping_template, goods_class, goods_class_name,goods_id, ns.site_name,ngs.sku_spec_format,ngs.goods_name';
|
||||
$join = [
|
||||
[
|
||||
'site ns',
|
||||
'ngs.site_id = ns.site_id',
|
||||
'inner'
|
||||
]
|
||||
];
|
||||
$info = model('goods_sku')->getInfo([ [ 'ngs.sku_id', '=', $this->bargain_info[ 'sku_id' ] ], [ 'ngs.site_id', '=', $this->site_id ] ], $field, 'ngs', $join);
|
||||
if (!empty($info)) {
|
||||
$num = $this->param[ 'num' ];
|
||||
//判断是否是虚拟订单
|
||||
if ($info[ 'is_virtual' ]) {
|
||||
$this->is_virtual = 1;
|
||||
} else {
|
||||
$this->is_virtual = 0;
|
||||
}
|
||||
$info[ 'num' ] = $num;
|
||||
$price = $this->bargain_info[ 'curr_price' ];
|
||||
$goods_money = $price * $num;
|
||||
$info[ 'price' ] = $price;
|
||||
$info[ 'goods_money' ] = $goods_money;
|
||||
$info[ 'real_goods_money' ] = $goods_money;//真实商品金额
|
||||
$info[ 'coupon_money' ] = 0;//优惠券金额
|
||||
$info[ 'promotion_money' ] = 0;//优惠金额
|
||||
|
||||
$this->site_name = $info[ 'site_name' ];
|
||||
$this->goods_money = $goods_money;
|
||||
$this->goods_list_str = $info[ 'sku_id' ] . ':' . $info[ 'num' ];
|
||||
$this->order_name = string_split('', ',', $info[ 'sku_name' ]);
|
||||
$this->goods_num = $info[ 'num' ];
|
||||
$this->goods_list[] = $info;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺订单计算
|
||||
*/
|
||||
public function shopOrderCalculate()
|
||||
{
|
||||
//重新计算订单总额
|
||||
$this->getOrderMoney();
|
||||
//理论上是多余的操作
|
||||
if ($this->order_money < 0) {
|
||||
$this->order_money = 0;
|
||||
}
|
||||
//总结计算
|
||||
$this->pay_money = $this->order_money;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 待付款订单
|
||||
*/
|
||||
public function orderPayment()
|
||||
{
|
||||
//计算
|
||||
$this->calculate();
|
||||
//配送信息数据
|
||||
$this->getDeliveryData();
|
||||
//订单初始项
|
||||
event('OrderPayment', [ 'order_object' => $this ]);
|
||||
|
||||
return get_object_vars($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 抵扣优惠项计算
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
603
addon/bargain/model/Poster.php
Executable file
603
addon/bargain/model/Poster.php
Executable file
@@ -0,0 +1,603 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\bargain\model;
|
||||
|
||||
use addon\postertemplate\model\PosterTemplate as PosterTemplateModel;
|
||||
use app\model\BaseModel;
|
||||
use app\model\system\Site;
|
||||
use app\model\upload\Upload;
|
||||
use app\model\web\Config;
|
||||
use extend\Poster as PosterExtend;
|
||||
|
||||
/**
|
||||
* 海报生成类
|
||||
*/
|
||||
class Poster extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 商品海报
|
||||
*/
|
||||
public function goods($app_type, $page, $qrcode_param, $promotion_type, $site_id)
|
||||
{
|
||||
try {
|
||||
if ($page == '/pages_promotion/bargain/detail') {
|
||||
$goods_info = $this->getGoodsInfo($qrcode_param[ 'bargain_id' ]);
|
||||
unset($qrcode_param[ 'bargain_id' ]);
|
||||
} else {
|
||||
$goods_info = $this->getGoodsInfo($qrcode_param[ 'id' ]);
|
||||
}
|
||||
if (empty($goods_info)) return $this->error('未获取到商品信息');
|
||||
|
||||
$qrcode_info = $this->getGoodsQrcode($app_type, $page, $qrcode_param, $promotion_type, $site_id);
|
||||
if ($qrcode_info[ 'code' ] < 0) return $qrcode_info;
|
||||
|
||||
//判断海报是否存在或停用
|
||||
$template_info = $this->getTemplateInfo($goods_info[ 'template_id' ]);
|
||||
|
||||
$site_model = new Site();
|
||||
$condition = array (
|
||||
["site_id", "=", $site_id]
|
||||
);
|
||||
$site_info = $site_model->getSiteInfo($condition);
|
||||
|
||||
$member_info = [];
|
||||
if (!empty($qrcode_param[ 'source_member' ])) {
|
||||
$member_info = $this->getMemberInfo($qrcode_param[ 'source_member' ]);
|
||||
}
|
||||
|
||||
$upload_config_model = new Config();
|
||||
$upload_config_result = $upload_config_model->getDefaultImg($site_id);
|
||||
|
||||
if (empty($goods_info[ 'template_id' ]) || empty($template_info) || $template_info[ 'template_status' ] == 0) {
|
||||
$poster_width = 720;
|
||||
$poster_height = 1280;
|
||||
$poster = new PosterExtend($poster_width, $poster_height);
|
||||
$option = [
|
||||
[
|
||||
'action' => 'imageCopy', // 背景图
|
||||
'data' => [
|
||||
img('upload/poster/bg/promotion_bargain.png'),
|
||||
0,
|
||||
0,
|
||||
720,
|
||||
1280,
|
||||
'square',
|
||||
0,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageCopy', // 商品图
|
||||
'data' => [
|
||||
$goods_info[ 'sku_image' ],
|
||||
86,
|
||||
174,
|
||||
548,
|
||||
548,
|
||||
'square',
|
||||
5,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageCopy', // 二维码
|
||||
'data' => [
|
||||
$qrcode_info[ 'data' ][ 'path' ],
|
||||
273,
|
||||
916,
|
||||
175,
|
||||
175,
|
||||
'square',
|
||||
0,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入商品价格
|
||||
'data' => [
|
||||
'原价 ¥ ' . $goods_info[ 'price' ] . ' 最低可砍至 ¥ ' . $goods_info[ 'floor_price' ],
|
||||
18,
|
||||
[51, 51, 51],
|
||||
86,
|
||||
828,
|
||||
548,
|
||||
1,
|
||||
false,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入商品名称
|
||||
'data' => [
|
||||
$goods_info[ 'sku_name' ],
|
||||
25,
|
||||
[34, 34, 34],
|
||||
86,
|
||||
780,
|
||||
548,
|
||||
1,
|
||||
true,
|
||||
1
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
if (!empty($member_info)) {
|
||||
$member_option = [
|
||||
[
|
||||
'action' => 'imageCircularCopy', // 写入用户头像
|
||||
'data' => [
|
||||
!empty($member_info[ 'headimg' ]) ? $member_info[ 'headimg' ] : $upload_config_result[ 'data' ][ 'value' ][ 'head' ],
|
||||
86,
|
||||
40,
|
||||
101,
|
||||
101
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入分享人昵称
|
||||
'data' => [
|
||||
$member_info[ 'nickname' ],
|
||||
24,
|
||||
[51, 51, 51],
|
||||
210,
|
||||
85,
|
||||
420,
|
||||
1,
|
||||
0,
|
||||
1
|
||||
]
|
||||
]
|
||||
];
|
||||
$option = array_merge($option, $member_option);
|
||||
}
|
||||
} else {
|
||||
$condition = [
|
||||
['template_id', '=', $goods_info[ 'template_id' ]],
|
||||
['site_id', '=', $site_id]
|
||||
];
|
||||
$poster_template_model = new 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',
|
||||
true,
|
||||
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 * 2,
|
||||
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'store_name_color' ]),
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'store_name_left' ] * 2,
|
||||
($poster_data[ 'data' ][ 'template_json' ][ 'store_name_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'store_name_font_size' ]) * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'store_name_width' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'store_name_height' ] * 2,
|
||||
true,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'store_name_is_show' ]
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageCopy', // 店铺logo
|
||||
'data' => [
|
||||
!empty($site_info[ 'data' ][ 'logo_square' ]) ? $site_info[ 'data' ][ 'logo_square' ] : getUrl() . '/app/shop/view/public/img/shop_logo.png',
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_left' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_top' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_width' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_height' ] * 2,
|
||||
'square',
|
||||
true,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'store_logo_is_show' ]
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageCopy', // 写入商品图
|
||||
'data' => [
|
||||
img($goods_info[ 'sku_image' ], 'mid'),
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_left' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_top' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_width' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_height' ] * 2,
|
||||
!empty($poster_data[ 'data' ][ 'template_json' ][ 'goods_img_shape' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_shape' ] : 'square',
|
||||
0,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_img_is_show' ]
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入商品名称
|
||||
'data' => [
|
||||
$goods_info[ 'sku_name' ],
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_name_font_size' ] * $fontRate * 2,
|
||||
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_name_color' ]),
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_name_left' ] * 2,
|
||||
($poster_data[ 'data' ][ 'template_json' ][ 'goods_name_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_font_size' ]) * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_name_width' ] * 2,
|
||||
1,//文本行数 $poster_data['data']['template_json']['goods_name_height']*2,
|
||||
true,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_name_is_show' ]
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageCopy', // 写入商品二维码
|
||||
'data' => [
|
||||
$qrcode_info[ 'data' ][ 'path' ],
|
||||
$poster_data[ 'data' ][ 'qrcode_left' ] * 2,
|
||||
$poster_data[ 'data' ][ 'qrcode_top' ] * 2,
|
||||
$poster_data[ 'data' ][ 'qrcode_width' ] * 2,
|
||||
$poster_data[ 'data' ][ 'qrcode_height' ] * 2,
|
||||
'square',
|
||||
0,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入商品价格
|
||||
'data' => [
|
||||
'¥' . $goods_info[ 'floor_price' ],
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_font_size' ] * $fontRate * 2,
|
||||
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_price_color' ]),
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_left' ] * 2,
|
||||
($poster_data[ 'data' ][ 'template_json' ][ 'goods_price_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_font_size' ]) * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_width' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_height' ] * 2,
|
||||
true,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_price_is_show' ]
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
if ($goods_info[ 'price' ] == 0) {
|
||||
$line = '一一一';
|
||||
} else {
|
||||
$line = '一一一一';
|
||||
}
|
||||
$market_price = [
|
||||
[
|
||||
'action' => 'imageText', // 写入商品划线价格
|
||||
'data' => [
|
||||
'¥' . $goods_info[ 'price' ],
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] * $fontRate * 2,
|
||||
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_color' ]),
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_left' ] * 2,
|
||||
($poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ]) * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_width' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_height' ] * 2,
|
||||
true,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_is_show' ] ?? 0
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入线
|
||||
'data' => [
|
||||
$line,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] * $fontRate * 2,
|
||||
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_color' ]),
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_left' ] * 2 - 5,
|
||||
($poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ]) * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_width' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_height' ] * 2,
|
||||
true,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_is_show' ]
|
||||
]
|
||||
],
|
||||
];
|
||||
$option = array_merge($option, $market_price);
|
||||
|
||||
if (!empty($member_info)) {
|
||||
$member_option = [
|
||||
[
|
||||
'action' => 'imageCopy', // 写入用户头像
|
||||
'data' => [
|
||||
!empty($member_info[ 'headimg' ]) ? $member_info[ 'headimg' ] : $upload_config_result[ 'data' ][ 'value' ][ 'head' ],
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_left' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_top' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_width' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_height' ] * 2,
|
||||
!empty($poster_data[ 'data' ][ 'template_json' ][ 'headimg_shape' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'headimg_shape' ] : 'square',
|
||||
0,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'headimg_is_show' ]
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入分享人昵称
|
||||
'data' => [
|
||||
$member_info[ 'nickname' ],
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_font_size' ] * $fontRate * 2,
|
||||
hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'nickname_color' ]),
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_left' ] * 2,
|
||||
($poster_data[ 'data' ][ 'template_json' ][ 'nickname_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'nickname_font_size' ]) * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_width' ] * 2,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_height' ] * 2,
|
||||
0,
|
||||
$poster_data[ 'data' ][ 'template_json' ][ 'nickname_is_show' ]
|
||||
]
|
||||
],
|
||||
];
|
||||
$option = array_merge($ground, $option, $member_option);
|
||||
}
|
||||
}
|
||||
|
||||
$option_res = $poster->create($option);
|
||||
if (is_array($option_res)) return $option_res;
|
||||
|
||||
$res = $option_res->jpeg('upload/poster/goods', 'goods_' . $promotion_type . '_' . $goods_info[ 'bargain_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)
|
||||
{
|
||||
return model('member')->getInfo(['member_id' => $member_id], 'nickname,headimg');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品信息
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
private function getGoodsInfo($id)
|
||||
{
|
||||
$join = [
|
||||
['goods_sku sku', 'pbg.sku_id = sku.sku_id', 'inner'],
|
||||
];
|
||||
$field = 'pbg.bargain_id,pbg.floor_price,sku.sku_name,sku.sku_id,sku.sku_image,sku.template_id,sku.price';
|
||||
return model('promotion_bargain_goods')->getInfo(['pbg.bargain_id' => $id], $field, 'pbg', $join);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品二维码
|
||||
* @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)
|
||||
{
|
||||
return 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[ 'l_id' ] . '_' . $qrcode_param[ 'source_member' ] . '_' . $site_id,
|
||||
], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取海报信息
|
||||
* @param unknown $template_id
|
||||
*/
|
||||
private function getTemplateInfo($template_id)
|
||||
{
|
||||
return model('poster_template')->getInfo(['template_id' => $template_id], 'template_id,template_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* 分享图片
|
||||
* @param $page
|
||||
* @param $qrcode_param
|
||||
* @param $site_id
|
||||
* @return array|\extend\multitype|PosterExtend|string|string[]
|
||||
*/
|
||||
public function shareImg($page, $qrcode_param, $site_id)
|
||||
{
|
||||
try {
|
||||
if ($page == '/pages_promotion/bargain/launch') {
|
||||
$goods_info = $this->getGoodsInfo($qrcode_param[ 'bargain_id' ]);
|
||||
unset($qrcode_param[ 'bargain_id' ]);
|
||||
} else {
|
||||
$goods_info = $this->getGoodsInfo($qrcode_param[ 'id' ]);
|
||||
}
|
||||
if (empty($goods_info)) {
|
||||
return $this->error('未获取到商品信息');
|
||||
}
|
||||
|
||||
$file_path = 'upload/share_img/bargain_' . $goods_info[ 'bargain_id' ] . '/sku_' . $goods_info[ 'sku_id' ] . '.jpg';
|
||||
if (file_exists($file_path)) return $this->success(['path' => $file_path]);
|
||||
|
||||
$poster_width = 600;
|
||||
$poster_height = 480;
|
||||
|
||||
$poster = new PosterExtend($poster_width, $poster_height);
|
||||
$option = [
|
||||
[
|
||||
'action' => 'setBackground', // 设背景色
|
||||
'data' => [255, 255, 255]
|
||||
],
|
||||
[
|
||||
'action' => 'imageCopy', // 商品图
|
||||
'data' => [
|
||||
img($goods_info[ 'sku_image' ], 'mid'),
|
||||
30,
|
||||
130,
|
||||
200,
|
||||
200,
|
||||
'square',
|
||||
50,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入商品名称
|
||||
'data' => [
|
||||
$goods_info[ 'sku_name' ],
|
||||
22,
|
||||
[51, 51, 51],
|
||||
250,
|
||||
170,
|
||||
330,
|
||||
2,
|
||||
false,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入商品价格
|
||||
'data' => [
|
||||
'砍成价:¥',
|
||||
15,
|
||||
[255, 0, 0],
|
||||
250,
|
||||
295,
|
||||
300,
|
||||
2,
|
||||
false,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入商品价格
|
||||
'data' => [
|
||||
$goods_info[ 'floor_price' ],
|
||||
32,
|
||||
[255, 0, 0],
|
||||
345,
|
||||
295,
|
||||
300,
|
||||
2,
|
||||
false,
|
||||
1,
|
||||
PUBLIC_PATH . 'static/font/custom.ttf'
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入商品原价
|
||||
'data' => [
|
||||
'原 价:¥',
|
||||
15,
|
||||
[153, 153, 153],
|
||||
250,
|
||||
330,
|
||||
300,
|
||||
2,
|
||||
false,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入商品原价
|
||||
'data' => [
|
||||
$goods_info[ 'price' ],
|
||||
16,
|
||||
[153, 153, 153],
|
||||
345,
|
||||
328,
|
||||
300,
|
||||
2,
|
||||
false,
|
||||
1,
|
||||
PUBLIC_PATH . 'static/font/custom.ttf',
|
||||
]
|
||||
],
|
||||
// 划线(两条线)
|
||||
[
|
||||
'action' => 'imageline',
|
||||
'data' => [
|
||||
325,
|
||||
320,
|
||||
325 + imagettfbbox(16, 0, PUBLIC_PATH . 'static/font/custom.ttf', '¥ ' . $goods_info[ 'price' ])[ 2 ],
|
||||
320,
|
||||
[153, 153, 153],
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageline',
|
||||
'data' => [
|
||||
325,
|
||||
321,
|
||||
325 + imagettfbbox(16, 0, PUBLIC_PATH . 'static/font/custom.ttf', '¥ ' . $goods_info[ 'price' ])[ 2 ],
|
||||
321,
|
||||
[153, 153, 153],
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageCopy', // 背景图
|
||||
'data' => [
|
||||
img('upload/share_img/bg/bargain_1.png'),
|
||||
0,
|
||||
0,
|
||||
600,
|
||||
480,
|
||||
'square',
|
||||
0,
|
||||
1
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
$option_res = $poster->create($option);
|
||||
if (is_array($option_res)) {
|
||||
return $option_res;
|
||||
}
|
||||
|
||||
return $option_res->jpeg('upload/share_img/bargain_' . $goods_info[ 'bargain_id' ],
|
||||
'sku_' . $goods_info[ 'sku_id' ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分享图片
|
||||
* @param int $bargain_id
|
||||
*/
|
||||
public function clearShareImg(int $bargain_id)
|
||||
{
|
||||
$dir = 'upload/share_img/bargain_' . $bargain_id;
|
||||
@deleteDir($dir);
|
||||
}
|
||||
|
||||
}
|
||||
135
addon/bargain/model/share/WchatShare.php
Executable file
135
addon/bargain/model/share/WchatShare.php
Executable file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\bargain\model\share;
|
||||
|
||||
use addon\bargain\model\Bargain as BargainModel;
|
||||
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_BARGAIN_PROMOTE',
|
||||
'path' => [ '/pages_promotion/bargain/detail' ],
|
||||
'method_prefix' => 'goodsDetail',
|
||||
],
|
||||
[
|
||||
'title' => '砍价列表',
|
||||
'config_key' => 'WCHAT_SHARE_CONFIG_BARGAIN_LIST_PROMOTE',
|
||||
'path' => [ '/pages_promotion/bargain/list' ],
|
||||
'method_prefix' => 'goodsList',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* 砍价分享数据
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function goodsListShareData($param)
|
||||
{
|
||||
//跳转路径
|
||||
$link = $this->getShareLink($param);
|
||||
$config_method = $this->goodsListShareConfig(__FUNCTION__);
|
||||
$config_data = $this->$config_method($param)[ 'value' ];
|
||||
|
||||
$data = [
|
||||
'link' => $link,
|
||||
'desc' => $config_data[ 'desc' ],
|
||||
'imgUrl' => $config_data[ 'imgUrl' ],
|
||||
'title' => $config_data[ 'title' ]
|
||||
];
|
||||
return [
|
||||
'permission' => [
|
||||
'hideOptionMenu' => false,
|
||||
'hideMenuItems' => [],
|
||||
],
|
||||
'data' => $data,//分享内容
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 砍价列表分享配置
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function goodsListShareConfig($param)
|
||||
{
|
||||
$site_id = $param[ 'site_id' ];
|
||||
$config = $param[ 'config' ];
|
||||
|
||||
$config_model = new ConfigModel();
|
||||
$data = $config_model->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', $config[ 'config_key' ] ] ])[ 'data' ];
|
||||
if (empty($data[ 'value' ])) {
|
||||
$data[ 'value' ] = [
|
||||
'title' => "砍价列表",
|
||||
'desc' => "我在参加\n砍价活动",
|
||||
'imgUrl' => ''
|
||||
];
|
||||
}
|
||||
if (empty($data[ 'value' ][ 'imgUrl' ])) {
|
||||
$data[ 'value' ][ 'imgUrl' ] = img('addon/bargain/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[ 'id' ]) || isset($query[ 'bargain_id' ])) {
|
||||
$bargain_id = $query[ 'id' ] ?? $query[ 'bargain_id' ];
|
||||
$goods = new BargainModel();
|
||||
$sku_info = $goods->getBargainGoodsDetail([ [ 'pb.bargain_id', '=', $bargain_id ] ])[ 'data' ];
|
||||
if (!empty($sku_info)) {
|
||||
$config_model = new \app\model\share\WchatShare();
|
||||
$config_data = $config_model->goodsDetailShareConfig($param);
|
||||
|
||||
$title = str_replace('{goods_name}', $sku_info[ 'sku_name' ], $config_data[ 'value' ][ 'title' ]);
|
||||
$desc = str_replace('{price}', $sku_info[ 'floor_price' ], $config_data[ 'value' ][ 'desc' ]);
|
||||
$link = $this->getShareLink($param);
|
||||
$image_url = $sku_info[ 'sku_image' ];
|
||||
|
||||
$data = [
|
||||
'title' => $title,
|
||||
'desc' => $desc,
|
||||
'link' => $link,
|
||||
'imgUrl' => $image_url,
|
||||
];
|
||||
return [
|
||||
'permission' => [
|
||||
'hideOptionMenu' => false,
|
||||
'hideMenuItems' => [],
|
||||
],
|
||||
'data' => $data,//分享内容
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
89
addon/bargain/model/share/WeappShare.php
Executable file
89
addon/bargain/model/share/WeappShare.php
Executable file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\bargain\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_BARGAIN_LIST',
|
||||
'path' => [ '/pages_promotion/bargain/list' ],
|
||||
'method_prefix' => 'bargainList',
|
||||
],
|
||||
];
|
||||
|
||||
protected $sort = 2;
|
||||
|
||||
/**
|
||||
* 首页分享数据
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function bargainListShareData($param)
|
||||
{
|
||||
//获取和替换配置数据
|
||||
$config_data = $this->bargainListShareConfig($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 bargainListShareConfig($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