添加网站文件
This commit is contained in:
115
application/common/behavior/CancelOrder.php
Normal file
115
application/common/behavior/CancelOrder.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\behavior;
|
||||
|
||||
use app\api\logic\DistributionLogic;
|
||||
use app\api\model\Order;
|
||||
use app\common\logic\IntegralLogic;
|
||||
use app\common\logic\OrderGoodsLogic;
|
||||
use app\common\logic\OrderLogLogic;
|
||||
use app\common\model\AccountLog;
|
||||
use app\common\model\OrderLog;
|
||||
use think\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 取消订单后的操作
|
||||
* Class CancelOrder
|
||||
* @package app\common\behavior
|
||||
*/
|
||||
class CancelOrder
|
||||
{
|
||||
public function run($params)
|
||||
{
|
||||
|
||||
$order_id = $params['order_id'];
|
||||
$handle_id = $params['handle_id'] ?? 0;
|
||||
$handle_type = $params['handle_type'] ?? 0;
|
||||
|
||||
$order = Order::get(['id' => $order_id], ['orderGoods']);
|
||||
if (empty($order)){
|
||||
return false;
|
||||
}
|
||||
|
||||
$user_id = $order['user_id'];
|
||||
|
||||
//订单取消后更新分销订单为已失效状态
|
||||
DistributionLogic::setDistributionOrderFail($order_id);
|
||||
|
||||
//下单扣库存的话(deduct_type=1),回退库存,支付后扣库存的话(deduct_type=0),判断订单是否支付才去回退库存
|
||||
OrderGoodsLogic::backStock($order['orderGoods'], $order['pay_status']);
|
||||
|
||||
//扣除每日首单奖励
|
||||
// IntegralLogic::backIntegral($user_id, $order_id);
|
||||
|
||||
//下单是否使用积分
|
||||
if ($order['use_integral'] > 0){
|
||||
IntegralLogic::handleIntegral(
|
||||
$user_id,
|
||||
$order['use_integral'],
|
||||
AccountLog::cancel_order_refund_integral,
|
||||
$order_id
|
||||
);
|
||||
}
|
||||
|
||||
//返回优惠券
|
||||
if (!empty($order['coupon_list_id'])) {
|
||||
Db::name('coupon_list')->where(['id' => $order['coupon_list_id']])->update([
|
||||
'status' => 0,
|
||||
'use_time' => '',
|
||||
'order_id' => '',
|
||||
'update_time' => time(),
|
||||
]);
|
||||
}
|
||||
|
||||
//订单日志
|
||||
switch ($handle_type){
|
||||
case OrderLog::TYPE_USER:
|
||||
OrderLogLogic::record(
|
||||
OrderLog::TYPE_USER,
|
||||
OrderLog::USER_CANCEL_ORDER,
|
||||
$order_id,
|
||||
$user_id,
|
||||
OrderLog::USER_CANCEL_ORDER
|
||||
);
|
||||
break;
|
||||
|
||||
case OrderLog::TYPE_SHOP:
|
||||
OrderLogLogic::record(
|
||||
OrderLog::TYPE_SHOP,
|
||||
OrderLog::SHOP_CANCEL_ORDER,
|
||||
$order_id,
|
||||
$handle_id,
|
||||
OrderLog::SHOP_CANCEL_ORDER
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
OrderLogLogic::record(
|
||||
OrderLog::TYPE_SYSTEM,
|
||||
OrderLog::SYSTEM_CANCEL_ORDER,
|
||||
$order_id,
|
||||
0,
|
||||
OrderLog::SYSTEM_CANCEL_ORDER
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
113
application/common/behavior/Footprint.php
Normal file
113
application/common/behavior/Footprint.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\behavior;
|
||||
|
||||
use app\common\model\Footprint as FootprintModel;
|
||||
use app\common\model\FootprintRecord as FootprintRecordModel;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 足迹记录
|
||||
* Class Footprint
|
||||
* @package app\common\behavior
|
||||
*/
|
||||
class Footprint
|
||||
{
|
||||
public function run($params)
|
||||
{
|
||||
try {
|
||||
// 全局气泡开关
|
||||
$footprint_status = ConfigServer::get('footprint', 'footprint_status', 1);
|
||||
if (!$footprint_status) return;
|
||||
// 判断某个气泡功能是否开启
|
||||
if ($this->getFootPrintIsAllowByType($params['type'])) {
|
||||
$this->record($params);
|
||||
}
|
||||
} catch (\Exception $e) {}
|
||||
}
|
||||
|
||||
// 记录足迹逻辑
|
||||
private function record($params)
|
||||
{
|
||||
// 获取参数(主要参数: type, user_id, goods_id[可能不存在])
|
||||
if (empty($params['type']) || !$params['type']) return;
|
||||
if (empty($params['user_id']) || !$params['user_id']) return;
|
||||
|
||||
switch ($params['type']) {
|
||||
case FootprintModel::enter_mall: //进入商城(30分钟内没记录才记录)
|
||||
if(!FootprintRecordModel::getFootPrintOneHourInner($params)) {
|
||||
$tpl = '访问了商城';
|
||||
FootprintRecordModel::add($params, $tpl);
|
||||
}
|
||||
break;
|
||||
case FootprintModel::browse_goods: //浏览商品(30分钟内没记录才记录)
|
||||
if(!FootprintRecordModel::getFootPrintOneHourInner($params)) {
|
||||
$tpl = '正在浏览'.$this->getGoodsName($params['foreign_id']);
|
||||
FootprintRecordModel::add($params, $tpl);
|
||||
}
|
||||
break;
|
||||
case FootprintModel::add_cart: //加入购物车
|
||||
$tpl = '正在购买'.$this->getGoodsName($params['foreign_id']);
|
||||
FootprintRecordModel::add($params, $tpl);
|
||||
break;
|
||||
case FootprintModel::receive_coupon: //领取优惠券
|
||||
$tpl = '正在领取'.$this->getCouponName($params['foreign_id']).'优惠券';
|
||||
FootprintRecordModel::add($params, $tpl);
|
||||
break;
|
||||
case FootprintModel::place_order: //下单结算
|
||||
$tpl = '成功下单'.$params['total_money'];
|
||||
FootprintRecordModel::add($params, $tpl);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取商品名称
|
||||
private function getGoodsName($goods_id)
|
||||
{
|
||||
$goods = Db::name('goods')->where(['id'=>(int)$goods_id])
|
||||
->field('id,name')->find();
|
||||
if ($goods) {
|
||||
if (mb_strlen($goods['name']) > 6) {
|
||||
return mb_substr($goods['name'], 0, 6). '**';
|
||||
}
|
||||
return $goods['nickname'];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
// 获取优惠券名称
|
||||
private function getCouponName($coupon_id)
|
||||
{
|
||||
$coupon = Db::name('coupon')->where(['id'=>(int)$coupon_id])
|
||||
->field('id,name')->find();
|
||||
return $coupon ? $coupon['name'] : '';
|
||||
}
|
||||
|
||||
// 获取足迹模板(是否允许使用)
|
||||
public function getFootPrintIsAllowByType($type)
|
||||
{
|
||||
$model = Db::name('footprint')->where(['type'=>(int)$type])->find();
|
||||
if ($model and $model['status']) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
104
application/common/behavior/GiveReward.php
Normal file
104
application/common/behavior/GiveReward.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\behavior;
|
||||
|
||||
|
||||
use app\common\logic\AccountLogLogic;
|
||||
use app\common\model\AccountLog;
|
||||
use Exception;
|
||||
use think\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
class GiveReward
|
||||
{
|
||||
/**
|
||||
* @Notes: 赠送积分或成长值
|
||||
* @Author: 张无忌
|
||||
* @param $params
|
||||
* @return bool
|
||||
*/
|
||||
public function run($params)
|
||||
{
|
||||
try {
|
||||
$order_id = $params['order_id']; //(订单ID)
|
||||
$scene = $params['scene']; //(赠送场景 [1=订单支付, 2=订单发货, 3=订单完成, 4=订单结算])
|
||||
|
||||
$order = Db::name('order')->find($order_id);
|
||||
if (!$order) return false;
|
||||
if (empty($order['attach_values'])) return false;
|
||||
$attach = json_decode($order['attach_values'], true);
|
||||
|
||||
$this->giveIntegral($order, $attach, $scene);
|
||||
$this->giveGrowth($order, $attach, $scene);
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
Log::write('赠送奖励失败:'.$e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Notes: 送积分
|
||||
* @Author: 张无忌
|
||||
* @param $order
|
||||
* @param $attach
|
||||
* @param $scene
|
||||
* @return bool
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
private function giveIntegral($order, $attach, $scene)
|
||||
{
|
||||
if ($attach['give_integral_scene'] != $scene) return true;
|
||||
if ($attach['give_integral_num'] <= 0) return true;
|
||||
|
||||
Db::name('user')->where(['id'=>$order['user_id']])->update([
|
||||
'user_integral' => ['inc', $attach['give_integral_num']],
|
||||
'update_time' => time()
|
||||
]);
|
||||
|
||||
$change_type = 1;
|
||||
$channel = AccountLog::order_add_integral;
|
||||
AccountLogLogic::AccountRecord(
|
||||
$order['user_id'],
|
||||
$attach['give_integral_num'],
|
||||
$change_type,
|
||||
$channel, '', $order['id']
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 送成长值
|
||||
* @Author: 张无忌
|
||||
* @param $order
|
||||
* @param $attach
|
||||
* @param $scene
|
||||
* @return bool
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
private function giveGrowth($order, $attach, $scene)
|
||||
{
|
||||
if ($attach['give_growth_scene'] != $scene) return true;
|
||||
if ($attach['give_growth_num'] <= 0) return true;
|
||||
|
||||
Db::name('user')->where(['id'=>$order['user_id']])->update([
|
||||
'user_growth' => ['inc', $attach['give_growth_num']],
|
||||
'update_time' => time()
|
||||
]);
|
||||
|
||||
$change_type = 1;
|
||||
$channel = AccountLog::order_give_growth;
|
||||
AccountLogLogic::AccountRecord(
|
||||
$order['user_id'],
|
||||
$attach['give_growth_num'],
|
||||
$change_type,
|
||||
$channel, '', $order['id']
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
147
application/common/behavior/Notice.php
Normal file
147
application/common/behavior/Notice.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\behavior;
|
||||
|
||||
use app\common\logic\NoticeLogic;
|
||||
use app\common\model\Client_;
|
||||
use app\common\model\NoticeSetting;
|
||||
use app\common\server\WxMessageServer;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
|
||||
/**
|
||||
* 通知信息
|
||||
* Class Notice
|
||||
* @package app\common\behavior
|
||||
*/
|
||||
class Notice
|
||||
{
|
||||
public function run($params)
|
||||
{
|
||||
try {
|
||||
if (empty($params['scene'])) {
|
||||
throw new Exception('参数缺失');
|
||||
}
|
||||
|
||||
//找到当前场景的通知设置记录,发送通知
|
||||
$this->noticeByScene($params['user_id'], $params);
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 根据各个场景发送通知
|
||||
* @param $user_id
|
||||
* @param $params
|
||||
* @author 段誉(2021/4/28 18:21)
|
||||
* @throws Exception
|
||||
*/
|
||||
public function noticeByScene($user_id, $params)
|
||||
{
|
||||
$scene_info = NoticeSetting::where('scene', $params['scene'])->find();
|
||||
|
||||
if (empty($scene_info)) {
|
||||
throw new Exception('信息错误');
|
||||
}
|
||||
|
||||
$params = $this->mergeParams($params);
|
||||
|
||||
//发送系统消息
|
||||
if (isset($scene_info['system_notice']['status']) && $scene_info['system_notice']['status'] == 1) {
|
||||
$content = NoticeLogic::contentFormat($scene_info['system_notice']['content'], $params);
|
||||
NoticeLogic::addNoticeLog($params, $scene_info,NoticeSetting::SYSTEM_NOTICE, $content);
|
||||
}
|
||||
|
||||
//发送短信记录
|
||||
if (isset($scene_info['sms_notice']['status']) && $scene_info['sms_notice']['status'] == 1) {
|
||||
|
||||
}
|
||||
|
||||
//发送公众号记录
|
||||
if (isset($scene_info['oa_notice']['status']) && $scene_info['oa_notice']['status'] == 1) {
|
||||
(new WxMessageServer($user_id,Client_::oa))->send($params);
|
||||
}
|
||||
|
||||
//发送小程序记录
|
||||
if (isset($scene_info['mnp_notice']['status']) && $scene_info['mnp_notice']['status'] == 1) {
|
||||
(new WxMessageServer($user_id, Client_::mnp))->send($params);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 拼装额外参数
|
||||
* @param $params
|
||||
* @author 段誉(2021/4/28 18:21)
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function mergeParams($params)
|
||||
{
|
||||
//订单相关信息
|
||||
if (!empty($params['order_id'])) {
|
||||
$order = Db::name('order')->where(['id' => $params['order_id']])->find();
|
||||
$order_goods = Db::name('order_goods')->alias('og')
|
||||
->field('g.name')
|
||||
->join('goods g', 'og.goods_id = g.id')
|
||||
->where('og.order_id', $params['order_id'])
|
||||
->find();
|
||||
|
||||
$goods_name = $order_goods['name'] ?? '商品';
|
||||
if (mb_strlen($goods_name) > 8 ) {
|
||||
$goods_name = mb_substr($goods_name,0,8) . '..';
|
||||
}
|
||||
$params['goods_name'] = $goods_name;
|
||||
$params['order_sn'] = $order['order_sn'];
|
||||
$params['time'] = date('Y-m-d H:i', $order['create_time']);
|
||||
$params['total_num'] = $order['total_num'];
|
||||
$params['order_amount'] = $order['order_amount'];
|
||||
}
|
||||
|
||||
//用户相关信息
|
||||
if (!empty($params['user_id'])) {
|
||||
$user = Db::name('user')->where('id', $params['user_id'])->find();
|
||||
$params['nickname'] = $user['nickname'];
|
||||
}
|
||||
|
||||
//下级名称;(邀请人场景)
|
||||
if (!empty($params['lower_id'])) {
|
||||
$params['lower_name'] = Db::name('user')->where('id', $params['lower_id'])->value('nickname');
|
||||
}
|
||||
|
||||
//跳转路径
|
||||
$jump_path = NoticeSetting::getPathByScene($params['scene'], $params['order_id'] ?? 0);
|
||||
$params['url'] = $jump_path['url'];
|
||||
$params['page'] = $jump_path['page'];
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
89
application/common/behavior/Printer.php
Normal file
89
application/common/behavior/Printer.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\behavior;
|
||||
use app\common\model\Order;
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\server\YlyPrinter;
|
||||
use think\Db;
|
||||
|
||||
class Printer
|
||||
{
|
||||
public function run($params)
|
||||
{
|
||||
try{
|
||||
$order_id = $params['order_id'] ?? '';
|
||||
if(empty($order_id)){
|
||||
return false;
|
||||
}
|
||||
//打印机配置
|
||||
$printer_config = Db::name('printer_config')
|
||||
->where(['status'=>1])
|
||||
->find();
|
||||
|
||||
//打印机列表
|
||||
$printer_list = Db::name('printer')
|
||||
->where(['type'=>$printer_config['id'],'del'=>0,'auto_print'=>1])
|
||||
->select();
|
||||
|
||||
if(empty($printer_list) || empty($printer_list)){
|
||||
return false;
|
||||
}
|
||||
//获取订单信息
|
||||
$order = $this->getOrderList($order_id);
|
||||
//获取打印模板
|
||||
$template_config = ConfigServer::get('printer', 'yly_template', []);
|
||||
//示例化打印机类
|
||||
$yly_print = new YlyPrinter($printer_config['client_id'],$printer_config['client_secret']);
|
||||
//调用打印机
|
||||
$yly_print->ylyPrint($printer_list,$order,$template_config);
|
||||
|
||||
return true;
|
||||
|
||||
}catch (\Exception $e){
|
||||
|
||||
return $e->getMessage();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:获取订单信息
|
||||
* @param $id
|
||||
* @author: cjhao 2021/4/24 15:22
|
||||
*/
|
||||
public function getOrderList($order_id){
|
||||
$order = new Order();
|
||||
|
||||
$order = $order
|
||||
->with(['order_goods'])
|
||||
->where('id', $order_id)
|
||||
->append(['delivery_address'])
|
||||
->find();
|
||||
|
||||
foreach ($order['order_goods'] as &$order_goods) {
|
||||
$info = json_decode($order_goods['goods_info'], true);
|
||||
$order_goods['name'] = $info['goods_name'];
|
||||
$order_goods['spec_value_str'] = $info['spec_value_str'];
|
||||
$order_goods['goods_image'] = empty($info['spec_image']) ? $info['image'] : $info['spec_image'];
|
||||
}
|
||||
return $order;
|
||||
}
|
||||
|
||||
}
|
||||
225
application/common/behavior/SmsSend.php
Normal file
225
application/common/behavior/SmsSend.php
Normal file
@@ -0,0 +1,225 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\behavior;
|
||||
|
||||
use app\common\logic\NoticeLogic;
|
||||
use app\common\model\{NoticeSetting, SmsLog, SmsConfig};
|
||||
use app\common\server\Alisms;
|
||||
use app\common\server\TencentSms;
|
||||
use think\Exception;
|
||||
|
||||
class SmsSend
|
||||
{
|
||||
protected $channel = 0; //发短信渠道[1=阿里短信, 2=腾讯短信]
|
||||
protected $sms_key = ''; //短信KEY
|
||||
protected $mobile = ''; //发送手机号码
|
||||
protected $sms_params = ''; //发送参数
|
||||
protected $config = ''; //短信配置
|
||||
protected $code = ''; //验证码(短信key为注册、找回密码)
|
||||
protected $sms = ''; //短信内容
|
||||
protected $content = ''; //短信准备发送内容
|
||||
protected $sms_log = ''; //短信记录model
|
||||
|
||||
protected $notice_id = null; //通知记录id
|
||||
|
||||
public function run($params)
|
||||
{
|
||||
try{
|
||||
// 设置短信参数
|
||||
$params['scene'] = $params['key'];
|
||||
$this->sms_key = $params['key'];
|
||||
$this->sms_params = $params['params'];
|
||||
$this->mobile = $params['mobile'];
|
||||
$result = $this->getSmsConfig($params['key']);
|
||||
if ($result !== true) return $result;
|
||||
|
||||
$this->sms_log = new SmsLog();
|
||||
$this->setSmsContent(); //短信内容
|
||||
$this->setSmsCode(); //短信验证码
|
||||
$this->createSmsLog(); //增加短信记录
|
||||
|
||||
//增加通知记录
|
||||
$this->notice_id = NoticeLogic::addNoticeLog($params, $this->sms, NoticeSetting::SMS_NOTICE, $this->content);
|
||||
|
||||
if ($this->channel == 1) {
|
||||
// 阿里云短信
|
||||
$alisms = new Alisms($this->config);
|
||||
$res = $alisms->setMobile($this->mobile)
|
||||
->setTemplateCode($this->sms['template_code'])
|
||||
->setTemplateParam($this->sms_params)
|
||||
->sendSms();
|
||||
|
||||
if (isset($res['Code']) && $res['Code'] == 'OK') {
|
||||
$send_status = SmsLog::send_success;
|
||||
$this->updateSmsLog($send_status, $res);
|
||||
return true;
|
||||
} else {
|
||||
$send_status = SmsLog::send_fail;
|
||||
$this->updateSmsLog($send_status, $res);
|
||||
$message = $res['Message'] ?? $res;
|
||||
throw new Exception('短信配置错误:' . $message);
|
||||
}
|
||||
} elseif ($this->channel == 2) {
|
||||
// 腾讯云短信
|
||||
$res = (new TencentSms($this->config))
|
||||
->setMobile($this->mobile)
|
||||
->setTemplateCode($this->sms['template_code'])
|
||||
->setTemplateParam($this->handleTcParams())
|
||||
->sendSms();
|
||||
|
||||
if (isset($res['SendStatusSet']) && $res['SendStatusSet'][0]['Code'] == 'Ok') {
|
||||
$send_status = SmsLog::send_success;
|
||||
$this->updateSmsLog($send_status, $res);
|
||||
return true;
|
||||
} else {
|
||||
$send_status = SmsLog::send_fail;
|
||||
$this->updateSmsLog($send_status, $res);
|
||||
$message = $res['SendStatusSet'][0]['Message'] ?? json_encode($res);
|
||||
throw new Exception('短信配置错误:' . $message);
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception('短信渠道不存在');
|
||||
} catch (\Exception $e) {
|
||||
$this->updateSmsLog(SmsLog::send_fail, $e->getMessage());
|
||||
NoticeLogic::updateNotice($this->notice_id, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 获取短信配置 (场景是否开启)
|
||||
* @param $scene (场景编号)
|
||||
* @return bool|string
|
||||
*/
|
||||
public function getSmsConfig($scene)
|
||||
{
|
||||
// 短信是否开启
|
||||
$able_send = config('project.sms');
|
||||
$this->config = SmsConfig::get(['status' => 1]);
|
||||
if (!$this->config || true != $able_send) {
|
||||
return '短信功能未开启';
|
||||
}
|
||||
|
||||
// 获取短信内容
|
||||
$this->channel = $this->config['id'];
|
||||
$sms_scene = NoticeSetting::where('scene', $scene)->find();
|
||||
$this->sms = $sms_scene['sms_notice'];
|
||||
$this->variable = $sms_scene['variable'];
|
||||
if (!$this->sms) { return '短信模板不存在'; }
|
||||
if ($this->sms['status'] == 0) { return '相关通知未开启'; }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:短信内容
|
||||
*/
|
||||
public function setSmsContent()
|
||||
{
|
||||
$this->content = $this->sms['content'];
|
||||
foreach ($this->sms_params as $item => $val) {
|
||||
$search_replace = '{' . $item . '}';
|
||||
$this->content = str_replace($search_replace, $val, $this->content);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:是否需要短信验证码
|
||||
*/
|
||||
public function setSmsCode()
|
||||
{
|
||||
if (in_array($this->sms_key, NoticeSetting::NOTICE_NEED_CODE)) {
|
||||
$code = array_intersect_key($this->sms_params, $this->variable);
|
||||
if ($code) $this->code = array_shift($code);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:记录短信日志
|
||||
*/
|
||||
public function createSmsLog()
|
||||
{
|
||||
$this->sms_log->message_key = $this->sms_key;
|
||||
$this->sms_log->mobile = $this->mobile;
|
||||
$this->sms_log->content = $this->content;
|
||||
$this->sms_log->code = $this->code;
|
||||
$this->sms_log->send_status = SmsLog::send_ing;
|
||||
$this->sms_log->send_time = time();
|
||||
$this->sms_log->create_time = time();
|
||||
$this->sms_log->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:更新短信状态(发送成功或发送失败)
|
||||
* @param $send_status int 短信状态
|
||||
* @param $result int 发送返回内容
|
||||
*/
|
||||
public function updateSmsLog($send_status, $result)
|
||||
{
|
||||
$this->sms_log->send_status = $send_status;
|
||||
$this->sms_log->results = json_encode($result);
|
||||
$this->sms_log->save();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @notes 腾讯云参数
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2021/8/4 14:10
|
||||
*/
|
||||
public function handleTcParams()
|
||||
{
|
||||
//腾讯云特殊处理
|
||||
$arr = [];
|
||||
$content = $this->sms['content'];
|
||||
foreach ($this->sms_params as $item => $val) {
|
||||
$search = '{' . $item . '}';
|
||||
if(strpos($content, $search) !== false
|
||||
&& !in_array($item, $arr)
|
||||
) {
|
||||
//arr => 获的数组[nickname, order_sn] //顺序可能是乱的
|
||||
$arr[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
//arr2 => 获得数组[nickname, order_sn] //调整好顺序的变量名数组
|
||||
$arr2 = [];
|
||||
if (!empty($arr)) {
|
||||
foreach ($arr as $v) {
|
||||
$key = strpos($content, $v);
|
||||
$arr2[$key] = $v;
|
||||
}
|
||||
}
|
||||
//格式化 arr2 => 以小到大的排序的数组
|
||||
ksort($arr2);
|
||||
$arr3 = array_values($arr2);
|
||||
|
||||
//arr4 => 获取到变量数组的对应的值 [mofung, 123456789]
|
||||
$arr4 = [];
|
||||
foreach ($arr3 as $v2) {
|
||||
if(isset($this->sms_params[$v2])) {
|
||||
$arr4[] = $this->sms_params[$v2];
|
||||
}
|
||||
}
|
||||
return $arr4;
|
||||
}
|
||||
|
||||
}
|
||||
125
application/common/cache/CacheBase.php
vendored
Normal file
125
application/common/cache/CacheBase.php
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\cache;
|
||||
|
||||
use think\facade\Cache;
|
||||
|
||||
abstract class CacheBase
|
||||
{
|
||||
protected $tag;
|
||||
protected $extend;
|
||||
protected $name;
|
||||
|
||||
public function __construct($key = '', $extend = [])
|
||||
{
|
||||
$this->tag = $this->setTag();
|
||||
$this->name = $this->tag . '_' . $key;
|
||||
$this->extend = $extend;
|
||||
}
|
||||
|
||||
|
||||
public abstract function setTag();
|
||||
|
||||
/**
|
||||
* 子类实现查出数据
|
||||
* @return mixed
|
||||
*/
|
||||
public abstract function setData();
|
||||
|
||||
/**
|
||||
* 创建并获取数据
|
||||
* @param null $expire
|
||||
* @return mixed
|
||||
*/
|
||||
public function set($expire = null)
|
||||
{
|
||||
$data = self::cacheGet($this->name);
|
||||
if ($data !== false) {
|
||||
return $data;
|
||||
}
|
||||
$data = $this->setData();
|
||||
self::cacheSet($this->name, $data, $expire);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* User: 意象信息科技 lr
|
||||
* Desc: 获取数据
|
||||
* @return mixed
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return self::cacheGet($this->name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断数据是否为空
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
$data = self::cacheGet($this->name);
|
||||
if ($data !== false) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @return bool
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
return self::cacheRm($this->name);
|
||||
}
|
||||
|
||||
public function delAll()
|
||||
{
|
||||
return Cache::clear($this->tag);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 刷新并获取
|
||||
* @return mixed
|
||||
*/
|
||||
public function refresh()
|
||||
{
|
||||
$this->del();
|
||||
return $this->set();
|
||||
}
|
||||
|
||||
protected function cacheSet($name, $value, $expire = null)
|
||||
{
|
||||
Cache::tag($this->tag)->set($name, $value, $expire);
|
||||
}
|
||||
|
||||
protected function cacheRm($name)
|
||||
{
|
||||
return Cache::rm($name);
|
||||
}
|
||||
|
||||
protected function cacheGet($name, $default = false)
|
||||
{
|
||||
return Cache::get($name, $default);
|
||||
}
|
||||
}
|
||||
43
application/common/cache/RegionCache.php
vendored
Normal file
43
application/common/cache/RegionCache.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\cache;
|
||||
|
||||
|
||||
use think\Db;
|
||||
|
||||
class RegionCache extends CacheBase
|
||||
{
|
||||
|
||||
public function setTag()
|
||||
{
|
||||
return 'region';
|
||||
}
|
||||
|
||||
/**
|
||||
* 子类实现查出数据
|
||||
* @return mixed
|
||||
*/
|
||||
public function setData()
|
||||
{
|
||||
return Db::name('dev_region')
|
||||
->column('name', 'id');
|
||||
}
|
||||
}
|
||||
102
application/common/command/BargainEnd.php
Normal file
102
application/common/command/BargainEnd.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
|
||||
use app\common\model\Bargain;
|
||||
use app\common\model\BargainLaunch;
|
||||
use app\common\model\Order;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 砍价活动结束定时任务
|
||||
* Class BargainEnd
|
||||
* @Author 张无忌
|
||||
* @package app\common\command
|
||||
*/
|
||||
class BargainEnd extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('bargain_end')
|
||||
->setDescription('结束已超时的砍价');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
try {
|
||||
$now = time();
|
||||
$bargainModel = new Bargain();
|
||||
$bargainLaunchModel = new BargainLaunch();
|
||||
|
||||
$succeed_ids = [];
|
||||
$defeat_ids = [];
|
||||
//砍价成功后的下单时间
|
||||
$payment_limit_time = ConfigServer::get('bargain', 'payment_limit_time', 0) * 60;
|
||||
if($payment_limit_time > 0){
|
||||
$payment_limit_time = $now + $payment_limit_time;
|
||||
}
|
||||
//找出所有超时未关掉的订单
|
||||
$bargainLaunchModel->where([['status','=',BargainLaunch::conductStatus],['launch_end_time','<=',$now]])
|
||||
->chunk(100, function($launchs) use(&$succeed_ids,&$defeat_ids) {
|
||||
|
||||
foreach ($launchs as $launch){
|
||||
$launch = $launch->toarray();
|
||||
//任意金额购买时,更新砍价成功
|
||||
if(2 == $launch['bargain_snap']['payment_where']){
|
||||
$succeed_ids[] = $launch['id'];
|
||||
}else{
|
||||
$defeat_ids[] = $launch['id'];
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
//标记成功
|
||||
if($succeed_ids){
|
||||
$bargainLaunchModel->where(['id'=>$succeed_ids])->update(['status'=>BargainLaunch::successStatus,'payment_limit_time'=>$payment_limit_time,'bargain_end_time'=>$now]);
|
||||
}
|
||||
//标记失败
|
||||
if($defeat_ids){
|
||||
$bargainLaunchModel->where(['id'=>$defeat_ids])->update(['status'=>BargainLaunch::failStatus,'bargain_end_time'=>$now]);
|
||||
}
|
||||
|
||||
// 查询出要关闭的砍价活动
|
||||
$bargain_ids = $bargainModel->where([
|
||||
['activity_end_time', '<', $now],
|
||||
['del', '=', 0],
|
||||
['status', '=', 1]
|
||||
])->column('id');
|
||||
|
||||
// 结束砍价活动(结束时间 < 当前时间)
|
||||
$bargainModel->whereIn('id', $bargain_ids)
|
||||
->update(['status' => 0]);
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::write('结束砍价活动失败:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
103
application/common/command/Crontab.php
Normal file
103
application/common/command/Crontab.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
use Cron\CronExpression;
|
||||
use think\Console;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\Db;
|
||||
use think\facade\Debug;
|
||||
use think\facade\Log;
|
||||
|
||||
class Crontab extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('crontab')
|
||||
->setDescription('定时任务');
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动定时任务守护进程
|
||||
* @param Input $input
|
||||
* @param Output $output
|
||||
* @return int|void|null
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
Log::close();
|
||||
|
||||
$time = time();
|
||||
|
||||
$crons = Db::name('dev_crontab')
|
||||
->where(['status' => 1])
|
||||
->select();
|
||||
if (empty($crons)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($crons as $cron) {
|
||||
//规则错误,不执行
|
||||
if (CronExpression::isValidExpression($cron['expression']) === false) {
|
||||
continue;
|
||||
}
|
||||
//未到时间,不执行
|
||||
$cron_expression = CronExpression::factory($cron['expression']);
|
||||
$next_time = $cron_expression->getNextRunDate(date('Y-m-d H:i:s', $cron['last_time']))->getTimestamp();
|
||||
if ($next_time >= $time) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//开始执行
|
||||
try {
|
||||
Debug::remark('begin');
|
||||
$parameter = explode(' ', $cron['parameter']);
|
||||
if (is_array($parameter) && !empty($cron['parameter'])) {
|
||||
Console::call($cron['command'], $parameter);
|
||||
} else {
|
||||
Console::call($cron['command']);
|
||||
}
|
||||
Db::name('dev_crontab')
|
||||
->where(['id' => $cron['id']])
|
||||
->update(['error' => '']);
|
||||
} catch (\Exception $e) {
|
||||
Db::name('dev_crontab')
|
||||
->where(['id' => $cron['id']])
|
||||
->update(['error' => $e->getMessage(), 'status' => 3]);
|
||||
} finally {
|
||||
Debug::remark('end');
|
||||
$range_time = Debug::getRangeTime('begin', 'end');
|
||||
$max_time = max($cron['max_time'], $range_time);
|
||||
Db::name('dev_crontab')
|
||||
->where(['id' => $cron['id']])
|
||||
->update(['last_time' => $time, 'time' => $range_time, 'max_time' => $max_time]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
172
application/common/command/DistributionOrder.php
Normal file
172
application/common/command/DistributionOrder.php
Normal file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
use app\common\logic\AccountLogLogic;
|
||||
use app\common\model\{AccountLog, AfterSale, NoticeSetting, Order, User, DistributionOrder as DistributionOrderModel};
|
||||
use app\common\server\ConfigServer;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\Db;
|
||||
use think\facade\Hook;
|
||||
use think\facade\Log;
|
||||
|
||||
class DistributionOrder extends Command
|
||||
{
|
||||
|
||||
/**
|
||||
* 分佣逻辑 => (没有售后订单且符合其他条件可结算)
|
||||
* 售后订单为 申请退款, 待退货, 待收货 属于情况不明, 不结算分佣订单
|
||||
* 售后订单为 等待退款 或 退款成功, 不结算分佣订单 分佣订单状态改为已失效
|
||||
* 售后订单为 拒绝 或 拒收货 情况清晰 不退钱 可结算分佣订单
|
||||
*/
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('distribution_order')
|
||||
->setDescription('结算分销订单');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
//查看分销配置是否开启
|
||||
$setting = ConfigServer::get('distribution', 'is_open', 1);
|
||||
if ($setting != 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//售后时间(未过售后时间的分销订单不处理)
|
||||
$after_sale_time = ConfigServer::get('after_sale', 'refund_days', 7);
|
||||
$after_sale_time = $after_sale_time * 24 * 60 * 60;
|
||||
$now = time();
|
||||
|
||||
Db::startTrans();
|
||||
try{
|
||||
//待分佣的分销订单
|
||||
$orders = Db::name('distribution_order_goods')->alias('d')
|
||||
->field('o.id as order_id,o.confirm_take_time, d.money, d.id as distribution_id, d.user_id, d.sn, d.order_goods_id')
|
||||
->join('order_goods og', 'og.id = d.order_goods_id')
|
||||
->join('order o', 'o.id = og.order_id')
|
||||
->where('d.status', DistributionOrderModel::STATUS_WAIT_HANDLE)
|
||||
->where('o.order_status', Order::STATUS_FINISH)
|
||||
->where(Db::raw("o.confirm_take_time+$after_sale_time < $now"))
|
||||
->select();
|
||||
|
||||
//处理用户表字段earnings为null时自增佣金报错的情况
|
||||
$check_user = User::whereNull('earnings')->find();
|
||||
if ($check_user) {
|
||||
User::whereNull('earnings')->update(['earnings' => 0]);
|
||||
}
|
||||
|
||||
foreach ($orders as $order) {
|
||||
|
||||
$user = User::get($order['user_id']);
|
||||
|
||||
//当前分佣订单是否可结算 //非分销会员或已被冻结的分销会员不参与分佣
|
||||
if ( false === self::isSettle($order) || empty($user)
|
||||
|| $user['is_distribution'] != 1
|
||||
|| $user['freeze_distribution'] == 1
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//增加佣金
|
||||
$user->earnings = ['inc', $order['money']];
|
||||
$user->update_time = time();
|
||||
$user->save();
|
||||
|
||||
//增加佣金变动记录
|
||||
AccountLogLogic::AccountRecord(
|
||||
$order['user_id'],
|
||||
$order['money'],
|
||||
1,
|
||||
AccountLog::distribution_inc_earnings,
|
||||
'',
|
||||
$order['distribution_id'],
|
||||
$order['sn']
|
||||
);
|
||||
|
||||
//更新分销订单状态
|
||||
DistributionOrderModel::updateOrderStatus($order['distribution_id'], DistributionOrderModel::STATUS_SUCCESS);
|
||||
|
||||
//通知会员
|
||||
Hook::listen('notice', [
|
||||
'user_id' => $order['user_id'],
|
||||
'earnings' => $order['money'],
|
||||
'scene' => NoticeSetting::GET_EARNINGS_NOTICE,
|
||||
]);
|
||||
|
||||
// 赠送成长值和积分
|
||||
Hook::listen('give_reward', [
|
||||
'order_id' => $order['order_id'],
|
||||
'scene' => 4, //4=订单结算
|
||||
]);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
Log::write('结算分佣订单错误:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//是否可以结算分佣订单 (检查是否有售后记录 没有则可结算, 有则需要检查售后记录状态)
|
||||
protected function isSettle($order)
|
||||
{
|
||||
//订单是否在售后(正在退款或已退款)
|
||||
$check = Db::name('after_sale')
|
||||
->where(['order_goods_id' => $order['order_goods_id']])
|
||||
->where('del', 0)
|
||||
->find();
|
||||
|
||||
if (!$check) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//有售后订单记录且状态 $no_settlement中的 不结算分佣订单
|
||||
$no_settlement = [
|
||||
AfterSale::STATUS_APPLY_REFUND, //申请退款
|
||||
AfterSale::STATUS_WAIT_RETURN_GOODS, //商品待退货
|
||||
AfterSale::STATUS_WAIT_RECEIVE_GOODS, //商家待收货
|
||||
];
|
||||
|
||||
//不结算且分佣订单改为已失效
|
||||
$set_fail = [
|
||||
AfterSale::STATUS_WAIT_REFUND, //等待退款
|
||||
AfterSale::STATUS_SUCCESS_REFUND, //退款成功
|
||||
];
|
||||
|
||||
//售后情况不明 不结算
|
||||
if (in_array($check['status'], $no_settlement)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//分佣订单更新为已失效 不结算
|
||||
if (in_array($check['status'], $set_fail)) {
|
||||
DistributionOrderModel::updateOrderStatus($order['distribution_id'], DistributionOrderModel::STATUS_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
143
application/common/command/OrderClose.php
Normal file
143
application/common/command/OrderClose.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\command;
|
||||
use app\api\model\{
|
||||
Order,Goods,GoodsItem
|
||||
};
|
||||
use app\common\logic\AccountLogLogic;
|
||||
use app\common\model\AccountLog;
|
||||
use app\common\model\Pay;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\Db;
|
||||
|
||||
class OrderClose extends Command{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('order_close')
|
||||
->setDescription('关闭订单');
|
||||
}
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
//是否下单扣库存 todo 默认是下单扣库存
|
||||
$deduct_type = ConfigServer::get('trading', 'deduct_type', 1);
|
||||
//取消订单时长 todo 默认是30分钟
|
||||
$order_cancel_time = ConfigServer::get('trading','order_cancel', 30) * 60;
|
||||
$now = time();
|
||||
|
||||
if ($order_cancel_time == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$order = new Order();
|
||||
$where[] = ['order_status','=',\app\common\model\Order::STATUS_WAIT_PAY];
|
||||
$where[] = ['pay_status','=',Pay::UNPAID];
|
||||
|
||||
$order_list = $order
|
||||
->where($where)
|
||||
->where(Db::raw("create_time+$order_cancel_time < $now"))
|
||||
->with(['orderGoods'])
|
||||
->select()->toArray();
|
||||
|
||||
|
||||
$order_ids = []; //更新的订单
|
||||
$update_total_stock = []; //更新总库存
|
||||
$update_stock = []; //更新规格库存
|
||||
$total_stock_num = []; //总库存
|
||||
$stock_num = []; //规格库存
|
||||
$update_coupon_ids = []; //更新优惠券状态
|
||||
foreach ($order_list as $order){
|
||||
$order_ids[] = $order['id'];
|
||||
//返回优惠券
|
||||
if($order['coupon_list_id']){
|
||||
$update_coupon_ids[] = $order['coupon_list_id'];
|
||||
}
|
||||
//更新积分
|
||||
if($order['use_integral'] > 0){
|
||||
Db::name('user')->where(['id'=>$order['user_id']])->setInc('user_integral',$order['use_integral']);
|
||||
AccountLogLogic::AccountRecord(
|
||||
$order['user_id'],
|
||||
$order['use_integral'],
|
||||
1,
|
||||
AccountLog::cancel_order_refund_integral
|
||||
);
|
||||
}
|
||||
//更新库存
|
||||
if($deduct_type){
|
||||
foreach ($order['order_goods'] as $order_goods){
|
||||
|
||||
//更新商品总库存数据
|
||||
if(isset($update_total_stock[$order_goods['goods_id']])){
|
||||
$total_stock_num[$order_goods['goods_id']] = $total_stock_num[$order_goods['goods_id']] + $order_goods['goods_num'];
|
||||
$update_total_stock[$order_goods['goods_id']]['stock'] = Db::raw('stock+'.$total_stock_num[$order_goods['goods_id']]);
|
||||
}else{
|
||||
$total_stock_num[$order_goods['goods_id']] = $order_goods['goods_num'];
|
||||
$update_total_stock[$order_goods['goods_id']] = [
|
||||
'id' => $order_goods['goods_id'],
|
||||
'stock' => Db::raw('stock+'.$total_stock_num[$order_goods['goods_id']])
|
||||
];
|
||||
}
|
||||
//更新商品规格库存数据
|
||||
if(isset($update_stock[$order_goods['item_id']])){
|
||||
$stock_num[$order_goods['item_id']] = $stock_num[$order_goods['item_id']] + $order_goods['goods_num'];
|
||||
$update_stock[$order_goods['item_id']]['stock'] = Db::raw('stock+'.$stock_num[$order_goods['item_id']]);
|
||||
}else{
|
||||
$stock_num[$order_goods['item_id']] = $order_goods['goods_num'];
|
||||
$update_stock[$order_goods['item_id']] = [
|
||||
'id' => $order_goods['item_id'],
|
||||
'stock' => Db::raw('stock+'.$stock_num[$order_goods['item_id']])
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($order_ids){
|
||||
$update_data = [
|
||||
'order_status' => \app\common\model\Order::STATUS_CLOSE,
|
||||
'update_time' => $now,
|
||||
];
|
||||
Db::name('order')->where(['id'=>$order_ids])->update($update_data);
|
||||
}
|
||||
|
||||
|
||||
//批量更新库存
|
||||
if($update_total_stock){
|
||||
$goods = new Goods();
|
||||
$goods_item = new GoodsItem();
|
||||
$goods->saveAll(array_values($update_total_stock));
|
||||
$goods_item->saveAll(array_values($update_stock));
|
||||
}
|
||||
//更新优惠券
|
||||
if($update_coupon_ids){
|
||||
$update_coupon = [
|
||||
'status' => 0,
|
||||
'use_time' => '',
|
||||
'order_id' => '',
|
||||
'update_time' => $now,
|
||||
];
|
||||
Db::name('coupon_list')->where(['id'=>$update_coupon_ids])->update($update_coupon);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
97
application/common/command/OrderFinish.php
Normal file
97
application/common/command/OrderFinish.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
use app\common\logic\OrderLogLogic;
|
||||
use app\common\model\Order;
|
||||
use app\common\model\OrderLog;
|
||||
use app\common\model\Pay;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\Db;
|
||||
use think\facade\Hook;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 确认收货
|
||||
* Class OrderFinish
|
||||
* @package app\common\command
|
||||
*/
|
||||
class OrderFinish extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('order_finish')
|
||||
->setDescription('自动确认收货(待收货订单)');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$now = time();
|
||||
$config = ConfigServer::get('trading', 'order_finish', 0);
|
||||
if($config == 0){
|
||||
return true;
|
||||
}
|
||||
|
||||
$finish_limit = $config * 24 * 60 * 60;
|
||||
|
||||
$orders = Db::name('order')
|
||||
->where(['order_status' => Order::STATUS_WAIT_RECEIVE, 'pay_status' => Pay::ISPAID, 'del' => 0])
|
||||
->where(Db::raw("shipping_time+$finish_limit < $now"))
|
||||
->select();
|
||||
if (empty($orders)){
|
||||
return true;
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try{
|
||||
foreach ($orders as $order){
|
||||
Db::name('order')
|
||||
->where(['id' => $order['id']])
|
||||
->update([
|
||||
'order_status' => Order::STATUS_FINISH,
|
||||
'update_time' => $now,
|
||||
'confirm_take_time' => $now,
|
||||
]);
|
||||
|
||||
// 赠送成长值和积分
|
||||
Hook::listen('give_reward', [
|
||||
'order_id' => $order['id'],
|
||||
'scene' => 4, //4=订单结算
|
||||
]);
|
||||
|
||||
//订单日志
|
||||
OrderLogLogic::record(
|
||||
OrderLog::TYPE_SYSTEM,
|
||||
OrderLog::SYSTEM_CONFIRM_ORDER,
|
||||
$order['id'],
|
||||
0,
|
||||
OrderLog::SYSTEM_CONFIRM_ORDER
|
||||
);
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Exception $e){
|
||||
Log::write('订单自动确认失败,失败原因:'.$e->getMessage());
|
||||
Db::rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
152
application/common/command/TeamEnd.php
Normal file
152
application/common/command/TeamEnd.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
use app\common\logic\OrderRefundLogic;
|
||||
use app\common\model\Order;
|
||||
use app\common\model\OrderLog;
|
||||
use app\common\model\Pay;
|
||||
use app\common\model\Team;
|
||||
use app\common\model\TeamFollow;
|
||||
use app\common\model\TeamFound;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\facade\Log;
|
||||
|
||||
|
||||
class TeamEnd extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('team_end')
|
||||
->setDescription('结束已超时的拼团');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$now = time();
|
||||
|
||||
//关闭活动
|
||||
$activity = Db::name('team_activity')
|
||||
->where('end_time', '<=', $now)
|
||||
->select();
|
||||
//更新商品is_team
|
||||
$team_ids = array_column($activity, 'team_id');
|
||||
|
||||
Db::name('goods g')
|
||||
->join('team_goods_item i', 'i.goods_id = g.id')
|
||||
->where('i.team_id', 'in', $team_ids)
|
||||
->update(['is_team' => 0]);
|
||||
|
||||
Db::name('team_activity')
|
||||
->where('team_id', 'in', $team_ids)
|
||||
->update(['status' => 0]);
|
||||
|
||||
|
||||
$map1 = [
|
||||
['found_end_time', '<=', $now],
|
||||
['status', '=', 0]
|
||||
];
|
||||
|
||||
$map2 = [
|
||||
['team_id', 'in', $team_ids],
|
||||
['status', '=', 0]
|
||||
];
|
||||
//已过团结束时间,但未成团
|
||||
$lists = Db::name('team_found')
|
||||
->field('id')
|
||||
->whereOr([$map1, $map2])
|
||||
->select();
|
||||
|
||||
if (empty($lists)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//需要退款的团id
|
||||
$refound_found_ids = [];
|
||||
|
||||
//系统自动成团: 0-关闭; 1-开启
|
||||
$setting = ConfigServer::get('team', 'automatic', 0);
|
||||
|
||||
//更新拼团状态
|
||||
foreach ($lists as $item) {
|
||||
$found = TeamFound::get($item['id']);
|
||||
if ($found['join'] == $found['need'] || $setting == 1) {
|
||||
//人数凑齐,拼团成功 或者 系统自动成团
|
||||
$team_status = Team::STATUS_SUCCESS;
|
||||
} else {
|
||||
//人数不齐,拼团失败
|
||||
$team_status = Team::STATUS_ERROR;
|
||||
$refound_found_ids[] = $item['id'];
|
||||
}
|
||||
$found->status = $team_status;
|
||||
$found->team_end_time = time();
|
||||
$found->save();
|
||||
|
||||
TeamFollow::where(['found_id' => $item['id']])
|
||||
->update(['status' => $team_status, 'team_end_time' => time()]);
|
||||
}
|
||||
|
||||
if (empty($refound_found_ids)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//失败的订单才退款
|
||||
$orders = Db::name('order')
|
||||
->where(['team_found_id' => $refound_found_ids, 'del' => 0])
|
||||
->select();
|
||||
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
foreach ($orders as $order) {
|
||||
if ($order['order_status'] == Order::STATUS_CLOSE) {
|
||||
continue;
|
||||
}
|
||||
if ($order['pay_status'] == Pay::REFUNDED || $order['pay_status'] == Pay::UNPAID) {
|
||||
continue;
|
||||
}
|
||||
//取消订单
|
||||
OrderRefundLogic::cancelOrder($order['id'], OrderLog::TYPE_SYSTEM);
|
||||
//更新订单状态
|
||||
OrderRefundLogic::cancelOrderRefundUpdate($order);
|
||||
//订单退款
|
||||
OrderRefundLogic::refund($order, $order['order_amount'], $order['order_amount']);
|
||||
}
|
||||
Db::commit();
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
//错误记录
|
||||
Log::write('拼购退款失败:' . $e->getMessage());
|
||||
} catch (\EasyWeChat\Kernel\Exceptions\Exception $e) {
|
||||
Db::rollback();
|
||||
//错误记录
|
||||
Log::write('拼购退款失败:' . $e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
//错误记录
|
||||
Log::write('拼购退款失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
63
application/common/command/Update.php
Normal file
63
application/common/command/Update.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
use app\common\server\ConfigServer;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\Db;
|
||||
use think\facade\Config;
|
||||
use think\facade\Log;
|
||||
|
||||
class Update extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('update')
|
||||
->setDescription('更新代码、同步数据以后执行');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
//修改旧活动专区错误
|
||||
$lists = Db::name('activity_goods')->where(['del' => 0])->select();
|
||||
|
||||
$temp = [];
|
||||
$count = 0;
|
||||
|
||||
foreach ($lists as $k => $v) {
|
||||
$temp_key = $v['goods_id'].'_'.$v['activity_id'];
|
||||
if (in_array($temp_key, $temp)) {
|
||||
Db::name('activity_goods')
|
||||
->where(['del' => 0, 'id' => $v['id']])
|
||||
->update(['del' => 1]);
|
||||
$count += 1;
|
||||
} else {
|
||||
$temp[] = $temp_key;
|
||||
}
|
||||
}
|
||||
Log::write('处理活动专区错误,删除'.$count.'数据');
|
||||
|
||||
// 更新file_cate表中type=null值的旧记录
|
||||
Db::name('file_cate')->whereNull('type')->update(['type' => 1]);
|
||||
}
|
||||
|
||||
}
|
||||
94
application/common/command/UserDistribution.php
Normal file
94
application/common/command/UserDistribution.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
use app\common\model\Pay;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\Db;
|
||||
|
||||
class UserDistribution extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('user_distribution')
|
||||
->setDescription('更新会员分销信息');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$users = Db::name('user u')
|
||||
->field('d.*')
|
||||
->join('user_distribution d', 'd.user_id = u.id')
|
||||
->where(['u.del' => 0])
|
||||
->select();
|
||||
|
||||
if (!$users){
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($users as $user){
|
||||
|
||||
//粉丝数量
|
||||
$where1 = [
|
||||
['first_leader', '=', $user['user_id']],
|
||||
];
|
||||
$where2 = [
|
||||
['second_leader', '=', $user['user_id']],
|
||||
];
|
||||
$fans = Db::name('user')
|
||||
->whereOr([$where1,$where2])
|
||||
->count();
|
||||
|
||||
//分销订单信息
|
||||
$distribution = Db::name('distribution_order_goods')
|
||||
->field('sum(money) as money, count(id) as order_num')
|
||||
->where(['user_id' => $user['user_id']])
|
||||
->find();
|
||||
|
||||
//订单信息
|
||||
$order = Db::name('order')
|
||||
->field('sum(order_amount) as order_amount, count(id) as order_num')
|
||||
->where([
|
||||
'user_id' => $user['user_id'],
|
||||
'pay_status' => Pay::ISPAID,
|
||||
'refund_status' => 0
|
||||
])
|
||||
->find();
|
||||
|
||||
|
||||
$data = [
|
||||
'distribution_order_num' => $distribution['order_num'] ?? 0,
|
||||
'distribution_money' => $distribution['money'] ?? 0,
|
||||
'order_num' => $order['order_num'] ?? 0,
|
||||
'order_amount' => $order['order_amount'] ?? 0,
|
||||
'fans' => $fans,
|
||||
'update_time' => time(),
|
||||
];
|
||||
|
||||
//更新会员分销信息表
|
||||
Db::name('user_distribution')
|
||||
->where('user_id', $user['user_id'])
|
||||
->update($data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
81
application/common/logic/AccountLogLogic.php
Normal file
81
application/common/logic/AccountLogLogic.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\logic;
|
||||
use app\common\model\User;
|
||||
use app\common\model\AccountLog;
|
||||
|
||||
class AccountLogLogic{
|
||||
/**
|
||||
* Notes:记录会员账户流水,如果变动类型是成长值,且是增加的,则调用更新会员等级方法。该方法应在添加用户账户后调用
|
||||
* @author: cjh 2020/12/15 11:49
|
||||
* @param int $user_id 用户id
|
||||
* @param float $amount 变动数量
|
||||
* @param int $change_type 变动类型:1-增加;2-减少
|
||||
* @param int $source_type 来源类型
|
||||
* @param string $remark 说明
|
||||
* @param string $source_id 来源id
|
||||
* @param string $source_sn 来源单号
|
||||
* @param string $extra 额外字段说明
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function AccountRecord($user_id,$amount,$change_type,$source_type,$remark ='',$source_id ='',$source_sn='',$extra=''){
|
||||
$user = User::get($user_id);
|
||||
if(empty($user)){
|
||||
return false;
|
||||
}
|
||||
$type = AccountLog::getChangeType($source_type);
|
||||
$left_amount = '';
|
||||
switch ($type){
|
||||
case 'money':
|
||||
$left_amount = $user->user_money;
|
||||
break;
|
||||
case 'integral':
|
||||
$left_amount = $user->user_integral;
|
||||
break;
|
||||
case 'growth':
|
||||
$left_amount = $user->user_growth;
|
||||
break;
|
||||
case 'earnings':
|
||||
$left_amount = $user->earnings;
|
||||
}
|
||||
$account_log = new AccountLog();
|
||||
$account_log->log_sn = createSn('account_log','log_sn','',4);
|
||||
$account_log->user_id = $user_id;
|
||||
$account_log->source_type = $source_type;
|
||||
$account_log->source_id = $source_id;
|
||||
$account_log->source_sn = $source_sn;
|
||||
$account_log->change_amount = $amount;
|
||||
$account_log->left_amount = $left_amount;
|
||||
$account_log->remark = AccountLog::getRemarkDesc($source_type,$source_sn,$remark);
|
||||
$account_log->extra = $extra;
|
||||
$account_log->change_type = $change_type;
|
||||
$account_log->create_time = time();
|
||||
$account_log->save();
|
||||
|
||||
//更新会员等级
|
||||
if($type === 'growth' && $change_type == 1){
|
||||
UserLevelLogic::updateUserLevel($user_id);
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
51
application/common/logic/AfterSaleLogLogic.php
Normal file
51
application/common/logic/AfterSaleLogLogic.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\model\AfterSaleLog;
|
||||
|
||||
/**
|
||||
* 售后记录日志
|
||||
* Class AfterSaleLogLogic
|
||||
* @package app\common\logic
|
||||
*/
|
||||
class AfterSaleLogLogic
|
||||
{
|
||||
public static function record($type, $channel, $order_id, $after_sale_id, $handle_id, $content, $desc = '')
|
||||
{
|
||||
if (empty($content)) {
|
||||
return true;
|
||||
}
|
||||
$log = new AfterSaleLog();
|
||||
$log->type = $type;
|
||||
$log->channel = $channel;
|
||||
$log->order_id = $order_id;
|
||||
$log->after_sale_id = $after_sale_id;
|
||||
$log->handle_id = $handle_id;
|
||||
$log->content = AfterSaleLog::getLogDesc($content);
|
||||
$log->create_time = time();
|
||||
|
||||
if ($desc != ''){
|
||||
$log->content = AfterSaleLog::getLogDesc($content).'('.$desc.')';
|
||||
}
|
||||
|
||||
$log->save();
|
||||
}
|
||||
}
|
||||
44
application/common/logic/AliPayLogic.php
Normal file
44
application/common/logic/AliPayLogic.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\server\AliPayServer;
|
||||
|
||||
class AliPayLogic
|
||||
{
|
||||
|
||||
//支付宝app支付
|
||||
public static function appPay($order)
|
||||
{
|
||||
$data = [
|
||||
'body'=>'商品简述',
|
||||
'subject'=>'商品名',
|
||||
'out_trade_no'=> $order['sn'],
|
||||
'timeout_express'=>'30m',
|
||||
'total_amount'=> $order['order_amount'],
|
||||
'product_code'=>'FAST_INSTANT_TRADE_PAY'
|
||||
];
|
||||
$notify_url = 'http://tp.test/api/index/notify';
|
||||
|
||||
$alipay = new AliPayServer();
|
||||
return $alipay->appAlipay($data, $notify_url);
|
||||
}
|
||||
}
|
||||
96
application/common/logic/CouponLogic.php
Normal file
96
application/common/logic/CouponLogic.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\logic;
|
||||
use think\Db;
|
||||
|
||||
class CouponLogic {
|
||||
public static function couponClose($user_id = ''){
|
||||
$coupon_list = Db::name('coupon')
|
||||
->where(['del'=>0])
|
||||
->column('id,use_time_type,use_time_start,use_time_end,use_time','id');
|
||||
|
||||
$coupon_ids = array_keys($coupon_list);
|
||||
$where[] = ['coupon_id','in',$coupon_ids];
|
||||
$where[] = ['status','in',0];
|
||||
if($user_id){
|
||||
$where[] = ['user_id','=',$user_id];
|
||||
}
|
||||
$user_coupon_list = Db::name('coupon_list')
|
||||
->where(['coupon_id'=>$coupon_ids,'status'=>0])
|
||||
->field('id,coupon_id,create_time')
|
||||
->order('id asc')
|
||||
->select();
|
||||
|
||||
$now = time();
|
||||
$update_data = [];
|
||||
foreach ($user_coupon_list as $coupon_item){
|
||||
$coupon = $coupon_list[$coupon_item['coupon_id']] ?? [];
|
||||
if($coupon){
|
||||
//用券时间类型:1-固定时间;2-领券当天起;3-领券次日起
|
||||
switch ($coupon['use_time_type']){
|
||||
case 1:
|
||||
if($now > $coupon['use_time_end']){
|
||||
$update_data[] = $coupon_item['id'];
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
$daytime = strtotime(date("Y-m-d",$coupon_item['create_time'])) + 86400 * $coupon['use_time'];
|
||||
if($now > $daytime){
|
||||
$update_data[] = $coupon_item['id'];
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
$day = $coupon['use_time'] + 2;
|
||||
$daytime = strtotime(date("Y-m-d",$coupon_item['create_time'])) + 86400 * $day;
|
||||
if($now > $daytime){
|
||||
$update_data[] = $coupon_item['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($update_data){
|
||||
Db::name('coupon_list')->where(['id'=>$update_data])->update(['status'=>2,'update_time'=>$now]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Desc: 使用优惠券
|
||||
* @param $coupon_list_id
|
||||
* @param $order_id
|
||||
* @throws \think\Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function handleCouponByOrder($coupon_list_id, $order_id)
|
||||
{
|
||||
$update_coupon = [
|
||||
'status' => 1,
|
||||
'use_time' => time(),
|
||||
'order_id' => $order_id,
|
||||
'update_time' => time(),
|
||||
];
|
||||
|
||||
Db::name('coupon_list')
|
||||
->where('id', $coupon_list_id)
|
||||
->update($update_coupon);
|
||||
}
|
||||
}
|
||||
188
application/common/logic/FileCateLogic.php
Normal file
188
application/common/logic/FileCateLogic.php
Normal file
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
|
||||
use think\Db;
|
||||
|
||||
class FileCateLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* Desc: 详情
|
||||
* @param $id
|
||||
* @return array|\PDOStatement|string|\think\Model|null
|
||||
*/
|
||||
public static function info($id)
|
||||
{
|
||||
return Db::name('file_cate')->where(['id' => $id])->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc: 添加分类
|
||||
* @param $post
|
||||
* @return bool
|
||||
*/
|
||||
public static function add($post)
|
||||
{
|
||||
$level = 0;
|
||||
|
||||
if ($post['pid']) {
|
||||
$level = Db::name('file_cate')
|
||||
->where(['id' => $post['pid']])
|
||||
->where(['del' => 0])
|
||||
->value('level');
|
||||
}
|
||||
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'pid' => $post['pid'],
|
||||
'sort' => $post['sort'],
|
||||
'level' => $level + 1,
|
||||
'create_time' => time(),
|
||||
'type' => 1
|
||||
];
|
||||
Db::name('file_cate')->insert($data);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc: 编辑分类
|
||||
* @param $post
|
||||
* @return bool
|
||||
*/
|
||||
public static function edit($post)
|
||||
{
|
||||
$level = 0;
|
||||
$data = [
|
||||
'pid' => $post['pid'],
|
||||
'name' => $post['name'],
|
||||
'sort' => $post['sort'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
|
||||
if ($post['pid']) {
|
||||
$level = Db::name('file_cate')
|
||||
->where(['id' => $post['pid']])
|
||||
->where(['del' => 0])
|
||||
->value('level');
|
||||
}
|
||||
|
||||
$data['level'] = $level + 1;
|
||||
|
||||
Db::name('file_cate')->where('id', $post['id'])->update($data);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Desc: 删除
|
||||
* @param $id
|
||||
* @return int|string
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
$data = [
|
||||
'del' => 1,
|
||||
'update_time' => time(),
|
||||
];
|
||||
return Db::name('file_cate')->where(['del' => 0, 'id' => $id])->update($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Desc: 树形结构
|
||||
* @return array
|
||||
*/
|
||||
public static function cateTree()
|
||||
{
|
||||
$lists = Db::name('file_cate')
|
||||
->where(['del' => 0, 'type'=>1])
|
||||
->order('sort')
|
||||
->select();
|
||||
|
||||
$tree = self::cateListToTree($lists, 0);
|
||||
$all = [
|
||||
'id' => 0,
|
||||
'field' => 'all',
|
||||
'title' => '全部',
|
||||
'children' => [],
|
||||
];
|
||||
array_unshift($tree,$all);
|
||||
return $tree;
|
||||
}
|
||||
|
||||
|
||||
public static function cateListToTree($lists, $pid = 0)
|
||||
{
|
||||
$tree = [];
|
||||
foreach ($lists as $k => $v) {
|
||||
if ($v['pid'] == $pid) {
|
||||
$temp['id'] = $v['id'];
|
||||
$temp['field'] = 'id';
|
||||
$temp['title'] = self::handleFileName($v['name'], 4);
|
||||
$temp['children'] = self::cateListToTree($lists, $v['id']);
|
||||
$temp['spread'] = true;
|
||||
$tree[] = $temp;
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Desc: 下拉框树状结构
|
||||
* @return array
|
||||
*/
|
||||
public static function categoryToSelect()
|
||||
{
|
||||
$lists = Db::name('file_cate')
|
||||
->where(['del' => 0])
|
||||
->order('sort')
|
||||
->select();
|
||||
|
||||
$tree = [];
|
||||
foreach ($lists as $val) {
|
||||
|
||||
if ($val['pid'] != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tree[$val['id']] = "|----" . $val['name'];
|
||||
foreach ($lists as $val2) {
|
||||
if ($val2['pid'] == $val['id']) {
|
||||
$tree[$val2['id']] = "|--------" . $val2['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
|
||||
//分类名超出隐藏
|
||||
public static function handleFileName($str, $length)
|
||||
{
|
||||
if (mb_strlen($str) > $length) {
|
||||
return mb_substr($str,0, $length) . '..';
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
}
|
||||
236
application/common/logic/IntegralLogic.php
Normal file
236
application/common/logic/IntegralLogic.php
Normal file
@@ -0,0 +1,236 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\api\model\User;
|
||||
use app\common\model\AccountLog;
|
||||
use app\common\model\OrderGoods;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\Db;
|
||||
|
||||
class IntegralLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 订单是否开启积分抵扣
|
||||
* @param $order_goods
|
||||
* @author 段誉(2021/4/1 11:05)
|
||||
* @return bool
|
||||
*/
|
||||
public static function isIntegralInOrder($order_goods)
|
||||
{
|
||||
$integral_switch = ConfigServer::get('marketing', 'integral_deduction_status', 0);
|
||||
|
||||
if ($integral_switch == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($order_goods as $good) {
|
||||
if ($good['is_integral'] != 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Desc: 处理积分
|
||||
* @param $user_id
|
||||
* @param $use_integral
|
||||
* @param $channel
|
||||
* @param $source_id
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function handleIntegral($user_id, $use_integral, $channel, $source_id)
|
||||
{
|
||||
$user = User::get($user_id);
|
||||
switch ($channel) {
|
||||
//下单积分抵扣
|
||||
case AccountLog::order_deduction_integral:
|
||||
$user->user_integral = ['dec', $use_integral];
|
||||
$change_type = 2;
|
||||
break;
|
||||
|
||||
//取消订单退回积分
|
||||
case AccountLog::cancel_order_refund_integral:
|
||||
$user->user_integral = ['inc', $use_integral];
|
||||
$change_type = 1;
|
||||
break;
|
||||
|
||||
//下单奖励积分(每天一单)
|
||||
case AccountLog::order_add_integral:
|
||||
$user->user_integral = ['inc', $use_integral];
|
||||
$change_type = 1;
|
||||
break;
|
||||
|
||||
//扣除首单积分奖励(用户取消订单)
|
||||
case AccountLog::deduct_order_first_integral:
|
||||
$diff = $user->user_integral - $use_integral;
|
||||
if ($diff < 0) {
|
||||
$user->user_integral = 0;
|
||||
} else {
|
||||
$user->user_integral = ['dec', $use_integral];
|
||||
}
|
||||
$change_type = 2;
|
||||
break;
|
||||
|
||||
//购买商品赠送积分
|
||||
case AccountLog::order_goods_give_integral:
|
||||
$user->user_integral = ['inc', $use_integral];
|
||||
$change_type = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
$user->save();
|
||||
//更新积分记录
|
||||
AccountLogLogic::AccountRecord($user_id, $use_integral, $change_type, $channel, '', $source_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Desc: 下单奖励积分(每天第一单)
|
||||
* @param $user_id
|
||||
* @param $order_id
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function rewardIntegral($user_id, $order_id)
|
||||
{
|
||||
//是否为当天第一个订单(是->奖励积分)
|
||||
$check = Db::name('account_log')
|
||||
->where(['user_id' => $user_id, 'source_type' => AccountLog::order_add_integral])
|
||||
->whereTime('create_time', 'today')
|
||||
->find();
|
||||
|
||||
//下单奖励开关;0-关闭;1-开启;
|
||||
$order_award_integral = ConfigServer::get('marketing', 'order_award_integral', 0);
|
||||
if ($order_award_integral == 0 || $check) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::handleIntegral($user_id, $order_award_integral, AccountLog::order_add_integral, $order_id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 扣除首单积分
|
||||
* @param $user_id
|
||||
* @param $order_id
|
||||
* @author 段誉(2021/2/25 10:23)
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function backIntegral($user_id, $order_id)
|
||||
{
|
||||
$log = Db::name('account_log')
|
||||
->where([
|
||||
'user_id' => $user_id,
|
||||
'source_type' => AccountLog::order_add_integral,
|
||||
'source_id' => $order_id
|
||||
])
|
||||
->find();
|
||||
|
||||
if (!$log){
|
||||
return false;
|
||||
}
|
||||
|
||||
self::handleIntegral($user_id, $log['change_amount'], AccountLog::deduct_order_first_integral, $order_id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 购买商品奖励积分
|
||||
* @param $user_id
|
||||
* @param $order_id
|
||||
* @author 段誉(2021/4/1 11:06)
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function rewardIntegralByGoods($user_id, $order_id)
|
||||
{
|
||||
$goods_model = new OrderGoods();
|
||||
$goods = $goods_model->alias('og')
|
||||
->field('g.*,og.total_pay_price')
|
||||
->join('goods g', 'g.id = og.goods_id')
|
||||
->where(['order_id' => $order_id])
|
||||
->select();
|
||||
|
||||
$get_integral = 0;//可得积分
|
||||
|
||||
foreach ($goods as $good) {
|
||||
//赠送积分类型:0-不赠送;1-赠送固定积分;2-按比例赠送积分'
|
||||
if ($good['give_integral_type'] == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$good['give_integral'] = empty($good['give_integral']) ? 0 : intval($good['give_integral']);
|
||||
|
||||
if ($good['give_integral_type'] == 1) {
|
||||
$get_integral += $good['give_integral'];
|
||||
}
|
||||
|
||||
if ($good['give_integral_type'] == 2) {
|
||||
$get_integral += $good['give_integral'] * $good['total_pay_price'] / 100;
|
||||
}
|
||||
}
|
||||
|
||||
if ($get_integral <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
//用户赠送积分
|
||||
self::handleIntegral($user_id, $get_integral, AccountLog::order_goods_give_integral, $order_id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 积分抵扣描述
|
||||
* @param $integral_config
|
||||
* @param $integral_limit
|
||||
* @author 段誉(2021/5/19 18:32)
|
||||
* @return string
|
||||
*/
|
||||
public static function getIntegralDesc($integral_config, $integral_limit)
|
||||
{
|
||||
if ($integral_config <= 0) {
|
||||
return '积分不可抵扣';
|
||||
}
|
||||
$integral_desc = $integral_config.'积分可抵扣1元';
|
||||
if ($integral_limit > 0) {
|
||||
$integral_desc .= ',单次抵扣积分不能低于'.$integral_limit;
|
||||
}
|
||||
return $integral_desc;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
37
application/common/logic/LogicBase.php
Normal file
37
application/common/logic/LogicBase.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
|
||||
class LogicBase
|
||||
{
|
||||
public static function dataSuccess($msg = '', $data = [], $code = 1, $show = 0)
|
||||
{
|
||||
return data_success($msg, $data, $code, $show);
|
||||
}
|
||||
|
||||
|
||||
public static function dataError($msg = '', $data = [], $code = 0, $show = 1)
|
||||
{
|
||||
return data_error($msg, $data, $code, $show);
|
||||
}
|
||||
|
||||
}
|
||||
203
application/common/logic/NoticeLogic.php
Normal file
203
application/common/logic/NoticeLogic.php
Normal file
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
|
||||
use app\common\model\NoticeSetting;
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\server\UrlServer;
|
||||
use think\Db;
|
||||
|
||||
class NoticeLogic
|
||||
{
|
||||
|
||||
//添加通知记录
|
||||
public static function addNoticeLog($params, $scene_info, $send_type, $content, $extra = '')
|
||||
{
|
||||
return Db::name('notice')->insertGetId([
|
||||
'user_id' => $params['user_id'] ?? 0,
|
||||
'title' => self::getTitleByScene($send_type, $scene_info),
|
||||
'content' => $content,
|
||||
'scene' => $params['scene'],
|
||||
'receive_type' => self::getReceiveTypeByScene($params['scene']),
|
||||
'send_type' => $send_type,
|
||||
'extra' => $extra,
|
||||
'create_time' => time()
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
//更新通知记录
|
||||
public static function updateNotice($notice_id, $extra)
|
||||
{
|
||||
return Db::name('notice')
|
||||
->where('id', $notice_id)
|
||||
->update(['extra' => $extra]);
|
||||
}
|
||||
|
||||
|
||||
//格式化消息内容(替换文本)
|
||||
public static function contentFormat($content, $params)
|
||||
{
|
||||
foreach ($params as $k => $v) {
|
||||
$search_replace = '{'.$k.'}';
|
||||
$content = str_replace($search_replace, $v, $content);
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
||||
//根据不同发送类型获取标题
|
||||
public static function getTitleByScene($send_type, $scene_info)
|
||||
{
|
||||
$title = '';
|
||||
switch ($send_type) {
|
||||
case NoticeSetting::SYSTEM_NOTICE:
|
||||
$title = $scene_info['system_notice']['title'] ?? '';
|
||||
break;
|
||||
case NoticeSetting::SMS_NOTICE:
|
||||
$title = '';
|
||||
break;
|
||||
case NoticeSetting::OA_NOTICE:
|
||||
$title = $scene_info['oa_notice']['name'] ?? '';
|
||||
break;
|
||||
case NoticeSetting::MNP_NOTICE:
|
||||
$title = $scene_info['mnp_notice']['name'] ?? '';
|
||||
break;
|
||||
}
|
||||
return $title;
|
||||
}
|
||||
|
||||
|
||||
//根据场景返回当前接收对象
|
||||
public static function getReceiveTypeByScene($scene)
|
||||
{
|
||||
if (in_array($scene, NoticeSetting::NOTICE_PLATFORM_SCENE)) {
|
||||
return NoticeSetting::NOTICE_PLATFORM;
|
||||
}
|
||||
|
||||
if (in_array($scene, NoticeSetting::NOTICE_USER_SCENE)) {
|
||||
return NoticeSetting::NOTICE_USER;
|
||||
}
|
||||
|
||||
if (in_array($scene, NoticeSetting::NOTICE_OTHER_SCENE)) {
|
||||
return NoticeSetting::NOTICE_OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//================================================================================================
|
||||
|
||||
|
||||
//消息主页
|
||||
public static function index($user_id)
|
||||
{
|
||||
//最新系统消息
|
||||
$server = Db::name('notice')
|
||||
->where('scene', '<>', NoticeSetting::GET_EARNINGS_NOTICE)
|
||||
->where(['user_id' => $user_id, 'send_type' => NoticeSetting::SYSTEM_NOTICE])
|
||||
->order('id desc')
|
||||
->find();
|
||||
|
||||
//最新收益通知
|
||||
$earning = Db::name('notice')
|
||||
->where('scene', NoticeSetting::GET_EARNINGS_NOTICE)
|
||||
->where(['user_id' => $user_id, 'send_type' => NoticeSetting::SYSTEM_NOTICE])
|
||||
->order('id desc')
|
||||
->find();
|
||||
|
||||
$data['system'] = [
|
||||
'title' => '系统通知',
|
||||
'content' => $server['content'] ?? '暂无系统消息',
|
||||
'img' => UrlServer::getFileUrl(ConfigServer::get('website', 'system_notice')),
|
||||
'type' => 'system',
|
||||
];
|
||||
|
||||
$data['earning'] = [
|
||||
'title' => '收益通知',
|
||||
'content' => $earning['content'] ?? '暂无收益消息',
|
||||
'img' => UrlServer::getFileUrl(ConfigServer::get('website', 'earning_notice')),
|
||||
'type' => 'earning',
|
||||
];
|
||||
$res = array_values($data);
|
||||
return $res;
|
||||
}
|
||||
|
||||
//消息列表
|
||||
public static function lists($user_id, $type, $page, $size)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['user_id', '=', $user_id];
|
||||
$where[] = ['send_type', '=', NoticeSetting::SYSTEM_NOTICE];
|
||||
|
||||
if ($type == 'earning') {
|
||||
$where[] = ['scene', '=', NoticeSetting::GET_EARNINGS_NOTICE];
|
||||
}else{
|
||||
$where[] = ['scene', '<>', NoticeSetting::GET_EARNINGS_NOTICE];
|
||||
}
|
||||
|
||||
$count = Db::name('notice')->where($where)->count();
|
||||
|
||||
$lists = Db::name('notice')
|
||||
->where($where)
|
||||
->order('id desc')
|
||||
->page($page, $size)
|
||||
->select();
|
||||
|
||||
foreach ($lists as $k => $item) {
|
||||
$lists[$k]['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
|
||||
$lists[$k]['type'] = NoticeSetting::getSceneDesc(($item['scene']));
|
||||
}
|
||||
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $page,
|
||||
'size' => $size,
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $page, $size)
|
||||
];
|
||||
self::setRead($where);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
//更新为已读
|
||||
public static function setRead($where)
|
||||
{
|
||||
//进入列表后全部已读
|
||||
Db::name('notice')
|
||||
->where($where)
|
||||
->where('read','<>', 1)
|
||||
->update(['read' => 1]);
|
||||
}
|
||||
|
||||
//是否有未读的消息
|
||||
public static function unRead($user_id)
|
||||
{
|
||||
$un_read = Db::name('notice')
|
||||
->where(['user_id' => $user_id, 'read' => 0])
|
||||
->where(['send_type' => NoticeSetting::SYSTEM_NOTICE])
|
||||
->find();
|
||||
if ($un_read){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
141
application/common/logic/OrderGoodsLogic.php
Normal file
141
application/common/logic/OrderGoodsLogic.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
|
||||
use app\api\logic\SeckillLogic;
|
||||
use app\common\model\Pay;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 订单商品逻辑
|
||||
* Class OrderGoodsLogic
|
||||
* @package app\common\logic
|
||||
*/
|
||||
class OrderGoodsLogic
|
||||
{
|
||||
//返回订单库存,销量
|
||||
public static function backStock($order_goods, $pay_status)
|
||||
{
|
||||
$deduct_type = ConfigServer::get('trading', 'deduct_type', 1);
|
||||
//支付后扣减
|
||||
if ($deduct_type == 0 && $pay_status == Pay::UNPAID) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($order_goods as $good) {
|
||||
//回退库存,回退规格库存,减少商品销量
|
||||
Db::name('goods')
|
||||
->where('id', $good['goods_id'])
|
||||
->update([
|
||||
// 'sales_sum' => Db::raw("sales_sum-" . $good['goods_num']),
|
||||
'stock' => Db::raw('stock+' . $good['goods_num'])
|
||||
]);
|
||||
|
||||
//补充规格表库存
|
||||
Db::name('goods_item')
|
||||
->where('id', $good['item_id'])
|
||||
->setInc('stock', $good['goods_num']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//下单扣除订单库存
|
||||
public static function decStock($goods)
|
||||
{
|
||||
$seckill_data = SeckillLogic::getSeckillGoods();
|
||||
$seckill = $seckill_data['seckill'];
|
||||
$seckill_goods = $seckill_data['seckill_goods'];
|
||||
|
||||
$goods_ids = [];
|
||||
|
||||
foreach ($goods as $k1 => $good) {
|
||||
$item_id = $good['item_id'];
|
||||
//扣除库存,扣除规格库存,增加商品销量
|
||||
Db::name('goods')
|
||||
->where('id', $good['goods_id'])
|
||||
->update([
|
||||
'sales_sum' => Db::raw("sales_sum+" . $good['goods_num']),
|
||||
'stock' => Db::raw('stock-' . $good['goods_num'])
|
||||
]);
|
||||
|
||||
//扣除规格表库存
|
||||
Db::name('goods_item')
|
||||
->where('id', $item_id)
|
||||
->setDec('stock', $good['goods_num']);
|
||||
|
||||
//秒杀商品增加销量
|
||||
if (isset($seckill_goods[$item_id])){
|
||||
$seckill_goods_id = $seckill_goods[$item_id]['seckill_goods_id'];
|
||||
Db::name('seckill_goods')
|
||||
->where('id', $seckill_goods_id)
|
||||
->update([
|
||||
'sales_sum' => Db::raw("sales_sum+" . $good['goods_num']),
|
||||
'update_time' => time()
|
||||
]);
|
||||
}
|
||||
|
||||
$goods_ids[] = $good['goods_id'];
|
||||
}
|
||||
|
||||
//下架商品总库存为0的商品
|
||||
if (!empty($goods_ids)){
|
||||
self::outGoods($goods_ids);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 下单后下架商品总库存为0的商品
|
||||
* @param $goods_id
|
||||
* @author 段誉(2021/3/19 16:19)
|
||||
* @return bool
|
||||
*/
|
||||
public static function outGoods($goods_ids)
|
||||
{
|
||||
try{
|
||||
$goods = Db::name('goods')
|
||||
->field('id, stock')
|
||||
->where('id', 'in', $goods_ids)
|
||||
->select();
|
||||
|
||||
if (empty($goods)){
|
||||
return true;
|
||||
}
|
||||
|
||||
$need_handle_ids = [];
|
||||
foreach ($goods as $good) {
|
||||
if ($good['stock'] <= 0) {
|
||||
$need_handle_ids[] = $good['id'];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($need_handle_ids)){
|
||||
return true;
|
||||
}
|
||||
//下架订单商品中 商品总库存已为0的商品
|
||||
Db::name('goods')->where('id', 'in', $need_handle_ids)->update(['status' => 0]);
|
||||
|
||||
} catch (\Exception $e) {}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
50
application/common/logic/OrderLogLogic.php
Normal file
50
application/common/logic/OrderLogLogic.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\model\OrderLog;
|
||||
|
||||
/**
|
||||
* 订单记录日志
|
||||
* Class OrderLogLogic
|
||||
* @package app\common\logic
|
||||
*/
|
||||
class OrderLogLogic
|
||||
{
|
||||
public static function record($type, $channel, $order_id, $handle_id, $content, $desc = '')
|
||||
{
|
||||
if (empty($content)) {
|
||||
return true;
|
||||
}
|
||||
$log = new OrderLog();
|
||||
$log->type = $type;
|
||||
$log->order_id = $order_id;
|
||||
$log->channel = $channel;
|
||||
$log->handle_id = $handle_id;
|
||||
$log->content = OrderLog::getLogDesc($content);
|
||||
$log->create_time = time();
|
||||
|
||||
if ($desc != '') {
|
||||
$log->content = OrderLog::getLogDesc($content) . '(' . $desc . ')';
|
||||
}
|
||||
|
||||
$log->save();
|
||||
}
|
||||
}
|
||||
349
application/common/logic/OrderRefundLogic.php
Normal file
349
application/common/logic/OrderRefundLogic.php
Normal file
@@ -0,0 +1,349 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
|
||||
use app\api\logic\DistributionLogic;
|
||||
use app\api\model\Order;
|
||||
use app\common\model\AccountLog;
|
||||
use app\common\model\Order as CommonOrder;
|
||||
use app\common\model\OrderGoods;
|
||||
use app\common\model\OrderLog;
|
||||
use app\common\model\Pay;
|
||||
use app\common\model\User;
|
||||
use app\common\server\AliPayServer;
|
||||
use app\common\server\WeChatPayServer;
|
||||
use app\common\server\WeChatServer;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\facade\Hook;
|
||||
|
||||
/**
|
||||
* 订单退款逻辑
|
||||
* Class OrderRefundLogic
|
||||
* @package app\common\logic
|
||||
*/
|
||||
class OrderRefundLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 取消订单
|
||||
* @param $order_id
|
||||
* @param int $handle_type
|
||||
* @param int $handle_id
|
||||
* @author 段誉(2021/1/28 15:23)
|
||||
* @return Order
|
||||
*/
|
||||
public static function cancelOrder($order_id, $handle_type = OrderLog::TYPE_SYSTEM, $handle_id = 0)
|
||||
{
|
||||
//更新订单状态
|
||||
$order = Order::get($order_id);
|
||||
$order->order_status = CommonOrder::STATUS_CLOSE;
|
||||
$order->update_time = time();
|
||||
$order->cancel_time = time();
|
||||
$order->save();
|
||||
|
||||
//取消订单后操作
|
||||
Hook::listen('cancel_order', ['order_id' => $order_id, 'handle_id' => $handle_id, 'handle_type' => $handle_type]);
|
||||
return $order;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 处理订单退款(事务在取消订单逻辑处)
|
||||
* @param $order
|
||||
* @param $order_amount
|
||||
* @param $refund_amount
|
||||
* @author 段誉(2021/1/28 15:23)
|
||||
* @throws Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function refund($order, $order_amount, $refund_amount)
|
||||
{
|
||||
//退款记录
|
||||
$refund_id = self::addRefundLog($order, $order_amount, $refund_amount);
|
||||
|
||||
switch ($order['pay_way']) {
|
||||
//余额退款
|
||||
case Pay::BALANCE_PAY:
|
||||
self::balancePayRefund($order, $refund_amount);
|
||||
break;
|
||||
//微信退款
|
||||
case Pay::WECHAT_PAY:
|
||||
self::wechatPayRefund($order, $refund_id);
|
||||
break;
|
||||
//支付宝退款
|
||||
case Pay::ALI_PAY:
|
||||
self::aliPayRefund($order, $refund_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 微信支付退款
|
||||
* @param $order (订单信息)
|
||||
* @param $refund_id (退款记录id)
|
||||
* @author 段誉(2021/1/27 16:04)
|
||||
* @throws Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function wechatPayRefund($order, $refund_id)
|
||||
{
|
||||
$config = WeChatServer::getPayConfigBySource($order['order_source'])['config'];
|
||||
|
||||
if (empty($config)) {
|
||||
throw new Exception('请联系管理员设置微信相关配置!');
|
||||
}
|
||||
|
||||
if (!isset($config['cert_path']) || !isset($config['key_path'])) {
|
||||
throw new Exception('请联系管理员设置微信证书!');
|
||||
}
|
||||
|
||||
if (!file_exists($config['cert_path']) || !file_exists($config['key_path'])) {
|
||||
throw new Exception('微信证书不存在,请联系管理员!');
|
||||
}
|
||||
|
||||
$refund_log = Db::name('order_refund')->where(['id' => $refund_id])->find();
|
||||
|
||||
$data = [
|
||||
'transaction_id' => $order['transaction_id'],
|
||||
'refund_sn' => $refund_log['refund_sn'],
|
||||
'total_fee' => $refund_log['order_amount'] * 100,//订单金额,单位为分
|
||||
'refund_fee' => intval($refund_log['refund_amount'] * 100),//退款金额
|
||||
];
|
||||
$result = WeChatPayServer::refund($config, $data);
|
||||
|
||||
if (isset($result['return_code']) && $result['return_code'] == 'FAIL') {
|
||||
throw new Exception($result['return_msg']);
|
||||
}
|
||||
|
||||
if (isset($result['err_code_des'])) {
|
||||
throw new Exception($result['err_code_des']);
|
||||
}
|
||||
|
||||
if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
|
||||
$update_data = [
|
||||
'wechat_refund_id' => $result['refund_id'] ?? 0,
|
||||
'refund_msg' => json_encode($result, JSON_UNESCAPED_UNICODE),
|
||||
];
|
||||
//更新退款日志记录
|
||||
Db::name('order_refund')->where(['id' => $refund_id])->update($update_data);
|
||||
|
||||
} else {
|
||||
throw new Exception('微信支付退款失败');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 支付宝退款
|
||||
* @param $order
|
||||
* @param $refund_id
|
||||
* @author 段誉(2021/3/23 15:48)
|
||||
* @throws Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function aliPayRefund($order, $refund_id)
|
||||
{
|
||||
$result = (new AliPayServer())->refund($order['order_sn'], $order['order_amount']);
|
||||
$result = (array)$result;
|
||||
|
||||
if ($result['code'] == '10000' && $result['msg'] == 'Success' && $result['fundChange'] == 'Y') {
|
||||
//更新退款日志记录
|
||||
$update_data = ['refund_msg' => json_encode($result['httpBody'], JSON_UNESCAPED_UNICODE)];
|
||||
Db::name('order_refund')->where(['id' => $refund_id])->update($update_data);
|
||||
} else {
|
||||
throw new Exception('支付宝退款失败');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 增加退款记录
|
||||
* @param $order
|
||||
* @param $order_amount
|
||||
* @param $refund_amount
|
||||
* @param string $result_msg
|
||||
* @author 段誉(2021/1/28 15:23)
|
||||
* @return int|string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function addRefundLog($order, $order_amount, $refund_amount, $result_msg = '退款成功')
|
||||
{
|
||||
$data = [
|
||||
'order_id' => $order['id'],
|
||||
'user_id' => $order['user_id'],
|
||||
'refund_sn' => createSn('order_refund', 'refund_sn'),
|
||||
'order_amount' => $order_amount,
|
||||
'refund_amount' => $refund_amount,
|
||||
'transaction_id' => $order['transaction_id'],
|
||||
'create_time' => time(),
|
||||
'refund_status' => 1,
|
||||
'refund_at' => time(),
|
||||
'refund_msg' => json_encode($result_msg, JSON_UNESCAPED_UNICODE),
|
||||
];
|
||||
return Db::name('order_refund')->insertGetId($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 取消订单,退款后更新订单和订单商品信息
|
||||
* @param $order
|
||||
* @author 段誉(2021/1/28 14:21)
|
||||
* @throws Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function cancelOrderRefundUpdate($order)
|
||||
{
|
||||
//订单商品=>标记退款成功状态
|
||||
Db::name('order_goods')
|
||||
->where(['order_id' => $order['id']])
|
||||
->update(['refund_status' => OrderGoods::REFUND_STATUS_SUCCESS]);
|
||||
|
||||
//更新订单支付状态为已退款
|
||||
Db::name('order')->where(['id' => $order['id']])->update([
|
||||
'pay_status' => Pay::REFUNDED,
|
||||
'refund_status' => 2,//订单退款状态; 0-未退款;1-部分退款;2-全部退款
|
||||
'refund_amount' => $order['order_amount'],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes:售后退款更新订单或订单商品状态
|
||||
* @param $order
|
||||
* @param $order_goods_id
|
||||
* @author 段誉(2021/1/28 15:22)
|
||||
*/
|
||||
public static function afterSaleRefundUpdate($order, $order_goods_id, $admin_id = 0)
|
||||
{
|
||||
$order_goods = OrderGoods::get(['id' => $order_goods_id]);
|
||||
$order_goods->refund_status = OrderGoods::REFUND_STATUS_SUCCESS;//退款成功
|
||||
$order_goods->save();
|
||||
|
||||
//更新订单状态
|
||||
$order = \app\common\model\Order::get(['id' => $order['id']]);
|
||||
$order->pay_status = Pay::REFUNDED;
|
||||
$order->refund_amount += $order_goods['total_pay_price'];//退款金额 + 以前的退款金额
|
||||
$order->refund_status = 1;//退款状态:0-未退款;1-部分退款;2-全部退款
|
||||
|
||||
//如果订单商品已全部退款
|
||||
if (self::checkOrderGoods($order['id'])) {
|
||||
$order->order_status = CommonOrder::STATUS_CLOSE;
|
||||
$order->refund_status = 2;
|
||||
|
||||
OrderLogLogic::record(
|
||||
OrderLog::TYPE_SHOP,
|
||||
OrderLog::SYSTEM_CANCEL_ORDER,
|
||||
$order['id'],
|
||||
$admin_id,
|
||||
OrderLog::SYSTEM_CANCEL_ORDER
|
||||
);
|
||||
}
|
||||
$order->save();
|
||||
|
||||
//更新相关分佣订单为已失效
|
||||
DistributionLogic::setFailByAfterSale($order_goods_id);
|
||||
}
|
||||
|
||||
|
||||
//订单内商品是否已全部
|
||||
public static function checkOrderGoods($order_id)
|
||||
{
|
||||
$order_goods = OrderGoods::where('order_id', $order_id)->select();
|
||||
if (empty($order_goods)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($order_goods as $item) {
|
||||
if ($item['refund_status'] != OrderGoods::REFUND_STATUS_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 余额退款
|
||||
* @param $order
|
||||
* @param $refund_amount
|
||||
* @author 段誉(2021/1/28 15:24)
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function balancePayRefund($order, $refund_amount)
|
||||
{
|
||||
$user = User::get($order['user_id']);
|
||||
$user->user_money = ['inc', $refund_amount];
|
||||
$user->save();
|
||||
|
||||
AccountLogLogic::AccountRecord(
|
||||
$order['user_id'],
|
||||
$refund_amount,
|
||||
1,
|
||||
AccountLog::cancel_order_refund,
|
||||
'',
|
||||
$order['id'],
|
||||
$order['order_sn']
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 退款失败增加错误记录
|
||||
* @param $order
|
||||
* @param $err_msg
|
||||
* @author 段誉(2021/1/28 15:24)
|
||||
* @return int|string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function addErrorRefund($order, $err_msg)
|
||||
{
|
||||
$refund_data = [
|
||||
'order_id' => $order['id'],
|
||||
'user_id' => $order['user_id'],
|
||||
'refund_sn' => createSn('order_refund', 'refund_sn'),
|
||||
'order_amount' => $order['order_amount'],//订单应付金额
|
||||
'refund_amount' => $order['order_amount'],//订单退款金额
|
||||
'transaction_id' => $order['transaction_id'],
|
||||
'create_time' => time(),
|
||||
'refund_status' => 2,
|
||||
'refund_msg' => json_encode($err_msg, JSON_UNESCAPED_UNICODE),
|
||||
];
|
||||
return Db::name('order_refund')->insertGetId($refund_data);
|
||||
}
|
||||
|
||||
}
|
||||
201
application/common/logic/PayNotifyLogic.php
Normal file
201
application/common/logic/PayNotifyLogic.php
Normal file
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\api\logic\GoodsLogic;
|
||||
use app\api\logic\OrderLogic;
|
||||
use app\api\logic\TeamLogic;
|
||||
use app\common\model\{AccountLog, Footprint, MessageScene_, NoticeSetting, OrderLog, User, Pay, Order, OrderTrade};
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\server\DistributionServer;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\facade\Hook;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 支付成功后处理订单状态
|
||||
* Class PayNotifyLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class PayNotifyLogic
|
||||
{
|
||||
public static function handle($action, $order_sn, $extra = [])
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
self::$action($order_sn, $extra);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
$record = [
|
||||
__CLASS__, __FUNCTION__, $e->getFile(), $e->getLine(), $e->getMessage()
|
||||
];
|
||||
Log::record(implode('-', $record));
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//下单回调
|
||||
private static function order($order_sn, $extra = [])
|
||||
{
|
||||
$time = time();
|
||||
|
||||
$order_model = new Order();
|
||||
$order = $order_model
|
||||
->with('order_goods')
|
||||
->where('order_sn',$order_sn)
|
||||
->find();
|
||||
|
||||
//增加会员消费累计额度
|
||||
$user = User::get($order['user_id']);
|
||||
$user->total_order_amount = ['inc', $order['order_amount']];
|
||||
|
||||
//余额支付,扣除余额
|
||||
if ($order['pay_way'] == Pay::BALANCE_PAY) {
|
||||
$user->user_money = ['dec', $order['order_amount']];
|
||||
$user->save();
|
||||
AccountLogLogic::AccountRecord($order['user_id'], $order['order_amount'], 2, AccountLog::balance_pay_order, '', $order['id'], $order_sn);
|
||||
} else {
|
||||
$user->save();
|
||||
}
|
||||
|
||||
$order->pay_status = Pay::ISPAID;
|
||||
$order->pay_time = $time;
|
||||
$order->order_status = Order::STATUS_WAIT_DELIVERY;
|
||||
if (isset($extra['transaction_id'])) {
|
||||
$order->transaction_id = $extra['transaction_id'];
|
||||
}
|
||||
$order->save();
|
||||
|
||||
//扣除库存
|
||||
$deduct_type = ConfigServer::get('trading','deduct_type', 1);
|
||||
if ($deduct_type == 0) {
|
||||
//扣除库存,增加销量
|
||||
OrderGoodsLogic::decStock($order['order_goods']);
|
||||
}
|
||||
|
||||
//订单日志
|
||||
OrderLogLogic::record(
|
||||
OrderLog::TYPE_USER,
|
||||
OrderLog::USER_PAID_ORDER,
|
||||
$order['id'],
|
||||
$user['id'],
|
||||
OrderLog::USER_PAID_ORDER
|
||||
);
|
||||
|
||||
//拼团订单,更新拼团信息
|
||||
if ($order['order_type'] == Order::TEAM_ORDER){
|
||||
TeamLogic::updateTeam($order['id']);
|
||||
}
|
||||
|
||||
//拼购,砍价的订单不参与分销分佣
|
||||
if ($order['order_type'] == Order::NORMAL_ORDER){
|
||||
DistributionServer::commission($order['id']);
|
||||
}
|
||||
|
||||
|
||||
//发送通知
|
||||
Hook::listen('notice', [
|
||||
'user_id' => $user['id'],
|
||||
'order_id' => $order['id'],
|
||||
'scene' => NoticeSetting::ORDER_PAY_NOTICE,
|
||||
]);
|
||||
|
||||
|
||||
//短信通知
|
||||
Hook::listen('sms_send', [
|
||||
'key' => NoticeSetting::ORDER_PAY_NOTICE,
|
||||
'mobile' => $order->mobile,
|
||||
'user_id' => $user->id,
|
||||
'params' => [
|
||||
'nickname' => $user->nickname,
|
||||
'order_sn' => $order->order_sn,
|
||||
'order_amount' => $order->order_amount,
|
||||
'time' => $order->create_time,
|
||||
'total_num' => $order->total_num.'件',
|
||||
'goods_name' => omit_str(($order->order_goods[0]['goods_name'] ?? '商品'), 8)
|
||||
]
|
||||
]);
|
||||
|
||||
$order_contact_mobile = ConfigServer::get('order_message', 'order_contact_mobile');
|
||||
//平台短信通知
|
||||
if($order_contact_mobile) {
|
||||
Hook::listen('sms_send',[
|
||||
'key' => NoticeSetting::USER_PAID_NOTICE_PLATFORM,
|
||||
'mobile' => $order_contact_mobile,
|
||||
'params' => [
|
||||
'order_sn' => $order['order_sn'],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
// 赠送成长值和积分
|
||||
Hook::listen('give_reward', [
|
||||
'order_id' => $order['id'],
|
||||
'scene' => 1, //1=下单支付场景
|
||||
]);
|
||||
|
||||
// 钩子-记录足迹(下单结算)
|
||||
Hook::listen('footprint', [
|
||||
'type' => Footprint::place_order,
|
||||
'user_id' => $user['id'],
|
||||
'foreign_id' => $order['id'], //订单ID
|
||||
'total_money' => $order['order_amount'] //订单应付金额
|
||||
]);
|
||||
|
||||
//打印订单
|
||||
Hook::listen('printer', [
|
||||
'order_id' => $order['id'],
|
||||
]);
|
||||
|
||||
}
|
||||
/**
|
||||
* note 充值回调
|
||||
* create_time 2020/10/26 18:53
|
||||
*/
|
||||
private static function recharge($order_sn,$extra = []){
|
||||
$new = time();
|
||||
$order = Db::name('recharge_order')->where(['order_sn'=>$order_sn])->find();
|
||||
$update_data['pay_time'] = $new;
|
||||
$update_data['pay_status'] = Pay::ISPAID;
|
||||
if (isset($extra['transaction_id'])) {
|
||||
$update_data['transaction_id'] = $extra['transaction_id'];
|
||||
}
|
||||
Db::name('recharge_order')->where(['id'=>$order['id']])->update($update_data);
|
||||
$user = User::get($order['user_id']);
|
||||
$total_money = $order['order_amount']+$order['give_money'];
|
||||
$total_integral = $order['give_integral'];
|
||||
$user->user_money = ['inc', $total_money];
|
||||
$user->user_integral = ['inc', $total_integral];
|
||||
$user->user_growth = ['inc', $order['give_growth']];
|
||||
$user->total_recharge_amount = ['inc',$total_money];
|
||||
$user->save();
|
||||
//记录余额
|
||||
$total_money > 0 && AccountLogLogic::AccountRecord($user->id,$total_money,1, AccountLog::recharge_money);
|
||||
//记录积分
|
||||
$total_integral > 0 && AccountLogLogic::AccountRecord($user->id,$total_integral,1, AccountLog::recharge_give_integral);
|
||||
//记录成长值
|
||||
$order['give_growth'] > 0 &&AccountLogLogic::AccountRecord($user->id,$order['give_growth'],1, AccountLog::recharge_give_growth);
|
||||
}
|
||||
|
||||
}
|
||||
419
application/common/logic/PaymentLogic.php
Normal file
419
application/common/logic/PaymentLogic.php
Normal file
@@ -0,0 +1,419 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\server\AliPayServer;
|
||||
use app\common\server\WeChatPayServer;
|
||||
use app\common\model\{Client_, Order, Pay, User};
|
||||
use think\facade\Env;
|
||||
|
||||
class PaymentLogic extends LogicBase
|
||||
{
|
||||
|
||||
protected static $error = '';
|
||||
protected static $return_code = 0;
|
||||
|
||||
/**
|
||||
* Notes: 错误信息
|
||||
* @return string
|
||||
* @author 段誉(2021/2/1 11:19)
|
||||
*/
|
||||
public static function getError()
|
||||
{
|
||||
return self::$error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 返回状态码
|
||||
* @return int
|
||||
* @author 段誉(2021/2/1 11:19)
|
||||
*/
|
||||
public static function getReturnCode()
|
||||
{
|
||||
return self::$return_code;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 支付
|
||||
* @param $from
|
||||
* @param $order
|
||||
* @param $order_source
|
||||
* @return array|bool|string
|
||||
* @author 段誉(2021/2/1 11:19)
|
||||
*/
|
||||
public static function pay($from, $order, $order_source)
|
||||
{
|
||||
switch ($order['pay_way']) {
|
||||
case Pay::WECHAT_PAY:
|
||||
|
||||
$res = WeChatPayServer::unifiedOrder($from, $order, $order_source);
|
||||
if (false === $res) {
|
||||
self::$error = WeChatPayServer::getError();
|
||||
}
|
||||
break;
|
||||
|
||||
case Pay::ALI_PAY:
|
||||
|
||||
$aliPay = new AliPayServer();
|
||||
$res = $aliPay->pay($from, $order, $order_source);
|
||||
if(false === $res) {
|
||||
self::$error = $aliPay->getError();
|
||||
} else {
|
||||
self::$return_code = 20001;//特殊状态码,用于前端判断
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
$ttPay = new ttPay();
|
||||
$res = $ttPay->run('order',$order);
|
||||
|
||||
// $res = self::ttpay($order);
|
||||
if(!empty($res['data'])) {
|
||||
self::$return_code = 8888;//特殊状态码,用于前端判断
|
||||
$res = $res['data'];
|
||||
}else{
|
||||
self::$error = $res['err_tips'];
|
||||
$res = false;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
self::$error = '订单异常';
|
||||
$res = false;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
//抖音支付
|
||||
public static function ttpay($data)
|
||||
{
|
||||
$url = 'https://developer.toutiao.com/api/apps/ecpay/v1/create_order';
|
||||
$params['app_id'] = 'tt0523739e9a12236501';
|
||||
$params['out_order_no'] = (string)$data['order_sn'];
|
||||
$params['total_amount'] = (int)$data['order_amount'] * 100;
|
||||
$params['subject'] = 'subject';
|
||||
$params['body'] = 'body';
|
||||
$params['valid_time'] = 3600;
|
||||
|
||||
|
||||
$params['sign'] = self::ttsign($params,'ejAuHvbI472euyhb34aVyLD92ll9tgZCqWnMi0tX');
|
||||
|
||||
|
||||
$http = self::httpPost($url, $params);
|
||||
return json_decode($http,true);
|
||||
}
|
||||
|
||||
//curl
|
||||
public static function httpPost($url, $data = null)
|
||||
{
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
if (!$data) return false;
|
||||
if (is_array($data)) {
|
||||
$data = json_encode($data);
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($curl, CURLOPT_HEADER, 0);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/json; charset=utf-8',
|
||||
'Content-Length:' . strlen($data),
|
||||
'Cache-Control: no-cache',
|
||||
'Pragma: no-cache'
|
||||
));
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
$res = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
return $res;
|
||||
}
|
||||
// 签名
|
||||
public static function ttsign($map,$secret)
|
||||
{
|
||||
|
||||
$rList = [];
|
||||
foreach($map as $k =>$v) {
|
||||
if ($k == "other_settle_params" || $k == "app_id" || $k == "sign" || $k == "thirdparty_id")
|
||||
continue;
|
||||
|
||||
$value = trim(strval($v));
|
||||
|
||||
$len = strlen($value);
|
||||
if ($len > 1 && substr($value, 0,1)=="\"" && substr($value, $len-1)=="\"")
|
||||
$value = substr($value,1, $len-1);
|
||||
$value = trim($value);
|
||||
if ($value == "" || $value == "null")
|
||||
continue;
|
||||
$rList[] = $value;
|
||||
}
|
||||
$rList[] = $secret;
|
||||
sort($rList, SORT_STRING);
|
||||
|
||||
|
||||
return md5(implode('&', $rList));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 是否在白名单内支付
|
||||
* @param $user_id
|
||||
* @author 段誉(2021/2/24 10:01)
|
||||
* @return bool
|
||||
*/
|
||||
public static function isPayWhiteList($user_id)
|
||||
{
|
||||
$white_list = Env::get('wechat.white_list', '');
|
||||
$white_list = explode(',', $white_list);
|
||||
if (in_array($user_id, $white_list)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Class ttPay{
|
||||
|
||||
private $api_url='https://developer.toutiao.com/api/apps/ecpay/v1/';
|
||||
private $app_id;
|
||||
private $token;
|
||||
private $salt;
|
||||
|
||||
public function __construct() {
|
||||
$this->app_id = 'tt0523739e9a12236501';
|
||||
$this->token='123qazqweeesdflomswwe';
|
||||
$this->salt='ejAuHvbI472euyhb34aVyLD92ll9tgZCqWnMi0tX';
|
||||
// $this->salt='58280e4f36d88e93d7a4be9f0e590b2302a462c5';
|
||||
}
|
||||
|
||||
public function run($action,$order){
|
||||
$action=$action?$action:'order';
|
||||
if(!in_array($action,['order','query','refund','settle','notify','set'])){
|
||||
echo '非法请求';die;
|
||||
}
|
||||
return $this->$action($order);
|
||||
}
|
||||
|
||||
//下单
|
||||
private function order($order){
|
||||
$data=[
|
||||
'out_order_no'=>$order['order_sn'],
|
||||
'total_amount'=>(int)$order['order_amount'] * 100,
|
||||
'subject'=>'购买服务',
|
||||
'body'=>'购买商品',
|
||||
'valid_time'=>3600,
|
||||
];
|
||||
return $this->post('create_order',$data);
|
||||
|
||||
}
|
||||
|
||||
//查询订单
|
||||
private function query(){
|
||||
$data=[
|
||||
'out_order_no'=>'2021110117254573565'
|
||||
];
|
||||
$res=$this->post('query_order',$data,false);
|
||||
echo json_encode($res);die;
|
||||
}
|
||||
|
||||
//订单退款
|
||||
private function refund(){
|
||||
$data=[
|
||||
'out_order_no'=>'2021110118351347832',
|
||||
'out_refund_no'=>$this->order_number(),
|
||||
'reason'=>'退款原因',
|
||||
'refund_amount'=>1,
|
||||
];
|
||||
$res=$this->post('create_refund',$data);
|
||||
echo json_encode($res);die;
|
||||
}
|
||||
|
||||
//订单分账
|
||||
private function settle(){
|
||||
$data=[
|
||||
'out_order_no'=>'2021110118301265990',
|
||||
'out_settle_no'=>$this->order_number(),
|
||||
'settle_desc'=>'分账描述',
|
||||
'settle_params'=>json_encode([]),//分润方参数 如[['merchant_uid'=>'商户号','amount'=>'10']] 可以有多个分账商户
|
||||
];
|
||||
$res=$this->post('settle',$data);
|
||||
echo json_encode($res);die;
|
||||
}
|
||||
|
||||
//支付设置回调测试
|
||||
private function set(){
|
||||
$content=file_get_contents('php://input');
|
||||
$this->log('log.txt',$content);
|
||||
}
|
||||
|
||||
//回调
|
||||
private function notify(){
|
||||
$content=file_get_contents('php://input');
|
||||
if(empty($content)) return false;
|
||||
$this->log('notify.txt',$content);
|
||||
$content=json_decode($content,true);
|
||||
$sign=$this->handler($content);
|
||||
if($sign==$content['msg_signature']){
|
||||
$msg=json_decode($content['msg'],true);
|
||||
echo '回调----'.$content['type']."\n";
|
||||
//这里更新应用业务逻辑代码,使用$msg跟应用订单比对更新订单,可以用 $content['type']判断是支付回调还是退款回调,payment支付回调 refund退款回调。
|
||||
$res=['err_no'=>0,'err_tips'=>'success'];
|
||||
echo json_encode($res);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 测试订单号,实际应用根据自己应用实际生成
|
||||
* @return string
|
||||
*/
|
||||
private function order_number(){
|
||||
return date('YmdHis').rand(10000,99999);
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求小程序平台服务端
|
||||
* @param string $url 接口地址
|
||||
* @param array $data 参数内容
|
||||
* @param boolean $notify 是否有回调
|
||||
* @return array
|
||||
*/
|
||||
private function post($method,$data,$notify=true){
|
||||
$data['app_id']=$this->app_id;
|
||||
|
||||
$data['sign']=$this->sign($data);
|
||||
$url=$this->api_url.$method;
|
||||
$res=$this->http('POST',$url,json_encode($data),['Content-Type: application/json'],true);
|
||||
return json_decode($res,true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 回调验签
|
||||
* @param array $map 验签参数
|
||||
* @return stirng
|
||||
*/
|
||||
private function handler($map){
|
||||
$rList = array();
|
||||
array_push($rList, $this->token);
|
||||
foreach($map as $k =>$v) {
|
||||
if ( $k == "type" || $k=='msg_signature')
|
||||
continue;
|
||||
$value = trim(strval($v));
|
||||
if ($value == "" || $value == "null")
|
||||
continue;
|
||||
array_push($rList, $value);
|
||||
}
|
||||
sort($rList,2);
|
||||
return sha1(implode($rList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求签名
|
||||
* @param array $map 请求参数
|
||||
* @return stirng
|
||||
*/
|
||||
private function sign($map) {
|
||||
$rList = array();
|
||||
foreach($map as $k =>$v) {
|
||||
if ($k == "other_settle_params" || $k == "app_id" || $k == "sign" || $k == "thirdparty_id")
|
||||
continue;
|
||||
$value = trim(strval($v));
|
||||
$len = strlen($value);
|
||||
if ($len > 1 && substr($value, 0,1)=="\"" && substr($value,$len, $len-1)=="\"")
|
||||
$value = substr($value,1, $len-1);
|
||||
$value = trim($value);
|
||||
if ($value == "" || $value == "null")
|
||||
continue;
|
||||
array_push($rList, $value);
|
||||
}
|
||||
array_push($rList, $this->salt);
|
||||
sort($rList, 2);
|
||||
return md5(implode('&', $rList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 写日志
|
||||
* @param string $path 日志路径
|
||||
* @param string $content 内容
|
||||
*/
|
||||
private function log($path, $content){
|
||||
$file=fopen($path, "a");
|
||||
fwrite($file, date('Y-m-d H:i:s').'-----'.$content."\n");
|
||||
fclose($file);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 网络请求
|
||||
* @param stirng $method 请求模式
|
||||
* @param stirng $url请求网关
|
||||
* @param array $params 请求参数
|
||||
* @param stirng $header 自定义头
|
||||
* @param boolean $multi 文件上传
|
||||
* @return array
|
||||
*/
|
||||
private function http( $method = 'GET', $url,$params,$header = array(), $multi = false){
|
||||
|
||||
$opts = array(
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_RETURNTRANSFER => 1,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_SSL_VERIFYHOST => false,
|
||||
CURLOPT_HTTPHEADER => $header
|
||||
);
|
||||
/* 根据请求类型设置特定参数 */
|
||||
switch(strtoupper($method)){
|
||||
case 'GET':
|
||||
$opts[CURLOPT_URL] = $url . '?' . http_build_query($params);
|
||||
break;
|
||||
case 'POST':
|
||||
//判断是否传输文件
|
||||
$params = $multi ? $params : http_build_query($params);
|
||||
$opts[CURLOPT_URL] = $url;
|
||||
$opts[CURLOPT_POST] = 1;
|
||||
$opts[CURLOPT_POSTFIELDS] = $params;
|
||||
break;
|
||||
default:
|
||||
throw new Exception('不支持的请求方式!');
|
||||
}
|
||||
|
||||
/* 初始化并执行curl请求 */
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, $opts);
|
||||
$data = curl_exec($ch);
|
||||
$error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
if($error) throw new Exception('请求发生错误:' . $error);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
593
application/common/logic/QrCodeLogic.php
Normal file
593
application/common/logic/QrCodeLogic.php
Normal file
@@ -0,0 +1,593 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\logic;
|
||||
use app\common\server\ConfigServer;
|
||||
use app\common\server\storage\Driver as StorageDriver;
|
||||
use app\common\server\UrlServer;
|
||||
use app\common\server\WeChatServer;
|
||||
use Endroid\QrCode\QrCode;
|
||||
use think\facade\Cache;
|
||||
use think\Exception;
|
||||
use EasyWeChat\Factory;
|
||||
|
||||
class QrCodeLogic extends LogicBase{
|
||||
//商品图片配置
|
||||
public function goodsShareConfig(){
|
||||
return [
|
||||
//会员头像
|
||||
'head_pic' => [
|
||||
'w' => 64, 'h' => 64, 'x' => 40, 'y' => 20,
|
||||
],
|
||||
//会员昵称
|
||||
'nickname' => [
|
||||
'color' => '#555555', 'font_face' => ROOT_PATH .'/font/SourceHanSansCN-Regular.otf', 'font_size' => 19, 'x' => 120, 'y' => 60,
|
||||
],
|
||||
//标题
|
||||
'title' => [
|
||||
'color' => '#333333', 'font_face' => ROOT_PATH .'/font/SourceHanSansCN-Bold.otf', 'font_size' => 20, 'w' => 360, 'x' => 40, 'y' => 785,
|
||||
],
|
||||
//价格符号
|
||||
'price_symbol' => [
|
||||
'color' => '#FF2C3C', 'font_face' => ROOT_PATH .'/font/SourceHanSansCN-Regular.otf', 'font_size' => 22, 'w' => 140, 'x' => 40, 'y' => 722,
|
||||
],
|
||||
//商品价格
|
||||
'price' => [
|
||||
'color' => '#FF2C3C', 'font_face' => ROOT_PATH .'/font/SourceHanSansCN-Bold.otf', 'font_size' => 32, 'w' => 140, 'x' => 64, 'y' => 722,
|
||||
],
|
||||
//小数
|
||||
'decimal'=> [
|
||||
'color' => '#FF2C3C', 'font_face' => ROOT_PATH .'/font/SourceHanSansCN-Bold.otf', 'font_size' => 22, 'w' => 140, 'x' => 114, 'y' => 722,
|
||||
],
|
||||
//市场价
|
||||
'market_price_symbol' => [
|
||||
'color' => '#999999', 'font_face' => ROOT_PATH .'/font/SourceHanSansCN-Regular.otf', 'font_size' => 22, 'w' => 140, 'x' => 142, 'y' => 722,
|
||||
],
|
||||
//市场价符号
|
||||
'market_price' => [
|
||||
'color' => '#999999', 'font_face' => ROOT_PATH .'/font/SourceHanSansCN-Regular.otf', 'font_size' => 20, 'w' => 140, 'x' => 168, 'y' => 722,
|
||||
],
|
||||
//推广主图商品主图
|
||||
'main_pic' => [
|
||||
'w' => 560, 'h' => 560, 'x' => 40, 'y' => 100,
|
||||
],
|
||||
//提醒长按扫码
|
||||
'notice' => [
|
||||
'color' => '#888888', 'font_face' => ROOT_PATH .'/font/SourceHanSansCN-Regular.otf', 'font_size' => 18, 'x' => 432, 'y' => 895,
|
||||
],
|
||||
//二维码
|
||||
'qr' => [
|
||||
'w' => 165,'h' => 165, 'x' => 436, 'y' => 700,
|
||||
],
|
||||
];
|
||||
}
|
||||
//生成商品分享图
|
||||
public function makeGoodsPoster($user,$goods,$url,$url_type){
|
||||
|
||||
try {
|
||||
$save_dir = ROOT_PATH .'/uploads/qr_code/goods_share/';
|
||||
$background_img = ROOT_PATH .'/images/share/share_goods_bg.png';
|
||||
!file_exists($save_dir) && mkdir($save_dir, 0777, true);
|
||||
|
||||
$cache_key = 'gid' . $goods['id'].'uid'.$user['id'].$url_type;
|
||||
$qr_src = md5($cache_key) . '.png';
|
||||
$poster_url = $save_dir . $qr_src;
|
||||
|
||||
$base64 = Cache::get($cache_key);
|
||||
if (!empty($base64)) {
|
||||
return self::dataSuccess('海报生成成功',$base64);
|
||||
}
|
||||
|
||||
|
||||
$poster_config = self::goodsShareConfig();
|
||||
//生成二维码
|
||||
if($url_type == 'path'){
|
||||
$scene = 'id='.$goods['id'].'&invite_code='.$user['distribution_code'];
|
||||
$result = $this->makeMnpQrcode($scene,$url,$qr_src,$save_dir);
|
||||
if(true !== $result){
|
||||
return self::dataError('微信配置错误:'.$result);
|
||||
}
|
||||
}else{
|
||||
$qrCode = new QrCode();
|
||||
$qrCode->setText($url);
|
||||
$qrCode->setSize(1000);
|
||||
$qrCode->setWriterByName('png');
|
||||
$qrCode->writeFile($poster_url);
|
||||
|
||||
}
|
||||
$user_avatar = UrlServer::getFileUrl($user['avatar'],'share');
|
||||
//判断头像是否存在
|
||||
if(!check_file_exists($user_avatar)){
|
||||
//如果不存在,使用默认头像
|
||||
$user_avatar = ROOT_PATH.ConfigServer::get('website', 'user_image');
|
||||
}
|
||||
|
||||
//默认商品主图
|
||||
$goods_image = UrlServer::getFileUrl($goods['image'],'share');
|
||||
|
||||
//判断是否有自定义分享海报图
|
||||
if($goods['poster']){
|
||||
$goods_image = UrlServer::getFileUrl($goods['poster'],'share');
|
||||
}
|
||||
if(!check_file_exists($goods_image)){
|
||||
//如果不存在,使用默认商品主图
|
||||
$goods_image = ROOT_PATH.ConfigServer::get('website', 'goods_image');
|
||||
}
|
||||
|
||||
$qr_code_logic = new QrCodeLogic();
|
||||
//获取背景图
|
||||
$share_background_img = imagecreatefromstring(file_get_contents($background_img));
|
||||
|
||||
//合成头像
|
||||
$qr_code_logic->writeImg($share_background_img, $user_avatar, $poster_config['head_pic'],true);
|
||||
|
||||
//合并商品主图
|
||||
$qr_code_logic->writeImg($share_background_img, $goods_image, $poster_config['main_pic'],false);
|
||||
|
||||
//合成昵称
|
||||
$nickname = filterEmoji($user['nickname']);
|
||||
$nickname = '来自'.$nickname.'的分享';
|
||||
$qr_code_logic->writeText($share_background_img, $nickname, $poster_config['nickname']);
|
||||
|
||||
//长按识别
|
||||
$notice = '长按识别二维码';
|
||||
$qr_code_logic->writeText($share_background_img, $notice, $poster_config['notice']);
|
||||
|
||||
//合成价格
|
||||
$qr_code_logic->writeText($share_background_img, '¥', $poster_config['price_symbol']);
|
||||
$qr_code_logic->writeText($share_background_img, floatval($goods['min_price']), $poster_config['price']);
|
||||
|
||||
//合成商品标题
|
||||
$goods_name = auto_adapt($poster_config['title']['font_size'], 0, $poster_config['title']['font_face'], $goods['name'], $poster_config['title']['w'],$poster_config['title']['y'],getimagesize($background_img));
|
||||
$qr_code_logic->writeText($share_background_img, $goods_name, $poster_config['title']);
|
||||
|
||||
//合成二维码
|
||||
$qr_code_logic->writeImg($share_background_img, $poster_url, $poster_config['qr'],false);
|
||||
|
||||
imagepng($share_background_img, $poster_url);
|
||||
if ($fp = fopen($poster_url, "rb", 0)) {
|
||||
$gambar = fread($fp, filesize($poster_url));
|
||||
fclose($fp);
|
||||
$base64 = chunk_split(base64_encode($gambar));
|
||||
$base64 = 'data:image/png;base64,' . $base64;
|
||||
}
|
||||
//删除文件
|
||||
if (strstr($poster_url, $save_dir)) {
|
||||
unlink($poster_url);
|
||||
}
|
||||
Cache::set($cache_key, $base64, 3600);
|
||||
|
||||
return self::dataSuccess('海报生成成功',$base64);
|
||||
|
||||
}catch (Exception $e){
|
||||
return self::dataError('海报生成错误:' . $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//用户图片配置
|
||||
public function userShareConfig()
|
||||
{
|
||||
return [
|
||||
//会员头像
|
||||
'head_pic' => [
|
||||
'w' => 80, 'h' => 80, 'x' => 30, 'y' => 680,
|
||||
],
|
||||
//会员昵称
|
||||
'nickname' => [
|
||||
'color' => '#333333', 'font_face' => ROOT_PATH.'/font/SourceHanSansCN-Regular.otf', 'font_size' => 20, 'x' => 120, 'y' => 730,
|
||||
],
|
||||
//标题
|
||||
'title' => [
|
||||
'color' => '#333333', 'font_face' => ROOT_PATH.'/font/SourceHanSansCN-Regular.otf', 'font_size' => 20, 'w' => 360, 'x' => 30, 'y' => 810,
|
||||
],
|
||||
//提醒长按扫码
|
||||
'notice' => [
|
||||
'color' => '#333333', 'font_face' => ROOT_PATH.'/font/SourceHanSansCN-Regular.otf', 'font_size' => 20, 'x' => 30, 'y' => 880,
|
||||
],
|
||||
//邀请码文本
|
||||
'code_text' => [
|
||||
'color' => '#FF2C3C', 'font_face' => ROOT_PATH.'/font/SourceHanSansCN-Regular.otf', 'font_size' => 20, 'x' => 355, 'y' => 930,
|
||||
],
|
||||
//二维码
|
||||
'qr' => [
|
||||
'w' => 170,'h' => 170, 'x' => 370, 'y' => 730,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
//生成用户小程序二维码
|
||||
public function makeUserMnpQrcode($code,$content,$img_src)
|
||||
{
|
||||
try {
|
||||
$config = WeChatServer::getMnpConfig();
|
||||
$app = Factory::miniProgram($config);
|
||||
$response = $app->app_code->get($content.'?invite_code='.$code, [
|
||||
'width' => 170,
|
||||
]);
|
||||
|
||||
if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
|
||||
$response->saveAs('uploads/qr_code/user_share/', $img_src);
|
||||
return true;
|
||||
}
|
||||
if(isset($response['errcode']) && 41030 === $response['errcode']){
|
||||
return '商城小程序码,先提交审核并通过';
|
||||
}
|
||||
return $response['errmsg'];
|
||||
|
||||
} catch (\EasyWeChat\Kernel\Exceptions\Exception $e){
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//获取分享海报背景
|
||||
public function getSharePosterBg()
|
||||
{
|
||||
$share_bg = ConfigServer::get('distribution', 'share_poster');
|
||||
// 获取存储引擎
|
||||
$config = [
|
||||
'default' => ConfigServer::get('storage', 'default', 'local'),
|
||||
'engine' => ConfigServer::get('storage_engine')
|
||||
];
|
||||
|
||||
if ($config['default'] == 'local') {
|
||||
return ROOT_PATH .'/'.$share_bg;
|
||||
} else {
|
||||
$share_bg = UrlServer::getFileUrl($share_bg,'share');
|
||||
if (!check_file_exists($share_bg)) {
|
||||
return ROOT_PATH .'/images/share/share_user_bg.png';
|
||||
}
|
||||
return $share_bg;
|
||||
}
|
||||
}
|
||||
|
||||
//删除旧的文件
|
||||
public function delOldPoster($poster_url, $save_dir, $qr_src)
|
||||
{
|
||||
// 获取存储引擎
|
||||
$config = [
|
||||
'default' => ConfigServer::get('storage', 'default', 'local'),
|
||||
'engine' => ConfigServer::get('storage_engine')
|
||||
];
|
||||
|
||||
if ($config['default'] == 'local') {
|
||||
//删除文件
|
||||
if (file_exists($poster_url) && strstr($poster_url, $save_dir)) {
|
||||
unlink($poster_url);
|
||||
}
|
||||
} else {
|
||||
try{
|
||||
$StorageDriver = new StorageDriver($config);
|
||||
$file_name = $save_dir . $qr_src;
|
||||
$StorageDriver->delete($file_name);
|
||||
} catch(Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//生成用户分享图
|
||||
public function makeUserPoster($user, $content, $url_type, $client)
|
||||
{
|
||||
try {
|
||||
$save_dir = 'uploads/qr_code/user_share/';
|
||||
$background_img = $this->getSharePosterBg();
|
||||
!file_exists($save_dir) && mkdir($save_dir, 0777, true);
|
||||
|
||||
$save_key = 'uid'.$user['id'].$url_type.$client;
|
||||
$qr_src = md5($save_key) . '.png';
|
||||
$poster_url = ROOT_PATH.'/'.$save_dir . $qr_src;
|
||||
|
||||
//删除旧的图片
|
||||
$this->delOldPoster($poster_url, $save_dir, $qr_src);
|
||||
|
||||
$poster_config = $this->userShareConfig();
|
||||
//生成二维码
|
||||
if($url_type == 'path'){
|
||||
$result = $this->makeUserMnpQrcode($user['distribution_code'], $content, $qr_src);
|
||||
if(true !== $result){
|
||||
return ['status' => 0, 'msg' => '微信配置错误:'.$result, 'data' => ''];
|
||||
}
|
||||
}else{
|
||||
$qrCode = new QrCode();
|
||||
$qrCode->setText($content);
|
||||
$qrCode->setSize(1000);
|
||||
$qrCode->setWriterByName('png');
|
||||
$qrCode->writeFile($poster_url);
|
||||
}
|
||||
$user_avatar = UrlServer::getFileUrl($user['avatar'],'share');
|
||||
//判断头像是否存在
|
||||
if(!check_file_exists($user_avatar)){
|
||||
//如果不存在,使用默认头像
|
||||
$user_avatar = ROOT_PATH.ConfigServer::get('website', 'user_image');
|
||||
}
|
||||
|
||||
$qr_code_logic = new QrCodeLogic();
|
||||
|
||||
//获取背景图
|
||||
$share_background_img = imagecreatefromstring(file_get_contents($background_img));
|
||||
//合成头像
|
||||
$qr_code_logic->writeImg($share_background_img, $user_avatar, $poster_config['head_pic'],true);
|
||||
|
||||
//合成昵称
|
||||
$nickname = filterEmoji($user['nickname']);
|
||||
$qr_code_logic->writeText($share_background_img, $nickname, $poster_config['nickname']);
|
||||
//长按识别
|
||||
$notice = '长按识别二维码 >>';
|
||||
$qr_code_logic->writeText($share_background_img, $notice, $poster_config['notice']);
|
||||
//合成商品标题
|
||||
$title = auto_adapt($poster_config['title']['font_size'], 0, $poster_config['title']['font_face'], '邀请你一起来赚大钱', $poster_config['title']['w'],$poster_config['title']['y'],getimagesize($background_img));
|
||||
$qr_code_logic->writeText($share_background_img, $title, $poster_config['title']);
|
||||
//邀请码
|
||||
$qr_code_logic->writeText($share_background_img, '邀请码 '.$user['distribution_code'], $poster_config['code_text']);
|
||||
//合成二维码
|
||||
$qr_code_logic->writeImg($share_background_img, $poster_url, $poster_config['qr'],false);
|
||||
|
||||
imagepng($share_background_img, $poster_url);
|
||||
|
||||
$file_name = $save_dir . $qr_src;
|
||||
$local_uir = ROOT_PATH.'/'.$file_name;
|
||||
self::upload($local_uir, $file_name);
|
||||
|
||||
return ['status' => 1, 'msg' => '', 'data' => $file_name.'?v='.time()];
|
||||
}catch (Exception $e){
|
||||
return ['status' => 0, 'msg' => $e->getMessage(), 'data' => ''];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 生成的图片根据不同的存储方式储存
|
||||
* @param $local_uri 本地图片路径
|
||||
* @param $img_uri 图片地址名称
|
||||
* @author 段誉(2021/3/2 18:47)
|
||||
* @throws Exception
|
||||
*/
|
||||
public function upload($local_uri, $file_name)
|
||||
{
|
||||
$config = [
|
||||
'default' => ConfigServer::get('storage', 'default', 'local'),
|
||||
'engine' => ConfigServer::get('storage_engine')
|
||||
];
|
||||
|
||||
if (empty($config['engine']['local'])) {
|
||||
$config['engine']['local'] = [];
|
||||
}
|
||||
|
||||
if ($config['default'] != 'local') {
|
||||
$StorageDriver = new StorageDriver($config);
|
||||
if (!$StorageDriver->fetch($local_uri, $file_name)) {
|
||||
throw new Exception('图片保存出错:' . $StorageDriver->getError());
|
||||
}
|
||||
//删除本地图片
|
||||
@unlink($file_name);
|
||||
}
|
||||
}
|
||||
//砍价图片配置
|
||||
public function bargainShareConfig(){
|
||||
return [
|
||||
//会员头像
|
||||
'head_pic' => [
|
||||
'w' => 64, 'h' => 64, 'x' => 40, 'y' => 20,
|
||||
],
|
||||
//会员昵称
|
||||
'nickname' => [
|
||||
'color' => '#555555', 'font_face' => ROOT_PATH .'/font/SourceHanSansCN-Regular.otf', 'font_size' => 19, 'x' => 120, 'y' => 60,
|
||||
],
|
||||
|
||||
'bargain_title' => [
|
||||
'color' => '#FF2C3C', 'font_face' => ROOT_PATH .'/font/SourceHanSansCN-Bold.otf', 'font_size' => 24, 'w' => 360, 'x' => 40, 'y' => 735,
|
||||
],
|
||||
'brief_title' => [
|
||||
'color' => '#F95F2F', 'font_face' => ROOT_PATH .'/font/SourceHanSansCN-Regular.otf', 'font_size' => 16, 'w' => 360, 'x' => 40, 'y' => 765,
|
||||
],
|
||||
//标题
|
||||
'title' => [
|
||||
'color' => '#333333', 'font_face' => ROOT_PATH .'/font/SourceHanSansCN-Regular.otf', 'font_size' => 20, 'w' => 360, 'x' => 40, 'y' => 795,
|
||||
],
|
||||
//推广主图商品主图
|
||||
'main_pic' => [
|
||||
'w' => 560, 'h' => 560, 'x' => 40, 'y' => 100,
|
||||
],
|
||||
//提醒长按扫码
|
||||
'notice' => [
|
||||
'color' => '#888888', 'font_face' => ROOT_PATH .'/font/SourceHanSansCN-Regular.otf', 'font_size' => 18, 'x' => 432, 'y' => 895,
|
||||
],
|
||||
//二维码
|
||||
'qr' => [
|
||||
'w' => 165,'h' => 165, 'x' => 436, 'y' => 700,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function makeBargainPoster($user,$bargain_launch,$url,$url_type){
|
||||
|
||||
try {
|
||||
$save_dir = ROOT_PATH .'/uploads/qr_code/bargain_share/';
|
||||
$background_img = ROOT_PATH .'/images/share/share_goods_bg.png';
|
||||
!file_exists($save_dir) && mkdir($save_dir,0777,true);
|
||||
|
||||
$cache_key = 'bid' . $bargain_launch['id'].'uid'.$user['id'].$url_type;
|
||||
$qr_src = md5($cache_key) . '.png';
|
||||
$poster_url = $save_dir . $qr_src;
|
||||
|
||||
$base64 = Cache::get($cache_key);
|
||||
if (!empty($base64)) {
|
||||
return self::dataSuccess('海报生成成功',$base64);
|
||||
}
|
||||
|
||||
|
||||
$poster_config = self::bargainShareConfig();
|
||||
//生成二维码
|
||||
if($url_type == 'path'){
|
||||
$scene = 'id='.$bargain_launch['id'];
|
||||
$result = $this->makeMnpQrcode($scene,$url,$qr_src,$save_dir);
|
||||
if(true !== $result){
|
||||
return self::dataError('微信配置错误:'.$result);
|
||||
}
|
||||
}else{
|
||||
$qrCode = new QrCode();
|
||||
$qrCode->setText($url);
|
||||
$qrCode->setSize(1000);
|
||||
$qrCode->setWriterByName('png');
|
||||
$qrCode->writeFile($poster_url);
|
||||
|
||||
}
|
||||
$user_avatar = UrlServer::getFileUrl($user['avatar'],'share');
|
||||
//判断头像是否存在
|
||||
if(!check_file_exists($user_avatar)){
|
||||
//如果不存在,使用默认头像
|
||||
$user_avatar = ROOT_PATH.ConfigServer::get('website', 'user_image');
|
||||
}
|
||||
//判断商品主图是否存在
|
||||
$goods_image = UrlServer::getFileUrl($bargain_launch['goods_snap']['goods_iamge'],'share');
|
||||
if(!check_file_exists($goods_image)){
|
||||
//如果不存在,使用默认商品主图
|
||||
$goods_image = ROOT_PATH.ConfigServer::get('website', 'goods_image');
|
||||
}
|
||||
|
||||
$qr_code_logic = new QrCodeLogic();
|
||||
//获取背景图
|
||||
$share_background_img = imagecreatefromstring(file_get_contents($background_img));
|
||||
|
||||
//合成头像
|
||||
$qr_code_logic->writeImg($share_background_img, $user_avatar, $poster_config['head_pic'],true);
|
||||
|
||||
//合并商品主图
|
||||
$qr_code_logic->writeImg($share_background_img, $goods_image, $poster_config['main_pic'],false);
|
||||
|
||||
//合成昵称
|
||||
$nickname = filterEmoji($user['nickname']);
|
||||
$nickname = '来自'.$nickname.'的分享';
|
||||
$qr_code_logic->writeText($share_background_img, $nickname, $poster_config['nickname']);
|
||||
|
||||
//长按识别
|
||||
$notice = '长按识别二维码';
|
||||
$qr_code_logic->writeText($share_background_img, $notice, $poster_config['notice']);
|
||||
|
||||
//合成砍价标题
|
||||
$bargain_title = '我正在参与砍价 还差一步';
|
||||
$qr_code_logic->writeText($share_background_img, $bargain_title, $poster_config['bargain_title']);
|
||||
|
||||
//合成简介
|
||||
$brief_title = '帮忙砍一刀';
|
||||
$qr_code_logic->writeText($share_background_img, $brief_title, $poster_config['brief_title']);
|
||||
|
||||
//合成商品标题
|
||||
$goods_name = auto_adapt($poster_config['title']['font_size'], 0, $poster_config['title']['font_face'], $bargain_launch['goods_snap']['name'], $poster_config['title']['w'],$poster_config['title']['y'],getimagesize($background_img));
|
||||
$qr_code_logic->writeText($share_background_img, $goods_name, $poster_config['title']);
|
||||
|
||||
//合成二维码
|
||||
$qr_code_logic->writeImg($share_background_img, $poster_url, $poster_config['qr'],false);
|
||||
|
||||
imagepng($share_background_img, $poster_url);
|
||||
if ($fp = fopen($poster_url, "rb", 0)) {
|
||||
$gambar = fread($fp, filesize($poster_url));
|
||||
fclose($fp);
|
||||
$base64 = chunk_split(base64_encode($gambar));
|
||||
$base64 = 'data:image/png;base64,' . $base64;
|
||||
}
|
||||
//删除文件
|
||||
if (strstr($poster_url, $save_dir)) {
|
||||
unlink($poster_url);
|
||||
}
|
||||
|
||||
$expire = $bargain_launch['launch_end_time'] - time();
|
||||
|
||||
Cache::set($cache_key, $base64, $expire);
|
||||
|
||||
return self::dataSuccess('海报生成成功',$base64);
|
||||
|
||||
}catch (Exception $e){
|
||||
return self::dataError('海报生成错误:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//小程序生成二维码(非永久码)
|
||||
public function makeMnpQrcode($scene,$url,$img_src,$save_dir){
|
||||
try {
|
||||
$config = WeChatServer::getMnpConfig();
|
||||
$app = Factory::miniProgram($config);
|
||||
|
||||
$response = $app->app_code->getUnlimit($scene, [
|
||||
'page' => $url,
|
||||
]);
|
||||
|
||||
if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
|
||||
$response->saveAs($save_dir, $img_src);
|
||||
return true;
|
||||
}
|
||||
if(isset($response['errcode']) && 41030 === $response['errcode']){
|
||||
return '商城小程序未上线或商城小程序页面发布';
|
||||
}
|
||||
return $response['errmsg'];
|
||||
|
||||
|
||||
} catch (\EasyWeChat\Kernel\Exceptions\Exception $e){
|
||||
|
||||
return $e->getMessage();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//写入图片
|
||||
public function writeImg($poster, $img_uri, $config, $is_rounded = false){
|
||||
$pic_img = imagecreatefromstring(file_get_contents($img_uri));
|
||||
$is_rounded?$pic_img = rounded_corner($pic_img):'';//切成圆角返回头像资源
|
||||
$pic_w = imagesx($pic_img);
|
||||
$pic_h = imagesy($pic_img);
|
||||
|
||||
//圆形头像大图合并到海报
|
||||
imagecopyresampled($poster, $pic_img,
|
||||
$config['x'],
|
||||
$config['y'],
|
||||
0, 0,
|
||||
$config['w'],
|
||||
$config['h'],
|
||||
$pic_w,
|
||||
$pic_h
|
||||
);
|
||||
|
||||
return $poster;
|
||||
}
|
||||
//写入文字
|
||||
public function writeText($poster, $text, $config){
|
||||
|
||||
$font_uri = $config['font_face'];
|
||||
$font_size = $config['font_size'];
|
||||
$color = substr($config['color'],1);
|
||||
//颜色转换
|
||||
$color= str_split($color, 2);
|
||||
$color = array_map('hexdec', $color);
|
||||
if (empty($color[3]) || $color[3] > 127) {
|
||||
$color[3] = 0;
|
||||
}
|
||||
//写入文字
|
||||
$font_col = imagecolorallocatealpha($poster, $color[0], $color[1], $color[2], $color[3]);
|
||||
imagettftext($poster, $font_size,0, $config['x'], $config['y'], $font_col, $font_uri, $text);
|
||||
return $poster;
|
||||
|
||||
}
|
||||
}
|
||||
75
application/common/logic/SmsLogic.php
Normal file
75
application/common/logic/SmsLogic.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\model\NoticeSetting;
|
||||
use app\common\model\SmsLog;
|
||||
|
||||
class SmsLogic
|
||||
{
|
||||
protected $message_key = '';
|
||||
protected $mobile = '';
|
||||
protected $code = '';
|
||||
protected $sms = '';
|
||||
protected $indate = 300;//todo 验证码有效期
|
||||
|
||||
public function __construct($key, $mobile, $code)
|
||||
{
|
||||
$this->message_key = NoticeSetting::SMS_SCENE[$key];
|
||||
$this->mobile = $mobile;
|
||||
$this->code = $code;
|
||||
$sms_Log = new SmsLog();
|
||||
$sms = $sms_Log
|
||||
->where(['message_key' => $this->message_key, 'mobile' => $this->mobile, 'is_verify' => 0])
|
||||
->order('id desc')
|
||||
->field('id,code,send_time')
|
||||
->find();
|
||||
|
||||
$this->sms = $sms;
|
||||
}
|
||||
|
||||
//检查验证码
|
||||
public function checkCode()
|
||||
{
|
||||
if (!isset($this->sms) || $this->sms->code !== $this->code) {
|
||||
return '验证码错误';
|
||||
}
|
||||
$send_time = $this->sms->getData('send_time');
|
||||
|
||||
$now = time();
|
||||
if ($this->sms->code === $this->code && $send_time + $this->indate < $now) {
|
||||
return '验证码已过期';
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
//标记已验证
|
||||
public function cancelCode()
|
||||
{
|
||||
if (empty($this->sms)) {
|
||||
return false;
|
||||
}
|
||||
unset($this->sms->send_time);
|
||||
$this->sms->is_verify = 1;
|
||||
$this->sms->update_time = time();
|
||||
return $this->sms->save();
|
||||
}
|
||||
}
|
||||
64
application/common/logic/UserLevelLogic.php
Normal file
64
application/common/logic/UserLevelLogic.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\logic;
|
||||
use think\Db;
|
||||
|
||||
class UserLevelLogic{
|
||||
/**
|
||||
* note 更新个人会员等级
|
||||
* create_time 2020/11/26 18:52
|
||||
*/
|
||||
public static function updateUserLevel($id){
|
||||
|
||||
$user = Db::name('user')->where(['id'=>$id])->field('user_growth,level')->find();
|
||||
$level = Db::name('user_level')
|
||||
->where([['growth_value','<=',$user['user_growth']],['del','=',0]])
|
||||
->order('growth_value desc')
|
||||
->find();
|
||||
|
||||
if($level){
|
||||
$growth_value = 0;
|
||||
$user['level'] > 0 && $growth_value = Db::name('user_level')->where(['id'=>$user['level']])->value('growth_value');
|
||||
if($level['growth_value'] > $growth_value){
|
||||
Db::name('user')->where(['id'=>$id])->update(['level'=>$level['id'],'update_time'=>time()]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
/**
|
||||
* note 更新所有用户的等级
|
||||
* create_time 2020/11/26 19:11
|
||||
*/
|
||||
public static function updateAllUserLevel($level_id){
|
||||
$growth_value = Db::name('user_level')->where(['id'=>$level_id])->value('growth_value');
|
||||
$no_update_user_ids = Db::name('user')->alias('U')
|
||||
->join('user_level L','U.level = L.id')
|
||||
->where('L.growth_value','>',$growth_value)
|
||||
->column('U.id');
|
||||
|
||||
return Db::name('user')
|
||||
->where([
|
||||
['id','not in',$no_update_user_ids],
|
||||
['del','=',0],
|
||||
['user_growth','>=',$growth_value],
|
||||
])->update(['level'=>$level_id,'update_time'=>time()]);
|
||||
|
||||
}
|
||||
}
|
||||
162
application/common/model/AccountLog.php
Normal file
162
application/common/model/AccountLog.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\model;
|
||||
use think\Model;
|
||||
|
||||
class AccountLog extends Model{
|
||||
/*******************************
|
||||
** 余额变动:100~199
|
||||
** 积分变动:200~299
|
||||
** 成长值变动:300~399
|
||||
** 佣金变动: 400~499
|
||||
*******************************/
|
||||
const admin_add_money = 100;
|
||||
const admin_reduce_money = 101;
|
||||
const recharge_money = 102;
|
||||
const balance_pay_order = 103;
|
||||
const cancel_order_refund = 104;
|
||||
const after_sale_refund = 105;
|
||||
const withdraw_to_balance = 106;
|
||||
const user_transfer_inc_balance = 107;
|
||||
const user_transfer_dec_balance = 108;
|
||||
|
||||
const admin_add_integral = 200;
|
||||
const admin_reduce_integral = 201;
|
||||
const sign_in_integral = 202;
|
||||
const recharge_give_integral = 203;
|
||||
const order_add_integral = 204;
|
||||
const register_add_integral = 205;
|
||||
const invite_add_integral = 206;
|
||||
const order_deduction_integral = 207;
|
||||
const cancel_order_refund_integral = 208;
|
||||
const luck_draw_integral = 209;
|
||||
const deduct_order_first_integral = 210;
|
||||
const order_goods_give_integral = 211;
|
||||
|
||||
const admin_add_growth = 300;
|
||||
const admin_reduce_growth = 301;
|
||||
const sign_give_growth = 302;
|
||||
const recharge_give_growth = 303;
|
||||
const order_give_growth = 304;//下单赠送成长值
|
||||
|
||||
const withdraw_dec_earnings = 400;//提现扣减佣金
|
||||
const withdraw_back_earnings = 401;//提现被拒绝返回佣金
|
||||
const distribution_inc_earnings = 402;//分销订单结算增加佣金
|
||||
|
||||
const money_change = [ //余额变动类型
|
||||
self::admin_add_money,self::admin_reduce_money,self::recharge_money,self::balance_pay_order,self::cancel_order_refund,self::after_sale_refund
|
||||
, self::withdraw_to_balance,self::user_transfer_inc_balance, self::user_transfer_dec_balance
|
||||
];
|
||||
const integral_change = [ //积分变动类型
|
||||
self::admin_add_integral,self::admin_reduce_integral,self::sign_in_integral,self::recharge_give_integral,self::order_add_integral,self::invite_add_integral
|
||||
, self::order_deduction_integral,self::register_add_integral,self::cancel_order_refund_integral,self::luck_draw_integral,self::deduct_order_first_integral
|
||||
, self::order_goods_give_integral
|
||||
];
|
||||
const growth_change = [ //成长值变动类型
|
||||
self::admin_add_growth,self::admin_reduce_growth,self::recharge_give_growth,self::sign_give_growth, self::order_give_growth
|
||||
];
|
||||
|
||||
const earnings_change = [ //佣金变动
|
||||
self::withdraw_dec_earnings, self::withdraw_back_earnings, self::distribution_inc_earnings
|
||||
];
|
||||
|
||||
public static function getAcccountDesc($from = true){
|
||||
$desc = [
|
||||
self::admin_add_money => '系统增加余额',
|
||||
self::admin_reduce_money => '系统扣减余额',
|
||||
self::recharge_money => '用户充值余额',
|
||||
self::admin_add_integral => '系统增加积分',
|
||||
self::admin_reduce_integral => '系统扣减积分',
|
||||
self::sign_in_integral => '每日签到赠送积分',
|
||||
self::recharge_give_integral => '充值赠送积分',
|
||||
self::order_add_integral => '下单赠送积分',
|
||||
self::order_deduction_integral => '下单积分抵扣',
|
||||
self::register_add_integral => '注册赠送积分',
|
||||
self::invite_add_integral => '邀请会员赠送积分',
|
||||
self::admin_add_growth => '系统增加成长值',
|
||||
self::admin_reduce_growth => '系统扣减成长值',
|
||||
self::sign_give_growth => '每日签到赠送成长值',
|
||||
self::recharge_give_growth => '充值赠送成长值',
|
||||
self::balance_pay_order => '下单扣减余额',
|
||||
self::cancel_order_refund => '取消订单退回余额',
|
||||
self::after_sale_refund => '售后退回余额',
|
||||
self::withdraw_to_balance => '佣金提现',
|
||||
self::withdraw_dec_earnings => '提现扣减佣金',
|
||||
self::withdraw_back_earnings => '拒绝提现返还佣金',
|
||||
self::distribution_inc_earnings => '订单结算获得佣金',
|
||||
self::cancel_order_refund_integral => '取消订单退回积分',
|
||||
self::deduct_order_first_integral => '扣除首单积分',
|
||||
self::luck_draw_integral => '积分抽奖中奖',
|
||||
self::order_goods_give_integral => '购买商品赠送积分',
|
||||
self::user_transfer_inc_balance => '会员转账(收入方)',
|
||||
self::user_transfer_dec_balance => '会员转账(支出方)',
|
||||
self::order_give_growth => '下单赠送成长值',
|
||||
];
|
||||
if($from === true){
|
||||
return $desc;
|
||||
}
|
||||
return $desc[$from] ?? '';
|
||||
}
|
||||
//返回变动类型
|
||||
public static function getChangeType($from){
|
||||
$type = '';
|
||||
if(in_array($from,self::money_change)){
|
||||
$type = 'money';
|
||||
}
|
||||
if(in_array($from,self::integral_change)){
|
||||
$type = 'integral';
|
||||
}
|
||||
if(in_array($from,self::growth_change)){
|
||||
$type = 'growth';
|
||||
}
|
||||
if(in_array($from,self::earnings_change)){
|
||||
$type = 'earnings';
|
||||
}
|
||||
return $type;
|
||||
}
|
||||
|
||||
public static function getRemarkDesc($from,$source_sn,$remark =''){
|
||||
return $remark;
|
||||
}
|
||||
|
||||
|
||||
public static function getChangeAmountAttr($value,$data){
|
||||
$amount = $value;
|
||||
if(!in_array($data['source_type'],self::money_change)){
|
||||
$amount = intval($value);
|
||||
}
|
||||
if($data['change_type'] == 1){
|
||||
return '+'.$amount;
|
||||
}
|
||||
return '-'.$amount;
|
||||
}
|
||||
|
||||
public static function getSourceTypeAttr($value,$data){
|
||||
return self::getAcccountDesc($value);
|
||||
|
||||
}
|
||||
|
||||
public static function getcreateTimeAttr($value,$data){
|
||||
if($value){
|
||||
return date('Y-m-d H:i:s',$value);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
98
application/common/model/Ad.php
Normal file
98
application/common/model/Ad.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\model;
|
||||
use think\Model;
|
||||
|
||||
class Ad extends Model{
|
||||
const mobile = 1;
|
||||
const pc = 2;
|
||||
|
||||
|
||||
public static function getAdTypeDesc($from = true){
|
||||
$desc = [
|
||||
self::mobile => '移动端商城',
|
||||
self::pc => 'pc端商城',
|
||||
];
|
||||
if($from === true){
|
||||
return $desc;
|
||||
}
|
||||
return $desc[$from] ?? '';
|
||||
}
|
||||
|
||||
public static function getLinkPage($type = true,$from = true){
|
||||
$page = [
|
||||
self::mobile => [
|
||||
[
|
||||
'name' => '商品分类',
|
||||
'path' => '/pages/sort/sort',
|
||||
'is_tab' => 1,
|
||||
],
|
||||
[
|
||||
'name' => '领券中心',
|
||||
'path' => '/pages/user_getcoupon/user_getcoupon',
|
||||
'is_tab' => 0,
|
||||
],
|
||||
[
|
||||
'name' => '个人中心',
|
||||
'path' => '/pages/user/user',
|
||||
'is_tab' => 1,
|
||||
],
|
||||
],
|
||||
self::pc => [
|
||||
[
|
||||
'name' => '商品分类',
|
||||
'path' => '/category',
|
||||
'is_tab' => 0,
|
||||
],
|
||||
[
|
||||
'name' => '领券中心',
|
||||
'path' => '/get_coupons',
|
||||
'is_tab' => 0,
|
||||
],
|
||||
[
|
||||
'name' => '个人中心',
|
||||
'path' => '/user/profile',
|
||||
'is_tab' => 0,
|
||||
],
|
||||
],
|
||||
];
|
||||
if(true !== $type){
|
||||
$page = $page[$type] ?? [];
|
||||
}
|
||||
if(true === $from){
|
||||
return $page;
|
||||
}
|
||||
return $page[$from] ?? [];
|
||||
}
|
||||
|
||||
|
||||
public static function getGoodsPath($from = true){
|
||||
$desc = [
|
||||
self::mobile => '/pages/goods_details/goods_details',
|
||||
self::pc => '/goods_details',
|
||||
];
|
||||
if(true === $from){
|
||||
return $desc;
|
||||
}
|
||||
return $desc[$from] ?? '';
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
117
application/common/model/AfterSale.php
Normal file
117
application/common/model/AfterSale.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class AfterSale extends Model
|
||||
{
|
||||
//售后状态
|
||||
const STATUS_APPLY_REFUND = 0;//申请退款
|
||||
const STATUS_REFUSE_REFUND = 1;//商家拒绝
|
||||
const STATUS_WAIT_RETURN_GOODS = 2;//商品待退货
|
||||
const STATUS_WAIT_RECEIVE_GOODS = 3;//商家待收货
|
||||
const STATUS_REFUSE_RECEIVE_GOODS = 4;//商家拒收货
|
||||
const STATUS_WAIT_REFUND = 5;//等待退款
|
||||
const STATUS_SUCCESS_REFUND = 6;//退款成功
|
||||
|
||||
//退款类型
|
||||
const TYPE_ONLY_REFUND = 0;//仅退款
|
||||
const TYPE_REFUND_RETURN = 1;//退款退货
|
||||
|
||||
//售后状态描述
|
||||
public static function getStatusDesc($state)
|
||||
{
|
||||
$data = [
|
||||
self::STATUS_APPLY_REFUND => '申请退款',
|
||||
self::STATUS_REFUSE_REFUND => '商家拒绝',
|
||||
self::STATUS_WAIT_RETURN_GOODS => '商品待退货',
|
||||
self::STATUS_WAIT_RECEIVE_GOODS => '商家待收货',
|
||||
self::STATUS_REFUSE_RECEIVE_GOODS => '商家拒收货',
|
||||
self::STATUS_WAIT_REFUND => '等待退款',
|
||||
self::STATUS_SUCCESS_REFUND => '退款成功',
|
||||
];
|
||||
if ($state === true) {
|
||||
return $data;
|
||||
}
|
||||
return $data[$state] ?? '';
|
||||
}
|
||||
|
||||
|
||||
//售后类型描述
|
||||
public static function getRefundTypeDesc($type)
|
||||
{
|
||||
$data = [
|
||||
self::TYPE_ONLY_REFUND => '仅退款',
|
||||
self::TYPE_REFUND_RETURN => '退款退货',
|
||||
];
|
||||
if ($type === true) {
|
||||
return $data;
|
||||
}
|
||||
return $data[$type] ?? '';
|
||||
}
|
||||
|
||||
|
||||
//售后原因
|
||||
public static function getReasonLists()
|
||||
{
|
||||
$data = [
|
||||
'7天无理由退换货',
|
||||
'大小尺寸与商品描述不符',
|
||||
'颜色/图案/款式不符',
|
||||
'做工粗糙/有瑕疵',
|
||||
'质量问题',
|
||||
'卖家发错货',
|
||||
'少件(含缺少配件)',
|
||||
'不喜欢/不想要',
|
||||
'快递/物流一直未送到',
|
||||
'空包裹',
|
||||
'快递/物流无跟踪记录',
|
||||
'货物破损已拒签',
|
||||
'其他',
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function orderGoods()
|
||||
{
|
||||
return $this->hasMany('order_goods', 'id', 'order_goods_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne('user', 'id', 'user_id')
|
||||
->field('id,sn,nickname,avatar,mobile,sex,create_time');
|
||||
}
|
||||
|
||||
public function order()
|
||||
{
|
||||
return $this->hasOne('order', 'id', 'order_id')
|
||||
->field('id,order_sn,total_amount,order_amount,pay_way,order_status');
|
||||
}
|
||||
|
||||
|
||||
public function logs()
|
||||
{
|
||||
return $this->hasMany('after_sale_log', 'after_sale_id', 'id')->order('id desc');
|
||||
}
|
||||
}
|
||||
67
application/common/model/AfterSaleLog.php
Normal file
67
application/common/model/AfterSaleLog.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class AfterSaleLog extends Model
|
||||
{
|
||||
//售后操作人类型
|
||||
const TYPE_USER = 0;//会员
|
||||
const TYPE_SHOP = 1;//门店
|
||||
|
||||
//售后动作
|
||||
const USER_APPLY_REFUND = 100;//会员申请售后
|
||||
const USER_SEND_EXPRESS = 101;//会员发快递
|
||||
const USER_CANCEL_REFUND = 102;//会员撤销售后
|
||||
const USER_AGAIN_REFUND = 103;//会员重新提交申请
|
||||
const SHOP_AGREE_REFUND = 104;//商家同意退款
|
||||
const SHOP_REFUSE_REFUND = 105;//商家拒绝退款
|
||||
const SHOP_TAKE_GOODS = 106;//商家收货
|
||||
const SHOP_REFUSE_TAKE_GOODS = 107;//商家拒绝收货
|
||||
const SHOP_CONFIRM_REFUND = 108;//商家确认退款
|
||||
const REFUND_SUCCESS = 109;//退款成功
|
||||
const REFUND_ERROR = 110;//退款失败
|
||||
|
||||
|
||||
//售后动作明细
|
||||
public static function getLogDesc($log)
|
||||
{
|
||||
$desc = [
|
||||
self::USER_APPLY_REFUND => '会员申请退款',
|
||||
self::USER_SEND_EXPRESS => '会员填写退货物流信息',
|
||||
self::USER_CANCEL_REFUND => '会员撤销售后申请',
|
||||
self::USER_AGAIN_REFUND => '会员重新提交申请',
|
||||
self::SHOP_AGREE_REFUND => '商家同意退款',
|
||||
self::SHOP_REFUSE_REFUND => '商家拒绝退款',
|
||||
self::SHOP_TAKE_GOODS => '商家收货',
|
||||
self::SHOP_REFUSE_TAKE_GOODS => '商家拒绝收货',
|
||||
self::SHOP_CONFIRM_REFUND => '商家确认退款',
|
||||
self::REFUND_SUCCESS => '退款成功',
|
||||
self::REFUND_ERROR => '退款失败',
|
||||
];
|
||||
|
||||
if ($log === true){
|
||||
return $desc;
|
||||
}
|
||||
|
||||
return isset($desc[$log]) ? $desc[$log] : $log;
|
||||
}
|
||||
}
|
||||
62
application/common/model/Bargain.php
Normal file
62
application/common/model/Bargain.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 砍价活动模型
|
||||
* Class Bargain
|
||||
* @Author 张无忌
|
||||
* @package app\common\model
|
||||
*/
|
||||
class Bargain extends Model
|
||||
{
|
||||
/**
|
||||
* Notes: 关联商品模型
|
||||
* @author 张无忌(2021/2/23 17:50)
|
||||
*/
|
||||
public function goods()
|
||||
{
|
||||
return $this->hasOne('Goods', 'id', 'goods_id')
|
||||
->field(['id', 'name', 'image', 'max_price', 'min_price']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 关联砍价参与人数
|
||||
* @author 张无忌(2021/2/23 18:06)
|
||||
*/
|
||||
public function launchPeopleNumber()
|
||||
{
|
||||
return $this->hasMany('BargainLaunch', 'bargain_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 关联砍价成功人数
|
||||
* @author 张无忌(2021/2/23 18:11)
|
||||
*/
|
||||
public function successKnifePeopleNumber()
|
||||
{
|
||||
return $this->hasMany('BargainLaunch', 'bargain_id', 'id')
|
||||
->where(['status'=>1]);
|
||||
}
|
||||
}
|
||||
38
application/common/model/BargainItem.php
Normal file
38
application/common/model/BargainItem.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 砍价活动 商品SKU模型
|
||||
* Class BargainItem
|
||||
* @Author 张无忌
|
||||
* @package app\common\model
|
||||
*/
|
||||
class BargainItem extends Model
|
||||
{
|
||||
public function goodsItem()
|
||||
{
|
||||
return $this->hasOne('GoodsItem', 'id', 'item_id');
|
||||
}
|
||||
}
|
||||
40
application/common/model/BargainKnife.php
Normal file
40
application/common/model/BargainKnife.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 砍价活动 助力模型
|
||||
* Class BargainKnife
|
||||
* @Author 张无忌
|
||||
* @package app\common\model
|
||||
*/
|
||||
class BargainKnife extends Model
|
||||
{
|
||||
// 关联用户模型
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne('user', 'id', 'user_id')
|
||||
->field('id,sn,nickname,avatar,level,mobile,sex,create_time');
|
||||
}
|
||||
}
|
||||
227
application/common/model/BargainLaunch.php
Normal file
227
application/common/model/BargainLaunch.php
Normal file
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use app\common\server\UrlServer;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 砍价活动 参与模型
|
||||
* Class BargainLaunch
|
||||
* @Author 张无忌
|
||||
* @package app\common\model
|
||||
*/
|
||||
class BargainLaunch extends Model
|
||||
{
|
||||
protected $json = ['goods_snap','bargain_snap'];
|
||||
protected $jsonAssoc = true;
|
||||
|
||||
const conductStatus = 0; //进行中
|
||||
const successStatus = 1; //成功
|
||||
const failStatus = 2; //失败
|
||||
|
||||
public static function getStatusDesc($type = true)
|
||||
{
|
||||
$desc = [
|
||||
self::conductStatus => '砍价中',
|
||||
self::successStatus => '砍价成功',
|
||||
self::failStatus => '砍价失败',
|
||||
];
|
||||
if ($type === true) {
|
||||
return $desc;
|
||||
}
|
||||
return $desc[$type] ?? '未知';
|
||||
}
|
||||
|
||||
// 关联用户模型
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne('user', 'id', 'user_id')
|
||||
->field('id,sn,nickname,avatar,level,mobile,sex,create_time');
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 关联订单模型
|
||||
* @author 张无忌(2021/2/24 15:55)
|
||||
*/
|
||||
public function order()
|
||||
{
|
||||
return $this->hasOne('Order', 'id', 'order_id')
|
||||
->field('id,order_sn,user_id,create_time,order_amount,order_status');
|
||||
}
|
||||
|
||||
public function bargainKnife(){
|
||||
return $this->hasMany('bargain_knife', 'launch_id', 'id');
|
||||
}
|
||||
|
||||
//显示商品价格
|
||||
public function getPriceAttr($value,$data){
|
||||
return $data['goods_snap']['price'];
|
||||
}
|
||||
|
||||
|
||||
//显示商品主图
|
||||
public function getImageAttr($value,$data){
|
||||
return UrlServer::getFileUrl($data['goods_snap']['goods_iamge']);
|
||||
}
|
||||
//显示商品名称
|
||||
public function getNameAttr($value,$data){
|
||||
return $data['goods_snap']['name'];
|
||||
}
|
||||
public function getItemIdAttr($value,$data){
|
||||
return $data['goods_snap']['item_id'];
|
||||
}
|
||||
//显示规格名称
|
||||
public function getSpecValueStrAttr($value,$data){
|
||||
return $data['goods_snap']['spec_value_str'];
|
||||
}
|
||||
public function getBtnTipsAttr($value,$data){
|
||||
$tips = '';
|
||||
if(1 == $data['status']){
|
||||
$tips = '砍价成功';
|
||||
}else if(0 == $data['status']){
|
||||
$tips = '继续砍价';
|
||||
}
|
||||
return $tips;
|
||||
}
|
||||
// //显示直接购买按钮
|
||||
// public function getBuyBtnAttr($value,$data){
|
||||
// $btn = 0;
|
||||
// if(2 == $data['bargain_snap']['payment_where'] && empty($data['order_id'])){
|
||||
// $btn = 1;
|
||||
// }
|
||||
// return $btn;
|
||||
// }
|
||||
//显示查看订单按钮
|
||||
public function getOrderBtnAttr($value,$data){
|
||||
$btn = 0;
|
||||
if($data['order_id']){
|
||||
$btn = 1;
|
||||
}
|
||||
return $btn;
|
||||
}
|
||||
//继续砍价按钮
|
||||
public function getBargainBtnAttr($value,$data){
|
||||
$btn = 0;
|
||||
if(0 == $data['status']){
|
||||
$btn = 1;
|
||||
}
|
||||
return $btn;
|
||||
}
|
||||
//砍价成功按钮
|
||||
public function getSuccessBtnAttr($value,$data){
|
||||
$btn = 0;
|
||||
if(1 == $data['status']){
|
||||
$btn = 1;
|
||||
}
|
||||
return $btn;
|
||||
}
|
||||
|
||||
//显示去支付按钮
|
||||
public function getPayBtnAttr($value,$data){
|
||||
$btn = 0;
|
||||
if(1 == $data['status']){
|
||||
$btn = 1;
|
||||
}
|
||||
return $btn;
|
||||
}
|
||||
|
||||
//显示砍价提示
|
||||
public function getBargainTipsAttr($value,$data){
|
||||
$tips = '须砍至最低价才可支付购买';
|
||||
if(2 == $data['bargain_snap']['payment_where']){
|
||||
$tips = '砍至任意金额可直接购买';
|
||||
}
|
||||
return $tips;
|
||||
}
|
||||
|
||||
//显示状态
|
||||
public function getStatusTextAttr($value,$data){
|
||||
return static::getStatusDesc($data['status']);
|
||||
}
|
||||
|
||||
//发起砍价时间
|
||||
public function getCreateTimeAttr($value,$data){
|
||||
return date('Y-m-d H:i:s',$data['launch_start_time']);
|
||||
}
|
||||
|
||||
//砍价结束时间
|
||||
public function getOverTimeAttr($value,$data){
|
||||
return $data['launch_end_time'];
|
||||
}
|
||||
|
||||
//剩余的差价
|
||||
public function getDiffPriceAttr($value,$data){
|
||||
return round($data['current_price'] - $data['bargain_price'],2);
|
||||
}
|
||||
|
||||
//已砍价的价格
|
||||
public function getKnifePriceAttr($value,$data){
|
||||
return round($data['goods_snap']['price'] - $data['current_price'],2);
|
||||
}
|
||||
|
||||
//砍价进度条
|
||||
public function getProgressAttr($value,$data){
|
||||
return round($data['bargain_price'] / $data['current_price'],2);
|
||||
}
|
||||
|
||||
//活动价
|
||||
public function getActivityPriceAttr($value,$data){
|
||||
return $data['bargain_snap']['floor_price'];
|
||||
}
|
||||
//显示砍价状态提示
|
||||
public function getStatusTipsAttr($value,$data){
|
||||
if(2 == $data['status']){
|
||||
return '非常遗憾,砍价失败了';
|
||||
}
|
||||
if(1 == $data['status']){
|
||||
return '恭喜您,砍价成功';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
//显示用户信息
|
||||
public function getKnifeListAttr($value,$data){
|
||||
$list = [];
|
||||
foreach ($this->bargain_knife as $knife){
|
||||
|
||||
$list[] = [
|
||||
'id' => $knife['id'],
|
||||
'user_id' => $knife['user']['id'],
|
||||
'nickname' => $knife['user']['nickname'],
|
||||
'avatar' => $knife['user']['avatar'],
|
||||
'help_price' => $knife['help_price'],
|
||||
'help_time' => date('Y-m-d H:i:s',$knife['help_time']),
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
//分享标题
|
||||
public function getShareTitlesAttr($value,$data){
|
||||
return $data['bargain_snap']['share_title'];
|
||||
}
|
||||
|
||||
//分享简介
|
||||
public function getShareIntrosAttr($value,$data){
|
||||
return $data['bargain_snap']['share_intro'];
|
||||
}
|
||||
}
|
||||
30
application/common/model/Capital_.php
Normal file
30
application/common/model/Capital_.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
class Capital_
|
||||
{
|
||||
public static function getData()
|
||||
{
|
||||
return range('A','Z');
|
||||
}
|
||||
}
|
||||
74
application/common/model/Client_.php
Normal file
74
application/common/model/Client_.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
class Client_
|
||||
{
|
||||
const mnp = 1;//小程序
|
||||
const oa = 2;//公众号
|
||||
const ios = 3;
|
||||
const android = 4;
|
||||
const pc = 5;
|
||||
const h5 = 6;//h5(非微信环境h5)
|
||||
const tt = 8;//头条
|
||||
|
||||
function getName($value)
|
||||
{
|
||||
switch ($value) {
|
||||
case self::mnp:
|
||||
$name = '小程序';
|
||||
break;
|
||||
case self::h5:
|
||||
$name = 'h5';
|
||||
break;
|
||||
case self::ios:
|
||||
$name = '苹果';
|
||||
break;
|
||||
case self::android:
|
||||
$name = '安卓';
|
||||
break;
|
||||
case self::oa:
|
||||
$name = '公众号';
|
||||
break;
|
||||
case self::tt:
|
||||
$name = 'h5';
|
||||
break;
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
public static function getClient($type = true)
|
||||
{
|
||||
$desc = [
|
||||
self::pc => 'pc商城',
|
||||
self::h5 => 'h5商城',
|
||||
self::oa => '公众号商城',
|
||||
self::mnp => '小程序商城',
|
||||
self::ios => '苹果APP商城',
|
||||
self::android => '安卓APP商城',
|
||||
];
|
||||
if ($type === true) {
|
||||
return $desc;
|
||||
}
|
||||
return $desc[$type] ?? '未知';
|
||||
}
|
||||
}
|
||||
30
application/common/model/Crontab_.php
Normal file
30
application/common/model/Crontab_.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
class Crontab_
|
||||
{
|
||||
public static $type = [
|
||||
1=>'定时任务',
|
||||
//2=>'守护进程'
|
||||
];
|
||||
}
|
||||
32
application/common/model/DevMessage.php
Normal file
32
application/common/model/DevMessage.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\model;
|
||||
use think\Model;
|
||||
|
||||
class DevMessage extends Model{
|
||||
//需要验证码的短信key
|
||||
const CODE_KEY = [
|
||||
'ZCYZ', //注册验证
|
||||
'ZHMM', //找回密码
|
||||
'YZMDL', //验证码登录
|
||||
'BGSJHM', //变更手机号码
|
||||
'BDSJHM', //绑定手机号码
|
||||
'ZHZFMM', //找回支付密码
|
||||
];
|
||||
}
|
||||
53
application/common/model/DistributionMember.php
Normal file
53
application/common/model/DistributionMember.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 分销会员
|
||||
* Class DistributionMember
|
||||
* @package app\common\model
|
||||
*/
|
||||
class DistributionMember extends Model
|
||||
{
|
||||
protected $name = 'distribution_member_apply';
|
||||
|
||||
//分销会员申请状态
|
||||
const STATUS_WAIT_AUDIT = 0; //待审核
|
||||
const STATUS_AUDIT_SUCCESS = 1; //审核通过
|
||||
const STATUS_AUDIT_ERROR = 2; //审核拒绝
|
||||
|
||||
|
||||
//分销会员申请状态
|
||||
public static function getApplyStatus($status = true)
|
||||
{
|
||||
$desc = [
|
||||
self::STATUS_WAIT_AUDIT => '待审核',
|
||||
self::STATUS_AUDIT_SUCCESS => '审核通过',
|
||||
self::STATUS_AUDIT_ERROR => '审核拒绝',
|
||||
];
|
||||
if ($status === true) {
|
||||
return $desc;
|
||||
}
|
||||
return $desc[$status] ?? '未知';
|
||||
}
|
||||
}
|
||||
78
application/common/model/DistributionOrder.php
Normal file
78
application/common/model/DistributionOrder.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 分销订单
|
||||
* Class DistributionOrder
|
||||
* @package app\common\model
|
||||
*/
|
||||
class DistributionOrder extends Model
|
||||
{
|
||||
protected $name = 'distribution_order_goods';
|
||||
|
||||
//分销订单状态
|
||||
const STATUS_WAIT_HANDLE = 1;//待返佣
|
||||
const STATUS_SUCCESS = 2;//已结算
|
||||
const STATUS_ERROR = 3;//已失效
|
||||
|
||||
|
||||
//分销订单状态
|
||||
public static function getOrderStatus($status = true)
|
||||
{
|
||||
$desc = [
|
||||
self::STATUS_WAIT_HANDLE => '待返佣',
|
||||
self::STATUS_SUCCESS => '已结算',
|
||||
self::STATUS_ERROR => '已失效',
|
||||
];
|
||||
if ($status === true) {
|
||||
return $desc;
|
||||
}
|
||||
return $desc[$status] ?? '未知';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 更新指定分佣订单状态
|
||||
* @param $distribution_id
|
||||
* @param $status
|
||||
* @author 段誉(2021/4/23 10:10)
|
||||
* @return DistributionOrder
|
||||
*/
|
||||
public static function updateOrderStatus($distribution_id, $status)
|
||||
{
|
||||
return self::where('id', $distribution_id)
|
||||
->update([
|
||||
'status' => $status,
|
||||
'update_time' => time()
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
//用户
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne('user', 'id', 'user_id')
|
||||
->field('id,sn,nickname,avatar,level,mobile,sex,create_time');
|
||||
}
|
||||
|
||||
}
|
||||
30
application/common/model/File.php
Normal file
30
application/common/model/File.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
class File
|
||||
{
|
||||
const type_other = 0;//其他
|
||||
const type_image = 1;//图片
|
||||
const type_video = 2;//视频
|
||||
|
||||
}
|
||||
151
application/common/model/FileCate.php
Normal file
151
application/common/model/FileCate.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class FileCate extends Model
|
||||
{
|
||||
public static function getTreeMenu($get)
|
||||
{
|
||||
$field = 'id,name,pid,level,sort';
|
||||
switch($get['type']) {
|
||||
case 'video':
|
||||
$where = [
|
||||
'del' => 0,
|
||||
'partner_id' => $get['partner_id'],
|
||||
'type' => self::getTypeNumber($get['type'])
|
||||
];
|
||||
$menu = self::where($where)->order('sort', 'desc')->select()->toArray();
|
||||
break;
|
||||
}
|
||||
return self::formatTreeMenu($menu);
|
||||
}
|
||||
|
||||
public static function getMenu($get)
|
||||
{
|
||||
$field = 'id,name,pid,level,sort';
|
||||
switch($get['type']) {
|
||||
case 'video':
|
||||
$where = [
|
||||
'del' => 0,
|
||||
'partner_id' => $get['partner_id'],
|
||||
'type' => self::getTypeNumber($get['type'])
|
||||
];
|
||||
$menu = self::field($field)->where($where)->order('sort', 'desc')->select()->toArray();
|
||||
break;
|
||||
}
|
||||
return self::formatMenu($menu);
|
||||
}
|
||||
|
||||
public static function getTypeNumber($type)
|
||||
{
|
||||
switch($type) {
|
||||
case 'image':
|
||||
return 1;
|
||||
case 'video':
|
||||
return 2;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static function formatMenu($menu)
|
||||
{
|
||||
$tree = [];
|
||||
foreach($menu as $item) {
|
||||
// 查找一级分类
|
||||
if($item['pid'] != 0) {
|
||||
continue;
|
||||
}
|
||||
$tree[$item['id']] = '|__'.$item['name'];
|
||||
// 查找二级分类
|
||||
foreach($menu as $subItem) {
|
||||
if($subItem['pid'] == $item['id']) {
|
||||
$tree[$subItem['id']] = '|____'.$subItem['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
|
||||
public static function formatTreeMenu($menu)
|
||||
{
|
||||
// [{
|
||||
// title: '江西' //一级菜单
|
||||
// ,children: [{
|
||||
// title: '南昌' //二级菜单
|
||||
// ,children: [{
|
||||
// title: '高新区' //三级菜单
|
||||
// //…… //以此类推,可无限层级
|
||||
// }]
|
||||
// }]
|
||||
// },{
|
||||
// title: '陕西' //一级菜单
|
||||
// ,children: [{
|
||||
// title: '西安' //二级菜单
|
||||
// }]
|
||||
// }]
|
||||
$tree = [];
|
||||
$i = 0;
|
||||
foreach($menu as $item) {
|
||||
// 查找一级分类
|
||||
if($item['pid'] != 0) {
|
||||
continue;
|
||||
}
|
||||
$tree[$i]["id"] = $item['id'];
|
||||
$tree[$i]["title"] = $item['name'];
|
||||
$tree[$i]["spread"] = true;
|
||||
$tree[$i]["children"] = [];
|
||||
// 查找二级分类
|
||||
$j = 0;
|
||||
foreach($menu as $subItem) {
|
||||
if($subItem['pid'] == $item['id']) {
|
||||
$tree[$i]["children"][$j]["id"] = $subItem['id'];
|
||||
$tree[$i]["children"][$j]["title"] = $subItem['name'];
|
||||
$tree[$i]["children"][$j]["spread"] = true;
|
||||
$tree[$i]["children"][$j]["children"] = [];
|
||||
// 查找三级分类
|
||||
$k = 0;
|
||||
foreach($menu as $thirdItem) {
|
||||
if($thirdItem['pid'] == $subItem['id']) {
|
||||
$tree[$i]["children"][$j]["children"][$k]["id"] = $thirdItem['id'];
|
||||
$tree[$i]["children"][$j]["children"][$k]["title"] = $thirdItem['name'];
|
||||
$k++;
|
||||
}
|
||||
}
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
|
||||
public static function getCateById($id)
|
||||
{
|
||||
$cate = FileCate::field('id,name,pid,sort')->where(['del'=>0, 'id'=>$id])->findOrEmpty();
|
||||
if($cate->isEmpty()) {
|
||||
return [];
|
||||
}
|
||||
return $cate->toArray();
|
||||
}
|
||||
}
|
||||
54
application/common/model/Footprint.php
Normal file
54
application/common/model/Footprint.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use think\Model;
|
||||
|
||||
class Footprint extends Model
|
||||
{
|
||||
const enter_mall = 1;
|
||||
const browse_goods = 2;
|
||||
const add_cart = 3;
|
||||
const receive_coupon = 4;
|
||||
const place_order = 5;
|
||||
|
||||
public static function getText($value)
|
||||
{
|
||||
$name = '';
|
||||
switch ($value) {
|
||||
case self::enter_mall:
|
||||
$name = '访问商城';
|
||||
break;
|
||||
case self::browse_goods:
|
||||
$name = '浏览商品';
|
||||
break;
|
||||
case self::add_cart:
|
||||
$name = '加入购物车';
|
||||
break;
|
||||
case self::receive_coupon:
|
||||
$name = '领取优惠券';
|
||||
break;
|
||||
case self::place_order:
|
||||
$name = '下单结算';
|
||||
break;
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
111
application/common/model/FootprintRecord.php
Normal file
111
application/common/model/FootprintRecord.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use think\Model;
|
||||
use function GuzzleHttp\Psr7\str;
|
||||
|
||||
class FootprintRecord extends Model
|
||||
{
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
/**
|
||||
* Notes: 关联用户模型
|
||||
* @author 张无忌(2020/12/17 11:51)
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne('User', 'id', 'user_id')
|
||||
->field(['id', 'nickname', 'avatar']);
|
||||
}
|
||||
|
||||
public function getTimeAttr($value, $data)
|
||||
{
|
||||
// 足迹记录时间
|
||||
$create_time = $data['create_time'];
|
||||
// 一小时前时间戳
|
||||
$an_hour_ago = strtotime("-1 hour");
|
||||
|
||||
// 小于1小时内显示xx分钟, 否则显示多少个小时
|
||||
if ($create_time > $an_hour_ago) {
|
||||
$minute = intval((time() - $create_time) / 60);
|
||||
return $minute <= 0 ? '刚刚' : strval($minute).'分钟前';
|
||||
} else {
|
||||
return '1小时前';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 获取30分钟内容的足迹
|
||||
* @param $data
|
||||
* @return FootprintRecord
|
||||
* @author 张无忌(2020/12/16 18:17)
|
||||
*/
|
||||
public static function getFootPrintOneHourInner($data)
|
||||
{
|
||||
// 一小时前时间戳
|
||||
$an_hour_ago = strtotime("-1 hour");
|
||||
// 30分钟前时间戳
|
||||
$half_an_hour_ago = $an_hour_ago + 1800;
|
||||
// 当前时间戳
|
||||
$current_time = time();
|
||||
|
||||
$where = [
|
||||
['create_time', '>', $half_an_hour_ago],
|
||||
['create_time', '<', $current_time]
|
||||
];
|
||||
if ($data['type']) {
|
||||
$where[] = ['user_id', '=', (int)$data['user_id']];
|
||||
$where[] = ['type', '=', (int)$data['type']];
|
||||
}
|
||||
|
||||
// 进入商城
|
||||
if ($data['type'] === Footprint::enter_mall) {
|
||||
$where[] = ['foreign_id', '=', 0];
|
||||
}
|
||||
|
||||
// 如果是浏览器商品
|
||||
if ($data['type'] === Footprint::browse_goods) {
|
||||
$where[] = ['foreign_id', '=', (int)$data['foreign_id']];
|
||||
}
|
||||
|
||||
$model = new self;
|
||||
return $model->field(true)->where($where)->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 添加足迹记录
|
||||
* @param $data (数据)
|
||||
* @param $tpl
|
||||
* @return FootprintRecord
|
||||
* @author 张无忌(2020/12/16 18:18)
|
||||
*/
|
||||
public static function add($data, $tpl)
|
||||
{
|
||||
return self::create([
|
||||
'type' => $data['type'],
|
||||
'user_id' => $data['user_id'],
|
||||
'foreign_id' => empty($data['foreign_id']) ? 0 : $data['foreign_id'],
|
||||
'template' => $tpl,
|
||||
'create_time' => time(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
62
application/common/model/Freight.php
Normal file
62
application/common/model/Freight.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class Freight extends Model
|
||||
{
|
||||
protected $name = 'freight';
|
||||
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
//计费方式
|
||||
const CHARGE_WAY_WEIGHT = 1;//按重量计费
|
||||
const CHARGE_WAY_VOLUME = 2; //体积计费
|
||||
const CHARGE_WAY_PIECE = 3;//按件计费
|
||||
|
||||
|
||||
public static function getChargeWay($type)
|
||||
{
|
||||
$data = [
|
||||
self::CHARGE_WAY_WEIGHT => '按重量计费',
|
||||
self::CHARGE_WAY_VOLUME => '按体积计费',
|
||||
self::CHARGE_WAY_PIECE => '按件计费',
|
||||
];
|
||||
|
||||
if ($type === true) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
return $data[$type] ?? '未知';
|
||||
}
|
||||
|
||||
public function getChargeWayTextAttr($value, $data)
|
||||
{
|
||||
return self::getChargeWay($data['charge_way']);
|
||||
}
|
||||
|
||||
|
||||
public function configs()
|
||||
{
|
||||
return $this->hasMany('freight_config', 'freight_id', 'id');
|
||||
}
|
||||
|
||||
}
|
||||
30
application/common/model/FreightConfig.php
Normal file
30
application/common/model/FreightConfig.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class FreightConfig extends Model
|
||||
{
|
||||
protected $name = 'freight_config';
|
||||
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
}
|
||||
63
application/common/model/Goods.php
Normal file
63
application/common/model/Goods.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Goods extends Model
|
||||
{
|
||||
/**
|
||||
* User: 意象信息科技 mjf
|
||||
* Desc: 获取以规格id为键的商品信息
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public static function getColumnGoods($field = '*')
|
||||
{
|
||||
$info = Db::name('goods_item i')
|
||||
->join('goods g', 'g.id = i.goods_id')
|
||||
->column($field, 'i.id');
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* User: 意象信息科技 mjf
|
||||
* Desc: 通过规格id获取商品信息
|
||||
* @param $item_id
|
||||
* @param string $field
|
||||
* @return array|\PDOStatement|string|Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function getOneByItem($item_id, $field = '*')
|
||||
{
|
||||
$info = Db::name('goods_item i')
|
||||
->field($field)
|
||||
->join('goods g', 'g.id = i.goods_id')
|
||||
->where('i.id', $item_id)
|
||||
->find();
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
}
|
||||
29
application/common/model/GoodsItem.php
Normal file
29
application/common/model/GoodsItem.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use think\Model;
|
||||
|
||||
class GoodsItem extends Model
|
||||
{
|
||||
|
||||
}
|
||||
11
application/common/model/Luckdraw.php
Normal file
11
application/common/model/Luckdraw.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use think\Model;
|
||||
|
||||
class Luckdraw extends Model
|
||||
{
|
||||
|
||||
}
|
||||
26
application/common/model/LuckdrawRecord.php
Normal file
26
application/common/model/LuckdrawRecord.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 抽奖记录模型
|
||||
* Class LuckDrawRecord
|
||||
* @package app\common\model
|
||||
*/
|
||||
class LuckdrawRecord extends Model
|
||||
{
|
||||
// 关联用户模型
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne('user', 'id', 'user_id')
|
||||
->field('id,sn,nickname,avatar,level,mobile,sex,create_time');
|
||||
}
|
||||
|
||||
public function getCreateTimeAttr($value)
|
||||
{
|
||||
return date('Y-m-d H:i:s', $value);
|
||||
}
|
||||
}
|
||||
243
application/common/model/Menu_.php
Normal file
243
application/common/model/Menu_.php
Normal file
@@ -0,0 +1,243 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\model;
|
||||
class Menu_{
|
||||
/*
|
||||
* 首页菜单
|
||||
*/
|
||||
const index_seckill = 1;
|
||||
const index_team_activity = 2;
|
||||
const index_hot_sell = 3;
|
||||
const index_coupon_list = 4;
|
||||
const index_sign_in = 5;
|
||||
const index_member_centre = 6;
|
||||
const index_my_collect = 7;
|
||||
const index_store_news = 8;
|
||||
const index_store_help = 9;
|
||||
const index_delivery_address = 10;
|
||||
const index_goods_category = 11;
|
||||
const index_luckdraw = 12;
|
||||
const index_bargain = 13;
|
||||
/*
|
||||
* 个人中心菜单
|
||||
*/
|
||||
const centre_my_wallet = 10;
|
||||
const centre_generalize = 11;
|
||||
const centre_my_coupon = 12;
|
||||
const centre_level_serve = 13;
|
||||
const centre_store_help = 14;
|
||||
const centre_delivery_address = 15;
|
||||
const centre_my_collect = 16;
|
||||
const centre_service = 17;
|
||||
const centre_team_activity = 18;
|
||||
const centre_bargain = 19;
|
||||
|
||||
/**
|
||||
* Notes: 菜单内容
|
||||
* @param bool $scene 场景:1-首页导航;2-个人中心
|
||||
* @param bool $from 菜单来源:获取具体的某个菜单
|
||||
* @return array
|
||||
* name => '菜单名称'
|
||||
* link => 调整链接
|
||||
* is_tab => 是否的tab页
|
||||
* link_type => 菜单类型:1-跳转;2-web-view;3-按钮(微信小程序可调用客服)
|
||||
* menu_type => 菜单内容类型:1-正常内容;2-分销菜单
|
||||
*
|
||||
*/
|
||||
public static function getMenuContent($scene = true,$from = true){
|
||||
//首页菜单
|
||||
$config1 = [
|
||||
self::index_seckill => [
|
||||
'name' => '限时秒杀',
|
||||
'link' => '/pages/bundle/goods_seckill/goods_seckill',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::index_team_activity => [
|
||||
'name' => '拼团活动',
|
||||
'link' => '/pages/bundle/goods_combination/goods_combination',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::index_hot_sell => [
|
||||
'name' => '热销榜单',
|
||||
'link' => '/pages/bundle/hot_list/hot_list',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::index_coupon_list => [
|
||||
'name' => '领券中心',
|
||||
'link' => '/pages/user_getcoupon/user_getcoupon',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::index_sign_in => [
|
||||
'name' => '积分签到',
|
||||
'link' => '/pages/bundle/user_sign/user_sign',
|
||||
'is_tab' => 0,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::index_member_centre => [
|
||||
'name' => '会员中心',
|
||||
'link' => '/pages/user_vip/user_vip',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::index_my_collect => [
|
||||
'name' => '我的收藏',
|
||||
'link' => '/pages/user_collection/user_collection',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::index_store_news => [
|
||||
'name' => '商城资讯',
|
||||
'link' => '/pages/news_list/news_list',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::index_store_help => [
|
||||
'name' => '帮助中心',
|
||||
'link' => '/pages/news_list/news_list?type=1',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::index_delivery_address => [
|
||||
'name' => '收货地址',
|
||||
'link' => '/pages/user_address/user_address',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::index_goods_category => [
|
||||
'name' => '商品分类',
|
||||
'link' => '/pages/sort/sort',
|
||||
'is_tab' => 1,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::index_luckdraw => [
|
||||
'name' => '积分抽奖',
|
||||
'link' => '/pages/bundle/luckly_wheel/luckly_wheel',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::index_bargain => [
|
||||
'name' => '砍价活动',
|
||||
'link' => '/pages/bundle/bargain/bargain',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
];
|
||||
//个人中心菜单
|
||||
$config2 = [
|
||||
self::centre_my_wallet => [
|
||||
'name' => '我的钱包',
|
||||
'link' => '/pages/bundle/user_wallet/user_wallet',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::centre_generalize => [
|
||||
'name' => '分销推广',
|
||||
'link' => '/pages/bundle/user_spread/user_spread',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 2,
|
||||
],
|
||||
self::centre_my_coupon => [
|
||||
'name' => '我的优惠券',
|
||||
'link' => '/pages/user_coupon/user_coupon',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::centre_level_serve => [
|
||||
'name' => '等级服务',
|
||||
'link' => '/pages/user_vip/user_vip',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::centre_store_help => [
|
||||
'name' => '帮助中心',
|
||||
'link' => '/pages/news_list/news_list?type=1',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::centre_delivery_address => [
|
||||
'name' => '收货地址',
|
||||
'link' => '/pages/user_address/user_address',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::centre_my_collect => [
|
||||
'name' => '我的收藏',
|
||||
'link' => '/pages/user_collection/user_collection',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::centre_service => [
|
||||
'name' => '联系客服',
|
||||
'link' => '/pages/bundle/contact_offical/contact_offical',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::centre_team_activity => [
|
||||
'name' => '我的拼团',
|
||||
'link' => '/pages/bundle/user_group/user_group',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
self::centre_bargain => [
|
||||
'name' => '砍价记录',
|
||||
'link' => '/pages/bundle/bargain_code/bargain_code',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
];
|
||||
$config_name = 'config'.$scene;
|
||||
$content = $$config_name;
|
||||
if($scene === true){
|
||||
$content = array_merge($config1,$config2);
|
||||
}
|
||||
if($from === true){
|
||||
return $content;
|
||||
}
|
||||
return $content[$from] ?? [];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
49
application/common/model/MessageScene_.php
Normal file
49
application/common/model/MessageScene_.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
/**
|
||||
* 微信/公众号的消息模板场景
|
||||
* Class MessageScene_
|
||||
* @package app\common\model
|
||||
*/
|
||||
class MessageScene_
|
||||
{
|
||||
const BUY_SUCCESS = 1; //购买成功通知
|
||||
const DELIVER_GOODS_SUCCESS = 2; //商品发货通知
|
||||
const REFUND_SUCCESS = 3; //退款成功通知
|
||||
|
||||
function getName($value)
|
||||
{
|
||||
$name = '';
|
||||
switch ($value) {
|
||||
case self::BUY_SUCCESS:
|
||||
$name = '购买成功通知';
|
||||
break;
|
||||
case self::DELIVER_GOODS_SUCCESS:
|
||||
$name = '商品发货通知';
|
||||
break;
|
||||
case self::REFUND_SUCCESS:
|
||||
$name = '退款成功通知';
|
||||
break;
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
269
application/common/model/NoticeSetting.php
Normal file
269
application/common/model/NoticeSetting.php
Normal file
@@ -0,0 +1,269 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 通知场景
|
||||
* Class Notice
|
||||
* @package app\common\model
|
||||
*/
|
||||
class NoticeSetting extends Model
|
||||
{
|
||||
|
||||
protected $name = 'dev_notice_setting';
|
||||
|
||||
//设置json
|
||||
// protected $json = ['variable', 'system_notice', 'sms_notice', 'oa_notice', 'mnp_notice'];
|
||||
// protected $jsonAssoc = true;
|
||||
|
||||
|
||||
//通知类型
|
||||
const SYSTEM_NOTICE = 1;
|
||||
const SMS_NOTICE = 2;
|
||||
const OA_NOTICE = 3;
|
||||
const MNP_NOTICE = 4;
|
||||
|
||||
|
||||
//通知对象
|
||||
const NOTICE_PLATFORM = 1; //通知平台
|
||||
const NOTICE_USER = 2; //通知会员
|
||||
const NOTICE_OTHER = 3; //通知游客(如新用户注册)
|
||||
|
||||
|
||||
//通知会员
|
||||
const ORDER_PAY_NOTICE = 100;//订单已支付
|
||||
const ORDER_DELIVERY_NOTICE = 101;//订单已发货
|
||||
const PLATFORM_PASS_REFUND_NOTICE = 102;//平台通过售后退款通知
|
||||
const PLATFORM_REFUSE_REFUND_NOTICE = 103;//平台拒绝售后退款通知
|
||||
const REGISTER_NOTICE = 104;//注册通知
|
||||
const CHANGE_MOBILE_NOTICE = 105;//变更手机号短信通知
|
||||
const GET_BACK_MOBILE_NOTICE = 106;//重置密码短信通知
|
||||
const REGISTER_SUCCESS_NOTICE = 107;//注册成功
|
||||
const INVITE_SUCCESS_NOTICE = 108;//邀请成功
|
||||
const GET_EARNINGS_NOTICE = 109;//获得收益
|
||||
const GET_GODE_LOGIN_NOTICE = 110;//验证码登录
|
||||
const BIND_MOBILE_NOTICE = 111;//绑定手机号
|
||||
const GET_BACK_PAY_CODE_NOTICE = 112;//找回支付密码
|
||||
|
||||
|
||||
//通知平台
|
||||
const USER_PAID_NOTICE_PLATFORM = 200;//会员支付下单通知平台
|
||||
const AFTER_SALE_NOTICE_PLATFORM = 201;//会员发起售后退款通知
|
||||
|
||||
|
||||
|
||||
//订单相关场景
|
||||
const ORDER_SCENE = [
|
||||
self::ORDER_PAY_NOTICE,
|
||||
self::ORDER_DELIVERY_NOTICE,
|
||||
self::PLATFORM_PASS_REFUND_NOTICE,
|
||||
self::PLATFORM_REFUSE_REFUND_NOTICE,
|
||||
];
|
||||
|
||||
|
||||
//通知平台的场景
|
||||
const NOTICE_PLATFORM_SCENE = [
|
||||
self::USER_PAID_NOTICE_PLATFORM,
|
||||
self::AFTER_SALE_NOTICE_PLATFORM,
|
||||
];
|
||||
|
||||
|
||||
//通知会员的场景
|
||||
const NOTICE_USER_SCENE = [
|
||||
self::ORDER_PAY_NOTICE,
|
||||
self::ORDER_DELIVERY_NOTICE,
|
||||
self::PLATFORM_PASS_REFUND_NOTICE,
|
||||
self::PLATFORM_REFUSE_REFUND_NOTICE,
|
||||
self::CHANGE_MOBILE_NOTICE,
|
||||
self::GET_BACK_MOBILE_NOTICE,
|
||||
self::REGISTER_SUCCESS_NOTICE,
|
||||
self::INVITE_SUCCESS_NOTICE,
|
||||
self::GET_EARNINGS_NOTICE,
|
||||
];
|
||||
|
||||
//通知游客(还不存在当前系统的人)
|
||||
const NOTICE_OTHER_SCENE = [
|
||||
self::REGISTER_NOTICE
|
||||
];
|
||||
|
||||
|
||||
//验证码的场景
|
||||
const NOTICE_NEED_CODE = [
|
||||
self::REGISTER_NOTICE,
|
||||
self::CHANGE_MOBILE_NOTICE,
|
||||
self::GET_BACK_MOBILE_NOTICE,
|
||||
self::GET_GODE_LOGIN_NOTICE,
|
||||
self::BIND_MOBILE_NOTICE,
|
||||
self::GET_BACK_PAY_CODE_NOTICE,
|
||||
];
|
||||
|
||||
|
||||
//场景值-兼容旧短信场景逻辑
|
||||
const SMS_SCENE = [
|
||||
'DDZFTZ' => self::ORDER_PAY_NOTICE,
|
||||
'DDFHTZ' => self::ORDER_DELIVERY_NOTICE,
|
||||
'SJTYSHTK' => self::PLATFORM_PASS_REFUND_NOTICE,
|
||||
'SJJJSHTK' => self::PLATFORM_REFUSE_REFUND_NOTICE,
|
||||
'ZCYZ' => self::REGISTER_NOTICE,
|
||||
'ZHMM' => self::GET_BACK_MOBILE_NOTICE,
|
||||
'DDTZ' => self::USER_PAID_NOTICE_PLATFORM,
|
||||
'SHTKDDTZ' => self::AFTER_SALE_NOTICE_PLATFORM,
|
||||
'YZMDL' => self::GET_GODE_LOGIN_NOTICE,
|
||||
'BGSJHM' => self::CHANGE_MOBILE_NOTICE,
|
||||
'BDSJHM' => self::BIND_MOBILE_NOTICE,
|
||||
'ZHZFMM' => self::GET_BACK_PAY_CODE_NOTICE,
|
||||
];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 获取场景描述
|
||||
* @param $state
|
||||
* @return array|mixed|string
|
||||
* @author 段誉(2021/4/26 16:15)
|
||||
*/
|
||||
public static function getSceneDesc($state)
|
||||
{
|
||||
$data = [
|
||||
self::ORDER_PAY_NOTICE => '订单已支付',
|
||||
self::ORDER_DELIVERY_NOTICE => '订单已发货',
|
||||
self::PLATFORM_PASS_REFUND_NOTICE => '平台通过售后退款通知',
|
||||
self::PLATFORM_REFUSE_REFUND_NOTICE => '平台拒绝售后退款通知',
|
||||
self::REGISTER_NOTICE => '注册通知',
|
||||
self::CHANGE_MOBILE_NOTICE => '变更手机号短信通知',
|
||||
self::GET_BACK_MOBILE_NOTICE => '重置密码短信通知',
|
||||
self::REGISTER_SUCCESS_NOTICE => '注册成功',
|
||||
self::INVITE_SUCCESS_NOTICE => '邀请成功',
|
||||
self::GET_EARNINGS_NOTICE => '获得收益',
|
||||
self::GET_GODE_LOGIN_NOTICE => '验证码登录',
|
||||
self::BIND_MOBILE_NOTICE => '绑定手机号',
|
||||
self::GET_BACK_PAY_CODE_NOTICE => '找回支付密码',
|
||||
|
||||
self::USER_PAID_NOTICE_PLATFORM => '会员支付下单通知平台',
|
||||
self::AFTER_SALE_NOTICE_PLATFORM => '会员发起售后退款通知',
|
||||
];
|
||||
if ($state === true) {
|
||||
return $data;
|
||||
}
|
||||
return $data[$state] ?? '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 根据场景获取跳转地址
|
||||
* @param $scene
|
||||
* @author 段誉(2021/4/27 17:01)
|
||||
* @return array
|
||||
*/
|
||||
public static function getPathByScene($scene, $extra_id)
|
||||
{
|
||||
$page = '/pages/index/index'; // 小程序主页路径
|
||||
$url = '/mobile/pages/index/index'; // 公众号主页路径
|
||||
if (in_array($scene, self::ORDER_SCENE)) {
|
||||
$url = '/mobile/pages/order_details/order_details?id='.$extra_id;
|
||||
$page = '/pages/order_details/order_details?id='.$extra_id;
|
||||
}
|
||||
return ['url' => $url, 'page' => $page];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 场景名称
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @author 段誉(2021/4/26 16:56)
|
||||
* @return array|mixed|string
|
||||
*/
|
||||
public function getSceneAttr($value, $data)
|
||||
{
|
||||
return self::getSceneDesc($value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 场景变量
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @author 段誉(2021/4/26 17:07)
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVariableAttr($value, $data)
|
||||
{
|
||||
return $this->jsonToArr($value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 系统消息
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @author 段誉(2021/4/26 17:18)
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function getSystemNoticeAttr($value, $data)
|
||||
{
|
||||
return $this->jsonToArr($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 短信消息
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @author 段誉(2021/4/26 17:25)
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function getSmsNoticeAttr($value, $data)
|
||||
{
|
||||
return $this->jsonToArr($value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 公众号消息
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @author 段誉(2021/4/26 17:25)
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function getOaNoticeAttr($value, $data)
|
||||
{
|
||||
return $this->jsonToArr($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 小程序消息
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @author 段誉(2021/4/26 17:25)
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function getMnpNoticeAttr($value, $data)
|
||||
{
|
||||
return $this->jsonToArr($value);
|
||||
}
|
||||
|
||||
|
||||
public function jsonToArr($data)
|
||||
{
|
||||
return empty($data) ? [] : json_decode($data, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
}
|
||||
183
application/common/model/Order.php
Normal file
183
application/common/model/Order.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Order extends Model
|
||||
{
|
||||
protected $name = 'order';
|
||||
|
||||
//订单类型
|
||||
const NORMAL_ORDER = 0;//普通订单
|
||||
const SECKILL_ORDER = 1;//秒杀订单
|
||||
const TEAM_ORDER = 2;//拼团订单
|
||||
const BARGAIN_ORDER = 3;//砍价订单
|
||||
|
||||
//订单状态
|
||||
const STATUS_WAIT_PAY = 0; //待付款
|
||||
const STATUS_WAIT_DELIVERY = 1; //待发货
|
||||
const STATUS_WAIT_RECEIVE = 2; //待收货
|
||||
const STATUS_FINISH = 3; //已完成
|
||||
const STATUS_CLOSE = 4; //已关闭
|
||||
|
||||
//配送方式
|
||||
const DELIVERY_STATUS_EXPRESS = 1;//快递配送
|
||||
const DELIVERY_STATUS_SELF = 2;//上门自提
|
||||
const DELIVERY_STATUS_CITY = 3;//同城配送
|
||||
|
||||
//订单状态
|
||||
public static function getOrderStatus($status = true)
|
||||
{
|
||||
$desc = [
|
||||
self::STATUS_WAIT_PAY => '待付款',
|
||||
self::STATUS_WAIT_DELIVERY => '待发货',
|
||||
self::STATUS_WAIT_RECEIVE => '待收货',
|
||||
self::STATUS_FINISH => '已完成',
|
||||
self::STATUS_CLOSE => '已关闭',
|
||||
];
|
||||
if ($status === true) {
|
||||
return $desc;
|
||||
}
|
||||
return $desc[$status] ?? '未知';
|
||||
}
|
||||
|
||||
|
||||
//订单类型
|
||||
public static function getOrderType($type)
|
||||
{
|
||||
$desc = [
|
||||
self::NORMAL_ORDER => '普通订单',
|
||||
self::SECKILL_ORDER => '秒杀订单',
|
||||
self::TEAM_ORDER => '拼团订单',
|
||||
self::BARGAIN_ORDER => '砍价订单',
|
||||
];
|
||||
|
||||
if ($type === true){
|
||||
return $desc;
|
||||
}
|
||||
return $desc[$type] ?? '未知';
|
||||
}
|
||||
|
||||
//配送方式
|
||||
public static function getDeliveryType($type)
|
||||
{
|
||||
$desc = [
|
||||
self::DELIVERY_STATUS_EXPRESS => '快递发货',
|
||||
self::DELIVERY_STATUS_SELF => '上门自提',
|
||||
self::DELIVERY_STATUS_CITY => '同城配送',
|
||||
];
|
||||
|
||||
if ($type === true){
|
||||
return $desc;
|
||||
}
|
||||
return $desc[$type] ?? '未知';
|
||||
}
|
||||
|
||||
|
||||
//下单时间
|
||||
public function getCreateTimeAttr($value, $data)
|
||||
{
|
||||
return date('Y-m-d H:i:s', $value);
|
||||
}
|
||||
|
||||
//付款时间
|
||||
public function getPayTimeAttr($value, $data)
|
||||
{
|
||||
if ($value) {
|
||||
return date('Y-m-d H:i:s', $value);
|
||||
}
|
||||
$value = '未支付';
|
||||
return $value;
|
||||
}
|
||||
|
||||
// 发货时间
|
||||
public function getShippingTimeAttr($value, $data)
|
||||
{
|
||||
if ($value) {
|
||||
return date('Y-m-d H:i:s', $value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
//收货时间
|
||||
public function getTakeTimeAttr($value, $data)
|
||||
{
|
||||
if ($value) {
|
||||
return date('Y-m-d H:i:s', $value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
//取消时间
|
||||
public function getCancelTimeAttr($value, $data)
|
||||
{
|
||||
if ($value) {
|
||||
return date('Y-m-d H:i:s', $value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
//订单类型
|
||||
public function getOrderTypeTextAttr($value, $data)
|
||||
{
|
||||
return self::getOrderType($data['order_type']);
|
||||
}
|
||||
|
||||
//订单状态
|
||||
public function getOrderStatusTextAttr($value, $data)
|
||||
{
|
||||
return self::getOrderStatus($data['order_status']);
|
||||
}
|
||||
|
||||
//订单支付方式
|
||||
public function getPayWayTextAttr($value, $data)
|
||||
{
|
||||
return Pay::getPayWay($data['pay_way']);
|
||||
}
|
||||
|
||||
//订单支付状态
|
||||
public function getPayStatusTextAttr($value, $data)
|
||||
{
|
||||
return Pay::getPayStatus($data['pay_status']);
|
||||
}
|
||||
|
||||
//订单来源
|
||||
public function getOrderSourceTextAttr($value, $data)
|
||||
{
|
||||
return Client_::getClient($data['order_source']);
|
||||
}
|
||||
|
||||
//订单商品数量
|
||||
public function getGoodsCountAttr($value, $data)
|
||||
{
|
||||
return count($this->order_goods);
|
||||
}
|
||||
|
||||
|
||||
//订单关联商品
|
||||
public function orderGoods()
|
||||
{
|
||||
return $this->hasMany('order_goods', 'order_id', 'id');
|
||||
}
|
||||
|
||||
//订单用户
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne('user', 'id', 'user_id')
|
||||
->field('id,sn,nickname,avatar,level,mobile,sex,create_time');
|
||||
}
|
||||
|
||||
//收货地址
|
||||
public function getDeliveryAddressAttr($value, $data)
|
||||
{
|
||||
$region = Db::name('dev_region')
|
||||
->where('id', 'IN', [$data['province'], $data['city'], $data['district']])
|
||||
->order('level asc')
|
||||
->column('name');
|
||||
|
||||
$region_desc = implode('', $region);
|
||||
return $region_desc . $data['address'];
|
||||
}
|
||||
}
|
||||
47
application/common/model/OrderGoods.php
Normal file
47
application/common/model/OrderGoods.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use app\common\server\UrlServer;
|
||||
use think\Model;
|
||||
|
||||
class OrderGoods extends Model
|
||||
{
|
||||
|
||||
//订单商品退款状态
|
||||
const REFUND_STATUS_NO = 0;//未申请退款
|
||||
const REFUND_STATUS_APPLY = 1;//申请退款
|
||||
const REFUND_STATUS_WAIT = 2;//等待退款
|
||||
const REFUND_STATUS_SUCCESS = 3;//退款成功
|
||||
|
||||
public function getImageAttr($value, $data)
|
||||
{
|
||||
if ($value) {
|
||||
return UrlServer::getFileUrl($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function getBaseImageAttr($value, $data)
|
||||
{
|
||||
return $data['image'];
|
||||
}
|
||||
|
||||
}
|
||||
87
application/common/model/OrderLog.php
Normal file
87
application/common/model/OrderLog.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class OrderLog extends Model
|
||||
{
|
||||
//操作人类型
|
||||
const TYPE_USER = 0;//会员
|
||||
const TYPE_SHOP = 1;//门店
|
||||
const TYPE_SYSTEM = 2;//系统
|
||||
|
||||
//订单动作
|
||||
const USER_ADD_ORDER = 101;//提交订单
|
||||
const USER_CANCEL_ORDER = 102;//取消订单
|
||||
const USER_DEL_ORDER = 103;//删除订单
|
||||
const USER_CONFIRM_ORDER = 104;//确认收货
|
||||
const USER_PAID_ORDER = 105;//支付订单
|
||||
|
||||
const SHOP_CANCEL_ORDER = 201;//商家取消订单
|
||||
const SHOP_DEL_ORDER = 202;//商家删除订单
|
||||
const SHOP_DELIVERY_ORDER = 203;//商家发货
|
||||
const SHOP_CONFIRM_ORDER = 204;//商家确认收货
|
||||
|
||||
const SYSTEM_CANCEL_ORDER = 301;//系统取消订单
|
||||
const SYSTEM_CONFIRM_ORDER = 302;//系统确认订单
|
||||
|
||||
//订单动作明细
|
||||
public static function getLogDesc($log)
|
||||
{
|
||||
$desc = [
|
||||
self::USER_ADD_ORDER => '会员提交订单',
|
||||
self::USER_CANCEL_ORDER => '会员取消订单',
|
||||
self::USER_DEL_ORDER => '会员删除订单',
|
||||
self::USER_CONFIRM_ORDER => '会员确认收货',
|
||||
self::USER_PAID_ORDER => '会员支付订单',
|
||||
|
||||
self::SHOP_CANCEL_ORDER => '商家取消订单',
|
||||
self::SHOP_DEL_ORDER => '商家删除订单',
|
||||
self::SHOP_DELIVERY_ORDER => '商家发货',
|
||||
self::SHOP_CONFIRM_ORDER => '商家确认收货',
|
||||
|
||||
self::SYSTEM_CANCEL_ORDER => '系统取消订单',
|
||||
self::SYSTEM_CONFIRM_ORDER => '系统确认收货',
|
||||
];
|
||||
|
||||
if ($log === true) {
|
||||
return $desc;
|
||||
}
|
||||
|
||||
return isset($desc[$log]) ? $desc[$log] : $log;
|
||||
}
|
||||
|
||||
//订单日志
|
||||
public static function getOrderLog($order_id)
|
||||
{
|
||||
$logs = Db::name('order_log')
|
||||
->where('order_id', $order_id)
|
||||
->select();
|
||||
|
||||
foreach ($logs as &$log){
|
||||
$log['create_time'] = date('Y-m-d H:i:s', $log['create_time']);
|
||||
$log['channel'] = self::getLogDesc($log['channel']);
|
||||
}
|
||||
|
||||
return $logs;
|
||||
}
|
||||
}
|
||||
106
application/common/model/Pay.php
Normal file
106
application/common/model/Pay.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use app\common\server\UrlServer;
|
||||
use think\Model;
|
||||
|
||||
class Pay extends Model
|
||||
{
|
||||
|
||||
protected $name = 'dev_pay';
|
||||
|
||||
|
||||
const UNPAID = 0;//待支付
|
||||
const ISPAID = 1;//已支付
|
||||
const REFUNDED = 2;//已退款
|
||||
const REFUSED_REFUND = 3;//拒绝退款
|
||||
|
||||
//支付方式
|
||||
const WECHAT_PAY = 1;//微信支付
|
||||
const ALI_PAY = 2;//支付宝支付
|
||||
const BALANCE_PAY = 3;//余额支付
|
||||
const OFFLINE_PAY = 4;//线下支付
|
||||
|
||||
|
||||
//支付状态
|
||||
public static function getPayStatus($type)
|
||||
{
|
||||
$data = [
|
||||
self::UNPAID => '待支付',
|
||||
self::ISPAID => '已支付',
|
||||
self::REFUNDED => '已退款',
|
||||
self::REFUSED_REFUND => '拒绝退款',
|
||||
];
|
||||
|
||||
if ($type === true) {
|
||||
return $data;
|
||||
}
|
||||
return $data[$type] ?? '未知';
|
||||
}
|
||||
|
||||
|
||||
//支付方式
|
||||
public static function getPayWay($type)
|
||||
{
|
||||
$data = [
|
||||
self::WECHAT_PAY => '微信支付',
|
||||
self::ALI_PAY => '支付宝支付',
|
||||
self::BALANCE_PAY => '余额支付',
|
||||
self::OFFLINE_PAY => '线下支付',
|
||||
];
|
||||
|
||||
if ($type === true) {
|
||||
return $data;
|
||||
}
|
||||
return $data[$type] ?? '其他';
|
||||
}
|
||||
|
||||
|
||||
|
||||
//图片路径
|
||||
public function getIconAttr($value, $data)
|
||||
{
|
||||
return UrlServer::getFileUrl($value);
|
||||
}
|
||||
|
||||
|
||||
//支付设置状态
|
||||
public function getStatusTextAttr($value, $data)
|
||||
{
|
||||
if ($data['status'] == 1){
|
||||
return '启用';
|
||||
}
|
||||
return '关闭';
|
||||
}
|
||||
|
||||
|
||||
//各种支付的配置
|
||||
public function getConfigAttr($value, $data)
|
||||
{
|
||||
if ($value){
|
||||
return json_decode($value, true);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
26
application/common/model/Shop.php
Normal file
26
application/common/model/Shop.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
use think\Model;
|
||||
|
||||
class Shop extends Model
|
||||
{
|
||||
|
||||
}
|
||||
47
application/common/model/ShopAccountLog.php
Normal file
47
application/common/model/ShopAccountLog.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\model;
|
||||
use think\Model;
|
||||
|
||||
class ShopAccountLog extends Model{
|
||||
const ORDER_SETTLE = 100; //店铺结算
|
||||
const WITHDRAW_AUDIT = 200; //店铺提现
|
||||
const WITHDRAW_REFUSE = 201; //店铺提现拒绝
|
||||
|
||||
|
||||
public static function getSourceTypeDesc($from){
|
||||
$desc = [
|
||||
self::ORDER_SETTLE => '店铺结算',
|
||||
self::WITHDRAW_AUDIT => '店铺提现',
|
||||
self::WITHDRAW_REFUSE => '店铺提现拒绝',
|
||||
];
|
||||
if($from === true){
|
||||
return $desc;
|
||||
}
|
||||
return $desc[$from] ?? '账户变动';
|
||||
}
|
||||
|
||||
public static function getRemarkDesc($from,$source_sn,$remark){
|
||||
$desc = [
|
||||
self::ORDER_SETTLE => '结算单号:'.$source_sn,
|
||||
self::WITHDRAW_AUDIT => '提现单号:'.$source_sn,
|
||||
];
|
||||
return $desc[$from] ?? $remark;
|
||||
}
|
||||
}
|
||||
69
application/common/model/ShopWithdraw.php
Normal file
69
application/common/model/ShopWithdraw.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\model;
|
||||
use think\Model;
|
||||
|
||||
class ShopWithdraw extends Model{
|
||||
|
||||
const WAIT_AUDIT = 1;
|
||||
const WAIT_REMITTANCE = 2;
|
||||
const SUCCEED_REMITTANCE =3;
|
||||
const AUDIT_REFUSE = 4;
|
||||
|
||||
|
||||
public static function getStatus($from){
|
||||
$desc = [
|
||||
self::WAIT_AUDIT => '待审核',
|
||||
self::WAIT_REMITTANCE => '待转账',
|
||||
self::SUCCEED_REMITTANCE => '已转账',
|
||||
self::AUDIT_REFUSE => '审核拒绝',
|
||||
];
|
||||
if($from === true){
|
||||
return $desc;
|
||||
}
|
||||
return $desc[$from] ?? '';
|
||||
}
|
||||
public function getCreateTimeAttr($value,$data){
|
||||
return date('Y-m-d H:i:s',$value);
|
||||
}
|
||||
|
||||
public function getMoneyAttr($value,$data){
|
||||
return '¥'.$value;
|
||||
}
|
||||
|
||||
public function getStatusDescAttr($value,$data){
|
||||
return self::getStatus($data['status']);
|
||||
}
|
||||
//todo 提现方式
|
||||
public function getWithdrawWayAttr($value,$data){
|
||||
$name = '银行卡';
|
||||
if($value == 2){
|
||||
$name = '支付宝';
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
public function getRemittanceTimeAttr($value,$data){
|
||||
if($value){
|
||||
return date('Y-m-d H:i:s',$value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
24
application/common/model/SmsConfig.php
Normal file
24
application/common/model/SmsConfig.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\model;
|
||||
use think\Model;
|
||||
|
||||
class SmsConfig extends Model{
|
||||
|
||||
}
|
||||
56
application/common/model/SmsLog.php
Normal file
56
application/common/model/SmsLog.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\model;
|
||||
use think\Model;
|
||||
|
||||
class SmsLog extends Model{
|
||||
const send_ing = 0;
|
||||
const send_success = 1;
|
||||
const send_fail = 2;
|
||||
|
||||
public static function getSendStatusDesc($from){
|
||||
$desc = [
|
||||
self::send_ing => '发送中',
|
||||
self::send_success => '发送成功',
|
||||
self::send_fail => '发送失败',
|
||||
];
|
||||
if($from === true){
|
||||
return $desc;
|
||||
}
|
||||
return $desc[$from] ?? '';
|
||||
}
|
||||
|
||||
public static function getCreateTimeAttr($value,$data){
|
||||
return date('Y-m-d H:i:s',$value);
|
||||
}
|
||||
public static function getSendTimeAttr($value,$data){
|
||||
if($value){
|
||||
return date('Y-m-d H:i:s',$value);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public static function getSendStatusAttr($value,$data){
|
||||
return self::getSendStatusDesc($value);
|
||||
}
|
||||
|
||||
public static function getResultsAttr($value,$data){
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
33
application/common/model/Team.php
Normal file
33
application/common/model/Team.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 拼团
|
||||
* Class Team
|
||||
* @package app\common\model
|
||||
*/
|
||||
class Team extends Model
|
||||
{
|
||||
const STATUS_WAIT_SUCCESS = 0;
|
||||
const STATUS_SUCCESS = 1;
|
||||
const STATUS_ERROR = 2;
|
||||
|
||||
//拼团状态
|
||||
public static function getStatusDesc($type)
|
||||
{
|
||||
$desc = [
|
||||
self::STATUS_WAIT_SUCCESS => '拼团中',
|
||||
self::STATUS_SUCCESS => '拼团成功',
|
||||
self::STATUS_ERROR => '拼团失败',
|
||||
];
|
||||
|
||||
if ($type === true){
|
||||
return $desc;
|
||||
}
|
||||
return $desc[$type] ?? '';
|
||||
}
|
||||
}
|
||||
24
application/common/model/TeamActivity.php
Normal file
24
application/common/model/TeamActivity.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 拼团活动商品-模型
|
||||
* Class TeamActivity
|
||||
* @package app\common\model
|
||||
*/
|
||||
class TeamActivity extends Model
|
||||
{
|
||||
// protected $pk = 'team_id';
|
||||
/**
|
||||
* Notes: 关联拼团模型
|
||||
* @author 张无忌(2021/1/14 15:34)
|
||||
*/
|
||||
public function teamFound()
|
||||
{
|
||||
return $this->hasMany('TeamFound', 'team_id', 'team_id');
|
||||
}
|
||||
}
|
||||
39
application/common/model/TeamFollow.php
Normal file
39
application/common/model/TeamFollow.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 拼团参团
|
||||
* Class TeamFollow
|
||||
* @package app\common\model
|
||||
*/
|
||||
class TeamFollow extends Model
|
||||
{
|
||||
// 关联用户模型
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne('user', 'id', 'follow_user_id')
|
||||
->field('id,sn,nickname,avatar,level,mobile,sex,create_time');
|
||||
}
|
||||
}
|
||||
44
application/common/model/TeamFound.php
Normal file
44
application/common/model/TeamFound.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 拼团开团
|
||||
* Class TeamFound
|
||||
* @package app\common\model
|
||||
*/
|
||||
class TeamFound extends Model
|
||||
{
|
||||
// 关联用户模型
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne('user', 'id', 'user_id')
|
||||
->field('id,sn,nickname,avatar,level,mobile,sex,create_time');
|
||||
}
|
||||
|
||||
public function teamFollow()
|
||||
{
|
||||
return $this->hasMany('team_follow', 'found_id', 'id');
|
||||
}
|
||||
}
|
||||
16
application/common/model/TeamGoodsItem.php
Normal file
16
application/common/model/TeamGoodsItem.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 拼团商品规格模型
|
||||
* Class TeamGoodsItem
|
||||
* @package app\common\model
|
||||
*/
|
||||
class TeamGoodsItem extends Model
|
||||
{
|
||||
|
||||
}
|
||||
64
application/common/model/User.php
Normal file
64
application/common/model/User.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use app\common\server\UrlServer;
|
||||
use think\Model;
|
||||
|
||||
class User extends Model
|
||||
{
|
||||
//头像
|
||||
public function getAvatarAttr($value, $data)
|
||||
{
|
||||
if ($value) {
|
||||
return UrlServer::getFileUrl($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function getBaseAvatarAttr($value, $data)
|
||||
{
|
||||
return $data['avatar'];
|
||||
}
|
||||
|
||||
//加入时间
|
||||
public function getCreateTimeAttr($value, $data)
|
||||
{
|
||||
return date('Y-m-d H:i:s', $value);
|
||||
}
|
||||
|
||||
//性别转换
|
||||
public function getSexAttr($value, $data)
|
||||
{
|
||||
switch ($value) {
|
||||
case 1:
|
||||
return '男';
|
||||
case 2:
|
||||
return '女';
|
||||
default:
|
||||
return '未知';
|
||||
}
|
||||
}
|
||||
|
||||
public function level()
|
||||
{
|
||||
return $this->hasOne('UserLevel','id', 'level');
|
||||
}
|
||||
}
|
||||
11
application/common/model/UserLevel.php
Normal file
11
application/common/model/UserLevel.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use think\Model;
|
||||
|
||||
class UserLevel extends Model
|
||||
{
|
||||
|
||||
}
|
||||
83
application/common/model/UserTask.php
Normal file
83
application/common/model/UserTask.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\model;
|
||||
use think\Model;
|
||||
|
||||
class UserTask extends Model{
|
||||
//会员任务
|
||||
const USERTASK = [
|
||||
[
|
||||
'type' =>'SatisfactionIntegral',
|
||||
'name' =>'满足积分{$num}',
|
||||
'real_name' =>'积分数',
|
||||
'max_number' =>0,
|
||||
'min_number' =>0,
|
||||
'unit' =>'分'
|
||||
],
|
||||
[
|
||||
'type' =>'ConsumptionAmount',
|
||||
'name' =>'消费满{$num}',
|
||||
'real_name' =>'消费金额',
|
||||
'max_number' =>0,
|
||||
'min_number' =>0,
|
||||
'unit' =>'元'
|
||||
],
|
||||
[
|
||||
'type' =>'ConsumptionFrequency',
|
||||
'name' =>'消费{$num}',
|
||||
'real_name' =>'消费次数',
|
||||
'max_number' =>0,
|
||||
'min_number' =>0,
|
||||
'unit' =>'次'
|
||||
],
|
||||
[
|
||||
'type' =>'CumulativeAttendance',
|
||||
'name' =>'累计签到{$num}',
|
||||
'real_name' =>'累计签到',
|
||||
'max_number' =>365,
|
||||
'min_number' =>1,
|
||||
'unit' =>'天'
|
||||
],
|
||||
[
|
||||
'type' =>'SharingTimes',
|
||||
'name' =>'分享给朋友{$num}',
|
||||
'real_name' =>'分享给朋友',
|
||||
'max_number' =>1000,
|
||||
'min_number' =>1,
|
||||
'unit' =>'次'
|
||||
],
|
||||
[
|
||||
'type' =>'InviteGoodFriends',
|
||||
'name' =>'邀请好友{$num}成为下线',
|
||||
'real_name' =>'邀请好友成为下线',
|
||||
'max_number' =>1000,
|
||||
'min_number' =>1,
|
||||
'unit' =>'人'
|
||||
],
|
||||
[
|
||||
'type' =>'InviteGoodFriendsLevel',
|
||||
'name' =>'邀请好友{$num}成为会员',
|
||||
'real_name' =>'邀请好友成为会员',
|
||||
'max_number' =>1000,
|
||||
'min_number' =>1,
|
||||
'unit' =>'人'
|
||||
],
|
||||
];
|
||||
|
||||
}
|
||||
58
application/common/model/WeChat.php
Normal file
58
application/common/model/WeChat.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\model;
|
||||
use think\Model;
|
||||
|
||||
class WeChat extends Model{
|
||||
/**
|
||||
* 消息类型常量
|
||||
*/
|
||||
const msg_type_text = 'text'; //回复文本信息
|
||||
const msg_type_image = 'image'; //回复图片信息
|
||||
const msg_type_voice = 'voice'; //回复语音信息
|
||||
const msg_type_video = 'video'; //回复视频消息
|
||||
const msg_type_music = 'music'; //回复音乐消息
|
||||
const msg_type_news = 'news'; //回复图文消息
|
||||
const msg_type_location = 'location'; //回复地理位置消息
|
||||
const msg_type_link = 'link'; //回复链接信息
|
||||
const msg_type_event = 'event'; //回复事件
|
||||
const msg_type_default = 'default'; //默认回复
|
||||
|
||||
/**
|
||||
* 事件类型常量
|
||||
*/
|
||||
const msg_event_subscribe = 'subscribe'; //关注事件-首次关注
|
||||
const msg_event_unsubscribe = 'unsubscribe'; //取消关注事件
|
||||
const msg_event_scan = 'SCAN'; //关注事件-已关注
|
||||
const msg_event_location = 'LOCATION'; //上报地理位置事件
|
||||
const msg_event_click = 'CLICK'; //点击菜单拉取消息时的事件推送
|
||||
const msg_event_view = 'VIEW'; //点击菜单跳转链接时的事件
|
||||
|
||||
public static function getCustomReply($form = true){
|
||||
$desc = [
|
||||
self::msg_event_subscribe => '关注回复',
|
||||
self::msg_type_text => '关键词回复',
|
||||
self::msg_type_default => '默认回复',
|
||||
];
|
||||
if( true === $form){
|
||||
return $desc;
|
||||
}
|
||||
return $desc[$form] ??[];
|
||||
}
|
||||
}
|
||||
71
application/common/model/Withdraw.php
Normal file
71
application/common/model/Withdraw.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class Withdraw extends Model
|
||||
{
|
||||
|
||||
//提现类型
|
||||
const TYPE_BALANCE = 1; // 提现到钱包余额
|
||||
const TYPE_WECHAT_CHANGE = 2; // 提现到微信零钱
|
||||
const TYPE_WECHAT_CODE = 3; // 提现到微信收款码
|
||||
const TYPE_ALI_CODE = 4; // 提现到支付宝收款码
|
||||
const TYPE_BANK = 5; // 提现到银行卡
|
||||
|
||||
|
||||
//提现状态
|
||||
const STATUS_WAIT = 1; // 待提现
|
||||
const STATUS_ING = 2; // 提现中
|
||||
const STATUS_SUCCESS = 3; // 提现成功
|
||||
const STATUS_FAIL = 4; //提现失败
|
||||
|
||||
//提现状态
|
||||
public static function getStatusDesc($status = true)
|
||||
{
|
||||
$desc = [
|
||||
self::STATUS_WAIT => '待提现',
|
||||
self::STATUS_ING => '提现中',
|
||||
self::STATUS_SUCCESS => '提现成功',
|
||||
self::STATUS_FAIL => '提现失败'
|
||||
];
|
||||
if ($status === true) {
|
||||
return $desc;
|
||||
}
|
||||
return $desc[$status] ?? '';
|
||||
}
|
||||
|
||||
//提现类型
|
||||
public static function getTypeDesc($status = true)
|
||||
{
|
||||
$desc = [
|
||||
self::TYPE_BALANCE => '钱包余额',
|
||||
self::TYPE_WECHAT_CHANGE => '微信零钱',
|
||||
self::TYPE_BANK => '银行卡',
|
||||
self::TYPE_WECHAT_CODE => '微信收款码',
|
||||
self::TYPE_ALI_CODE => '支付宝收款码',
|
||||
];
|
||||
if ($status === true) {
|
||||
return $desc;
|
||||
}
|
||||
return $desc[$status] ?? '';
|
||||
}
|
||||
}
|
||||
247
application/common/server/AliPayServer.php
Normal file
247
application/common/server/AliPayServer.php
Normal file
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\server;
|
||||
|
||||
|
||||
use Alipay\EasySDK\Kernel\Factory;
|
||||
use Alipay\EasySDK\Kernel\Config;
|
||||
use app\common\logic\PayNotifyLogic;
|
||||
use app\common\model\Client_;
|
||||
use app\common\model\Pay;
|
||||
use think\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
class AliPayServer
|
||||
{
|
||||
|
||||
|
||||
protected $error = '未知错误';
|
||||
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
Factory::setOptions($this->getOptions());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 支付设置
|
||||
* @author 段誉(2021/3/23 10:33)
|
||||
* @return Config
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
$result = (new Pay())->where(['code' => 'alipay'])->find();
|
||||
|
||||
if (empty($result)) {
|
||||
throw new \Exception('请配置好支付设置');
|
||||
}
|
||||
|
||||
$options = new Config();
|
||||
$options->protocol = 'https';
|
||||
$options->gatewayHost = 'openapi.alipay.com';
|
||||
// $options->gatewayHost = 'openapi.alipaydev.com'; //测试沙箱地址
|
||||
$options->signType = 'RSA2';
|
||||
$options->appId = $result['config']['app_id'] ?? '';
|
||||
// 应用私钥
|
||||
$options->merchantPrivateKey = $result['config']['private_key'] ?? '';
|
||||
//支付宝公钥
|
||||
$options->alipayPublicKey = $result['config']['ali_public_key'] ?? '';
|
||||
//回调地址
|
||||
$options->notifyUrl = url('payment/aliNotify', '', '', true);
|
||||
return $options;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: pc支付
|
||||
* @param $attach
|
||||
* @param $order
|
||||
* @author 段誉(2021/3/22 18:38)
|
||||
* @return string
|
||||
*/
|
||||
public function pagePay($attach, $order)
|
||||
{
|
||||
$domain = request()->domain();
|
||||
$result = Factory::payment()->page()->optional('passback_params', $attach)->pay(
|
||||
'订单:'.$order['order_sn'],
|
||||
$order['order_sn'],
|
||||
$order['order_amount'],
|
||||
$domain.'/pc/user/order'
|
||||
);
|
||||
return $result->body;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: app支付
|
||||
* @param $attach
|
||||
* @param $order
|
||||
* @author 段誉(2021/3/22 18:38)
|
||||
* @return string
|
||||
*/
|
||||
public function appPay($attach, $order)
|
||||
{
|
||||
$result = Factory::payment()->app()->optional('passback_params', $attach)->pay(
|
||||
$order['order_sn'],
|
||||
$order['order_sn'],
|
||||
$order['order_amount']
|
||||
);
|
||||
return $result->body;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 手机网页支付
|
||||
* @param $attach
|
||||
* @param $order
|
||||
* @author 段誉(2021/3/22 18:38)
|
||||
* @return string
|
||||
*/
|
||||
public function wapPay($attach, $order)
|
||||
{
|
||||
$domain = request()->domain();
|
||||
$result = Factory::payment()->wap()->optional('passback_params', $attach)->pay(
|
||||
'订单:'.$order['order_sn'],
|
||||
$order['order_sn'],
|
||||
$order['order_amount'],
|
||||
$domain.'/mobile/pages/user_order/user_order',
|
||||
$domain.'/mobile/pages/user_order/user_order'
|
||||
);
|
||||
return $result->body;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 支付
|
||||
* @param $from
|
||||
* @param $order
|
||||
* @param $order_source
|
||||
* @author 段誉(2021/3/22 18:33)
|
||||
* @return bool|string
|
||||
*/
|
||||
public function pay($from, $order, $order_source)
|
||||
{
|
||||
try{
|
||||
switch ($order_source){
|
||||
case Client_::pc:
|
||||
$result = $this->pagePay($from, $order);
|
||||
break;
|
||||
case Client_::ios:
|
||||
case Client_::android:
|
||||
$result = $this->appPay($from, $order);
|
||||
break;
|
||||
case Client_::h5:
|
||||
$result = $this->wapPay($from, $order);
|
||||
break;
|
||||
default:
|
||||
throw new \Exception('支付方式错误');
|
||||
}
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
$this->error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 支付回调验证
|
||||
* @param $data
|
||||
* @author 段誉(2021/3/22 17:22)
|
||||
* @return bool
|
||||
*/
|
||||
public function verifyNotify($data)
|
||||
{
|
||||
try {
|
||||
$verify = Factory::payment()->common()->verifyNotify($data);
|
||||
if (false === $verify) {
|
||||
throw new \Exception('异步通知验签失败');
|
||||
}
|
||||
if (!in_array($data['trade_status'], ['TRADE_SUCCESS', 'TRADE_FINISHED'])) {
|
||||
return true;
|
||||
}
|
||||
$extra['transaction_id'] = $data['trade_no'];
|
||||
//验证订单是否已支付
|
||||
switch ($data['passback_params']) {
|
||||
case 'order':
|
||||
$order = Db::name('order')->where(['order_sn' => $data['out_trade_no']])->find();
|
||||
if (!$order || $order['pay_status'] >= Pay::ISPAID) {
|
||||
return true;
|
||||
}
|
||||
PayNotifyLogic::handle('order', $data['out_trade_no'], $extra);
|
||||
break;
|
||||
|
||||
case 'recharge':
|
||||
$order = Db::name('recharge_order')->where(['order_sn' => $data['out_trade_no']])->find();
|
||||
if (!$order || $order['pay_status'] >= Pay::ISPAID) {
|
||||
return true;
|
||||
}
|
||||
PayNotifyLogic::handle('recharge', $data['out_trade_no'], $extra);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$record = [
|
||||
__CLASS__, __FUNCTION__, $e->getFile(), $e->getLine(), $e->getMessage()
|
||||
];
|
||||
Log::record(implode('-', $record));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 查询订单
|
||||
* @param $order_sn
|
||||
* @author 段誉(2021/3/23 15:21)
|
||||
* @return \Alipay\EasySDK\Payment\Common\Models\AlipayTradeQueryResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function checkPay($order_sn)
|
||||
{
|
||||
return Factory::payment()->common()->query($order_sn);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 退款
|
||||
* @param $order_sn 订单号
|
||||
* @param $order_amount 金额
|
||||
* @author 段誉(2021/3/25 10:24)
|
||||
* @return \Alipay\EasySDK\Payment\Common\Models\AlipayTradeRefundResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function refund($order_sn, $order_amount)
|
||||
{
|
||||
return Factory::payment()->common()->refund($order_sn, $order_amount);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
86
application/common/server/Alisms.php
Normal file
86
application/common/server/Alisms.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\server;
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
|
||||
class Alisms
|
||||
{
|
||||
private $app_key = '';
|
||||
private $secret_key = '';
|
||||
private $sign = '';
|
||||
private $mobile = '';
|
||||
private $template_code = '';
|
||||
private $template_param = '';
|
||||
|
||||
public function __construct($config)
|
||||
{
|
||||
$this->sign = $config['sign'];
|
||||
$this->app_key = $config['app_key'];
|
||||
$this->secret_key = $config['secret_key'];
|
||||
}
|
||||
public function setTemplateCode($template_code){
|
||||
$this->template_code = $template_code;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setMobile($mobile){
|
||||
$this->mobile = $mobile;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setTemplateParam($template_param = ''){
|
||||
$this->template_param = json_encode($template_param);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function sendSms(){
|
||||
try {
|
||||
AlibabaCloud::accessKeyClient($this->app_key, $this->secret_key)
|
||||
->regionId('cn-hangzhou')
|
||||
->asDefaultClient();
|
||||
|
||||
$result = AlibabaCloud::rpc()
|
||||
->product('Dysmsapi')
|
||||
// ->scheme('https') // https | http
|
||||
->version('2017-05-25')
|
||||
->action('SendSms')
|
||||
->method('POST')
|
||||
->host('dysmsapi.aliyuncs.com')
|
||||
->options([
|
||||
'query' => [
|
||||
'RegionId' => "cn-hangzhou",
|
||||
'PhoneNumbers' => $this->mobile, //发送手机号
|
||||
'SignName' => $this->sign, //短信签名
|
||||
'TemplateCode' => $this->template_code, //短信模板CODE
|
||||
'TemplateParam' => $this->template_param, //自定义随机数
|
||||
],
|
||||
])
|
||||
->request();
|
||||
return $result->toArray();
|
||||
} catch (ClientException $e) {
|
||||
return $e->getErrorMessage() . PHP_EOL;
|
||||
} catch (ServerException $e) {
|
||||
return $e->getErrorMessage() . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
64
application/common/server/AreaServer.php
Normal file
64
application/common/server/AreaServer.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\server;
|
||||
|
||||
|
||||
use app\common\cache\RegionCache;
|
||||
use think\Db;
|
||||
use think\facade\Cache;
|
||||
|
||||
class AreaServer
|
||||
{
|
||||
/**
|
||||
* 通过id获取地址
|
||||
* @param $val 为非数组,返回单独地点名,为数组时,按顺序拼接地址返回
|
||||
* @param string $address val为数组时,连接详细地址一起返回
|
||||
* @return mixed|string
|
||||
*/
|
||||
public static function getAddress($val, $address = '')
|
||||
{
|
||||
$area_id_name = (new RegionCache(''))->set(3600);
|
||||
if (!is_array($val)) {
|
||||
return isset($area_id_name[$val]) ? $area_id_name[$val] : '';
|
||||
}
|
||||
$long_address = '';
|
||||
foreach ($val as $id) {
|
||||
$long_address .= isset($area_id_name[$id]) ? $area_id_name[$id] : '';
|
||||
}
|
||||
return $long_address . $address;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id获取地址经纬度上
|
||||
* @param $id
|
||||
* @return array|\PDOStatement|string|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function getDb09LngAndLat($id)
|
||||
{
|
||||
return Db::name('dev_region')
|
||||
->where('id', '=', $id)
|
||||
->field(['db09_lng', 'db09_lat'])
|
||||
->find();
|
||||
}
|
||||
}
|
||||
114
application/common/server/ConfigServer.php
Normal file
114
application/common/server/ConfigServer.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\server;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use think\facade\Config;
|
||||
|
||||
class ConfigServer
|
||||
{
|
||||
/**
|
||||
* User: 意象信息科技 lr
|
||||
* Desc: 设置配置值
|
||||
* @param $type
|
||||
* @param $name
|
||||
* @param $value
|
||||
* @return mixed
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public static function set($type, $name, $value)
|
||||
{
|
||||
$original = $value;
|
||||
$update_time = time();
|
||||
if (is_array($value)) {
|
||||
$value = json_encode($value, true);
|
||||
}
|
||||
$data = Db::name('config')
|
||||
->where(['type' => $type, 'name' => $name])
|
||||
->find();
|
||||
if (empty($data)) {
|
||||
Db::name('config')
|
||||
->insert(['type' => $type, 'name' => $name, 'value' => $value]);
|
||||
} else {
|
||||
Db::name('config')
|
||||
->where(['type' => $type, 'name' => $name])
|
||||
->update(['value' => $value, 'update_time' => $update_time]);
|
||||
}
|
||||
return $original;
|
||||
}
|
||||
|
||||
/**
|
||||
* User: 意象信息科技 lr
|
||||
* Desc: 获取配置值
|
||||
* @param $type
|
||||
* @param $name
|
||||
* @param string $default_value
|
||||
* @return mixed|string
|
||||
*/
|
||||
public static function get($type, $name = '', $default_value = null)
|
||||
{
|
||||
if ($name) {
|
||||
$value = Db::name('config')
|
||||
->where(['type' => $type, 'name' => $name])
|
||||
->value('value');
|
||||
$json = json_decode($value, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
$value = $json;
|
||||
}
|
||||
if ($value) {
|
||||
return $value;
|
||||
}
|
||||
if($value ===0 || $value==='0'){
|
||||
return $value;
|
||||
}
|
||||
if ($default_value !== null) {
|
||||
return $default_value;
|
||||
}
|
||||
return Config::get('default.' . $type . '.' . $name);
|
||||
}
|
||||
|
||||
$data = Db::name('config')
|
||||
->where(['type' => $type])
|
||||
->column('value', 'name');
|
||||
|
||||
foreach ($data as $k => $v) {
|
||||
$json = json_decode($v, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
$data[$k] = $json;
|
||||
}
|
||||
}
|
||||
if ($data) {
|
||||
return $data;
|
||||
}
|
||||
if($data ===0 || $data==='0'){
|
||||
return $data;
|
||||
}
|
||||
if ($default_value !== null) {
|
||||
return $default_value;
|
||||
}
|
||||
return Config::get('default.' . $type . '.' . $name);
|
||||
}
|
||||
}
|
||||
271
application/common/server/CrontabServer.php
Normal file
271
application/common/server/CrontabServer.php
Normal file
@@ -0,0 +1,271 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\server;
|
||||
|
||||
|
||||
use Cron\CronExpression;
|
||||
use think\Console;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Config;
|
||||
use think\facade\Debug;
|
||||
use Workerman\Lib\Timer;
|
||||
use Workerman\Worker;
|
||||
|
||||
class CrontabServer
|
||||
{
|
||||
|
||||
public $run_status = false;//运行状态
|
||||
public $cron_lists = []; //任务列表
|
||||
public $system; //1-wondows;2-unix;
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
* CrontabServer constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (Cache::get('crontab_run_status')) {
|
||||
$this->run_status = true;
|
||||
}
|
||||
$this->cron_lists = Db::name('dev_crontab')
|
||||
->where(['status' => 1])
|
||||
->select();
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||
$this->system = 1;
|
||||
} else {
|
||||
$this->system = 2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 运行定时任务
|
||||
* @return string
|
||||
* @throws Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if (empty($this->cron_lists)) {
|
||||
return '当前无需要执行的定时任务或守护进程';
|
||||
}
|
||||
|
||||
Db::name('dev_crontab')
|
||||
->where(['status' => 1])
|
||||
->update(['error' => '']);
|
||||
|
||||
|
||||
if ($this->system == 1) {
|
||||
self::windows($this->cron_lists);
|
||||
} else {
|
||||
self::unix($this->cron_lists);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* unix系统
|
||||
* @param $cron_lists
|
||||
*/
|
||||
private function unix($cron_lists)
|
||||
{
|
||||
$task = new Worker();
|
||||
$task->count = count($cron_lists);//根据列表任务分配线程
|
||||
$task->onWorkerStart = function ($task) use ($cron_lists) {
|
||||
$task_id = $task->id;
|
||||
//创建定时器
|
||||
$timer_id = Timer::add(1, function () use (&$timer_id, $task_id, $cron_lists) {
|
||||
try {
|
||||
self::setStatus();
|
||||
Db::close();
|
||||
$time = time();
|
||||
$cron = $cron_lists[$task_id];
|
||||
if ($cron['type'] == 1) {
|
||||
if (CronExpression::isValidExpression($cron['expression']) === false) {
|
||||
throw new \Exception("规则设置错误"); //定时任务运行规则错误,不执行
|
||||
}
|
||||
$cron_expression = CronExpression::factory($cron['expression']);
|
||||
$last_time = Db::name('dev_crontab')->where(['id' => $cron['id']])->value('last_time');
|
||||
$next_time = $cron_expression->getNextRunDate(date('Y-m-d H:i:s', $last_time))->getTimestamp();
|
||||
if ($next_time >= time()) {
|
||||
sleep(1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//执行定时任务
|
||||
Debug::remark('begin');
|
||||
$parameter = explode(' ', $cron['parameter']);
|
||||
if (is_array($parameter) && !empty($parameter)) {
|
||||
Console::call($cron['command'], $parameter);
|
||||
} else {
|
||||
Console::call($cron['command']);
|
||||
}
|
||||
Debug::remark('end');
|
||||
|
||||
echo "系统任务名称为:{$cron['name']}:" . "\n";
|
||||
|
||||
} catch (\Exception $e) {
|
||||
//运行错误,关闭定时任务
|
||||
echo "系统任务名称为:{$cron['name']}:" . $e->getMessage();
|
||||
Db::name('dev_crontab')
|
||||
->where(['id' => $cron['id']])
|
||||
->update(['error' => $e->getMessage(), 'status' => 3]);
|
||||
Timer::del($timer_id);
|
||||
} catch (Exception $e) {
|
||||
echo "系统任务名称为:{$cron['name']}:" . $e->getMessage();
|
||||
Db::name('dev_crontab')
|
||||
->where(['id' => $cron['id']])
|
||||
->update(['error' => $e->getMessage(), 'status' => 3]);
|
||||
Timer::del($timer_id);
|
||||
}
|
||||
|
||||
$range_time = Debug::getRangeTime('begin', 'end');
|
||||
$max_time = max($cron['max_time'], $range_time);
|
||||
Db::name('dev_crontab')
|
||||
->where(['id' => $cron['id']])
|
||||
->update(['last_time' => $time, 'time' => $range_time, 'max_time' => $max_time]);
|
||||
});
|
||||
};
|
||||
|
||||
Worker::runAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* windows系统下
|
||||
* @param $cron_lists
|
||||
*/
|
||||
private function windows($cron_lists)
|
||||
{
|
||||
$task = new Worker();
|
||||
$task->count = 1;
|
||||
$task->onWorkerStart = function ($task) use ($cron_lists) {
|
||||
//创建定时器
|
||||
$timer_id = Timer::add(1, function () use ($cron_lists) {
|
||||
self::setStatus();
|
||||
foreach ($cron_lists as $k => $v) {
|
||||
$cron = $v;
|
||||
try {
|
||||
$time = time();
|
||||
if ($cron['type'] == 1) {
|
||||
if (CronExpression::isValidExpression($cron['expression']) === false) {
|
||||
throw new \Exception("规则设置错误"); //定时任务运行规则错误,不执行
|
||||
}
|
||||
$cron_expression = CronExpression::factory($cron['expression']);
|
||||
|
||||
$last_time = Db::name('dev_crontab')->where(['id' => $cron['id']])->value('last_time');
|
||||
$next_time = $cron_expression->getNextRunDate(date('Y-m-d H:i:s', $last_time))->getTimestamp();
|
||||
if ($next_time >= time()) {
|
||||
usleep(100000);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
//执行定时任务
|
||||
Debug::remark('begin');
|
||||
$parameter = explode(' ', $cron['parameter']);
|
||||
if (is_array($parameter) && !empty($parameter)) {
|
||||
Console::call($cron['command'], $parameter);
|
||||
} else {
|
||||
Console::call($cron['command']);
|
||||
}
|
||||
Debug::remark('end');
|
||||
|
||||
echo "系统任务名称为:{$cron['name']}:" . "\n";
|
||||
|
||||
} catch (\Exception $e) {
|
||||
//运行错误,关闭定时任务
|
||||
echo "系统任务名称为:{$cron['name']}:" . $e->getMessage();
|
||||
Db::name('dev_crontab')
|
||||
->where(['id' => $cron['id']])
|
||||
->update(['error' => $e->getMessage(), 'status' => 3]);
|
||||
} catch (Exception $e) {
|
||||
echo "系统任务名称为:{$cron['name']}:" . $e->getMessage();
|
||||
Db::name('dev_crontab')
|
||||
->where(['id' => $cron['id']])
|
||||
->update(['error' => $e->getMessage(), 'status' => 3]);
|
||||
}
|
||||
|
||||
$range_time = Debug::getRangeTime('begin', 'end');
|
||||
$max_time = max($cron['max_time'], $range_time);
|
||||
Db::name('dev_crontab')
|
||||
->where(['id' => $cron['id']])
|
||||
->update(['last_time' => $time, 'time' => $range_time, 'max_time' => $max_time]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Worker::runAll();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置状态
|
||||
* @return mixed
|
||||
*/
|
||||
private function setStatus()
|
||||
{
|
||||
return Cache::set('crontab_run_status', 1, 60);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新定时任务状态
|
||||
* @throws Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public function updateStatus()
|
||||
{
|
||||
if ($this->run_status === false) {
|
||||
$this->cron_lists = Db::name('dev_crontab')
|
||||
->where(['status' => 1])
|
||||
->update(['status' => 2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 启动
|
||||
* @param bool $stop
|
||||
*/
|
||||
public function run($stop = true)
|
||||
{
|
||||
$php_path = real_path();
|
||||
$this->setStatus();
|
||||
if ($stop) {
|
||||
if ($this->system == 1) {
|
||||
pclose(popen("start taskkill /f /im php.exe /t", 'r'));
|
||||
} else {
|
||||
pclose(popen($php_path . ' ../think crontab stop --d', 'r'));
|
||||
}
|
||||
} else {
|
||||
if ($this->system == 1) {
|
||||
pclose(popen("start taskkill /f /im php.exe /t", 'r'));
|
||||
sleep(2);
|
||||
pclose(popen("start " . $php_path . " ../think crontab restart --d", 'r'));
|
||||
} else {
|
||||
pclose(popen($php_path . ' ../think crontab restart --d', 'r'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
138
application/common/server/DistributionServer.php
Normal file
138
application/common/server/DistributionServer.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\server;
|
||||
|
||||
|
||||
use think\Db;
|
||||
|
||||
class DistributionServer
|
||||
{
|
||||
public static function commission($order_id)
|
||||
{
|
||||
$field = [
|
||||
'o.user_id' => 'user_id',
|
||||
'og.id' => 'order_goods_id',
|
||||
'og.goods_num' => 'goods_num',
|
||||
'og.total_pay_price' => 'total_price',
|
||||
'g.first_ratio' => 'first_ratio',
|
||||
'g.second_ratio' => 'second_ratio',
|
||||
'g.three_ratio' => 'three_ratio',
|
||||
'u.first_leader' => 'first_leader',
|
||||
'u.second_leader' => 'second_leader',
|
||||
'u.third_leader' => 'third_leader',
|
||||
];
|
||||
$goods_lists = Db::name('order_goods og')
|
||||
->join('goods g', 'og.goods_id=g.id')
|
||||
->join('order o', 'og.order_id=o.id')
|
||||
->join('user u', 'o.user_id=u.id')
|
||||
->field($field)
|
||||
->where('o.id', $order_id)
|
||||
->where('g.is_commission', 1)
|
||||
->select();
|
||||
if (empty($goods_lists)) {
|
||||
//无商品需要分佣
|
||||
return;
|
||||
}
|
||||
|
||||
//按商品分佣
|
||||
$time = time();
|
||||
foreach ($goods_lists as $goods) {
|
||||
|
||||
//一级分佣
|
||||
if ($goods['first_ratio'] <= 0 || $goods['first_ratio'] >= 100) {
|
||||
//设置为0,不分佣
|
||||
continue;
|
||||
}
|
||||
if (empty($goods['first_leader'])) {
|
||||
//无上级,无需分佣
|
||||
continue;
|
||||
}
|
||||
$money = $goods['total_price'] * $goods['first_ratio'] / 100;
|
||||
if ($money < 0.01) {
|
||||
//金额小于0.01分佣
|
||||
continue;
|
||||
}
|
||||
self::createOrder($goods['first_leader'], $goods['order_goods_id'], $goods['goods_num'], $money, $time);
|
||||
}
|
||||
|
||||
foreach ($goods_lists as $goods) {
|
||||
|
||||
//二级分佣
|
||||
if ($goods['second_ratio'] <= 0 || $goods['second_ratio'] >= 100) {
|
||||
//设置为0,不分佣
|
||||
continue;
|
||||
}
|
||||
$money = $goods['total_price'] * $goods['second_ratio'] / 100;
|
||||
if ($money < 0.01) {
|
||||
//金额小于0.01分佣
|
||||
continue;
|
||||
}
|
||||
if (empty($goods['second_leader'])) {
|
||||
//无上级,无需分佣
|
||||
continue;
|
||||
}
|
||||
self::createOrder($goods['second_leader'], $goods['order_goods_id'], $goods['goods_num'], $money, $time);
|
||||
}
|
||||
|
||||
foreach ($goods_lists as $goods) {
|
||||
|
||||
//三级分佣
|
||||
if ($goods['three_ratio'] <= 0) {
|
||||
//设置为0,不分佣
|
||||
continue;
|
||||
}
|
||||
$money = $goods['total_price'] * $goods['three_ratio'] / 100;
|
||||
if ($money < 0.01) {
|
||||
//金额小于0.01分佣
|
||||
continue;
|
||||
}
|
||||
if (empty($goods['third_leader'])) {
|
||||
//无上级,无需分佣
|
||||
continue;
|
||||
}
|
||||
self::createOrder($goods['third_leader'], $goods['order_goods_id'], $goods['goods_num'], $money, $time);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建分佣订单
|
||||
* @param $leader_id
|
||||
* @param $source_id
|
||||
* @param $goods_num
|
||||
* @param $money
|
||||
* @param $create_time
|
||||
*/
|
||||
private static function createOrder($leader_id, $source_id, $goods_num, $money, $create_time)
|
||||
{
|
||||
$data = [
|
||||
'sn' => createSn('distribution_order_goods','sn'),
|
||||
'user_id' => $leader_id,
|
||||
'order_goods_id' => $source_id,
|
||||
'goods_num' => $goods_num,
|
||||
'money' => $money,
|
||||
'status' => 1,
|
||||
'create_time' => $create_time,
|
||||
];
|
||||
Db::name('distribution_order_goods')
|
||||
->insert($data);
|
||||
}
|
||||
}
|
||||
372
application/common/server/FileServer.php
Normal file
372
application/common/server/FileServer.php
Normal file
@@ -0,0 +1,372 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\server;
|
||||
|
||||
|
||||
use app\common\server\storage\Driver as StorageDriver;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use app\common\model\File;
|
||||
|
||||
class FileServer extends ServerBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 上传图片
|
||||
* @param $cate_id
|
||||
* @param string $save_dir (保存目录, 不建议修改, 不要超二级目录)
|
||||
* @return array
|
||||
* @author 张无忌(2021/2/20 9:53)
|
||||
*/
|
||||
public static function image($cate_id, $save_dir='uploads/images')
|
||||
{
|
||||
try {
|
||||
$config = [
|
||||
'default' => ConfigServer::get('storage', 'default', 'local'),
|
||||
'engine' => ConfigServer::get('storage_engine')
|
||||
];
|
||||
|
||||
if (empty($config['engine']['local'])) {
|
||||
$config['engine']['local'] = [];
|
||||
}
|
||||
|
||||
$StorageDriver = new StorageDriver($config);
|
||||
$StorageDriver->setUploadFile('file');
|
||||
|
||||
if (!$StorageDriver->upload($save_dir)) {
|
||||
throw new Exception('图片上传失败' . $StorageDriver->getError());
|
||||
}
|
||||
|
||||
// 图片上传路径
|
||||
$fileName = $StorageDriver->getFileName();
|
||||
// 图片信息
|
||||
$fileInfo = $StorageDriver->getFileInfo();
|
||||
|
||||
//名字长度太长
|
||||
if (strlen($fileInfo['name']) > 128) {
|
||||
$file_name = substr($fileInfo['name'], 0, 123);
|
||||
$file_end = substr($fileInfo['name'], strlen($fileInfo['name'])-5, strlen($fileInfo['name']));
|
||||
$fileInfo['name'] = $file_name.$file_end;
|
||||
}
|
||||
|
||||
// 记录图片信息
|
||||
$data = [
|
||||
'cate_id' => $cate_id,
|
||||
'name' => $fileInfo['name'],
|
||||
'type' => File::type_image,
|
||||
'uri' => $save_dir . '/' . str_replace("\\","/", $fileName),
|
||||
'create_time' => time(),
|
||||
];
|
||||
Db::name('file')->insert($data);
|
||||
return self::dataSuccess('上传文件成功', $data);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$message = lang($e->getMessage()) ?? $e->getMessage();
|
||||
return self::dataError('上传文件失败:' . $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 用户上传图片
|
||||
* @param $user_id (用户ID)
|
||||
* @param string $save_dir (保存目录, 不建议修改, 不要超二级目录)
|
||||
* @return array
|
||||
* @author 张无忌(2021/2/20 9:53)
|
||||
*/
|
||||
public static function userFormImage($user_id = 0, $save_dir='uploads/user')
|
||||
{
|
||||
try {
|
||||
$config = [
|
||||
'default' => ConfigServer::get('storage', 'default', 'local'),
|
||||
'engine' => ConfigServer::get('storage_engine')
|
||||
];
|
||||
|
||||
if (empty($config['engine']['local'])) {
|
||||
$config['engine']['local'] = [];
|
||||
}
|
||||
|
||||
$StorageDriver = new StorageDriver($config);
|
||||
$StorageDriver->setUploadFile('file');
|
||||
|
||||
if (!$StorageDriver->upload($save_dir)) {
|
||||
throw new Exception('图片上传失败' . $StorageDriver->getError());
|
||||
}
|
||||
|
||||
// 图片上传路径
|
||||
$fileName = $StorageDriver->getFileName();
|
||||
// 图片信息
|
||||
$fileInfo = $StorageDriver->getFileInfo();
|
||||
|
||||
// 记录图片信息
|
||||
$data = [
|
||||
'user_id' => $user_id ? $user_id : 0,
|
||||
'name' => $fileInfo['name'],
|
||||
'type' => File::type_image,
|
||||
'uri' => $save_dir . '/' . str_replace("\\","/", $fileName),
|
||||
'create_time' => time(),
|
||||
];
|
||||
Db::name('user_file')->insert($data);
|
||||
|
||||
$result['url'] = UrlServer::getFileUrl($data['uri']);
|
||||
$result['base_url'] = $data['uri'];
|
||||
$result['name'] = $data['name'];
|
||||
|
||||
return self::dataSuccess('上传文件成功', $result);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$message = lang($e->getMessage()) ?? $e->getMessage();
|
||||
return self::dataError('上传文件失败:' . $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 上传视频
|
||||
* @param string $save_dir (保存目录, 不建议修改, 不要超二级目录)
|
||||
* @return array
|
||||
* @author 张无忌(2021/2/20 9:53)
|
||||
*/
|
||||
public static function video($save_dir='uploads/video')
|
||||
{
|
||||
try {
|
||||
$config = [
|
||||
'default' => ConfigServer::get('storage', 'default', 'local'),
|
||||
'engine' => ConfigServer::get('storage_engine')
|
||||
];
|
||||
|
||||
if (empty($config['engine']['local'])) {
|
||||
$config['engine']['local'] = [];
|
||||
}
|
||||
|
||||
$StorageDriver = new StorageDriver($config);
|
||||
$StorageDriver->setUploadFile('file');
|
||||
|
||||
if (!$StorageDriver->upload($save_dir)) {
|
||||
throw new Exception('图片上传失败' . $StorageDriver->getError());
|
||||
}
|
||||
|
||||
// 图片上传路径
|
||||
$fileName = $StorageDriver->getFileName();
|
||||
// 图片信息
|
||||
$fileInfo = $StorageDriver->getFileInfo();
|
||||
|
||||
// 记录图片信息
|
||||
$data = [
|
||||
'name' => $fileInfo['name'],
|
||||
'type' => File::type_video,
|
||||
'domain' => UrlServer::getFileUrl('/'),
|
||||
'uri' => $save_dir . '/' . str_replace("\\","/", $fileName),
|
||||
'create_time' => time(),
|
||||
];
|
||||
return self::dataSuccess('上传文件成功', $data);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$message = lang($e->getMessage()) ?? $e->getMessage();
|
||||
return self::dataError('上传文件失败:' . $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 用户上传图片
|
||||
* @param string $save_dir (保存目录, 不建议修改, 不要超二级目录)
|
||||
* @param bool $isLocal (是否存不使用oss 只存本地, 上传退款证书会用到)
|
||||
* @return array
|
||||
* @author 张无忌(2021/2/20 9:53)
|
||||
*/
|
||||
public static function other($save_dir='uploads/other', $isLocal=false )
|
||||
{
|
||||
try {
|
||||
if ($isLocal == false) {
|
||||
$config = [
|
||||
'default' => ConfigServer::get('storage', 'default', 'local'),
|
||||
'engine' => ConfigServer::get('storage_engine')
|
||||
];
|
||||
} else {
|
||||
$config = [
|
||||
'default' => 'local',
|
||||
'engine' => ConfigServer::get('storage_engine')
|
||||
];
|
||||
}
|
||||
if (empty($config['engine']['local'])) {
|
||||
$config['engine']['local'] = [];
|
||||
}
|
||||
|
||||
$StorageDriver = new StorageDriver($config);
|
||||
$StorageDriver->setUploadFile('file');
|
||||
|
||||
if (!$StorageDriver->upload($save_dir)) {
|
||||
throw new Exception('上传失败' . $StorageDriver->getError());
|
||||
}
|
||||
|
||||
// 图片上传路径
|
||||
$fileName = $StorageDriver->getFileName();
|
||||
// 图片信息
|
||||
$fileInfo = $StorageDriver->getFileInfo();
|
||||
|
||||
// 信息
|
||||
$data = [
|
||||
'name' => $fileInfo['name'],
|
||||
'type' => File::type_other,
|
||||
'uri' => $save_dir . '/' . str_replace("\\","/", $fileName),
|
||||
'create_time' => time(),
|
||||
];
|
||||
Db::name('file')->insert($data);
|
||||
return self::dataSuccess('上传文件成功', $data);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$message = lang($e->getMessage()) ?? $e->getMessage();
|
||||
return self::dataError('上传文件失败:' . $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 文件列表
|
||||
* @param $pag_no
|
||||
* @param $page_size
|
||||
* @param int $cate_id
|
||||
* @param string $type
|
||||
* @author 张无忌(2021/2/20 10:23)
|
||||
* @return array
|
||||
*/
|
||||
public static function lists($pag_no, $page_size, $cate_id = 0, $type = '')
|
||||
{
|
||||
try {
|
||||
$where['del'] = 0;
|
||||
if ($type) $where['type'] = $type;
|
||||
|
||||
if ($cate_id != 0) {
|
||||
$where['cate_id'] = $cate_id;
|
||||
}
|
||||
|
||||
$count = Db::name('file')
|
||||
->where($where)
|
||||
->count();
|
||||
$lists = Db::name('file')
|
||||
->field(['name', 'uri', 'id'])
|
||||
->where($where)
|
||||
->page($pag_no, $page_size)
|
||||
->order(['id' => 'desc'])
|
||||
->select();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['uri'] = UrlServer::getFileUrl($item['uri']);
|
||||
}
|
||||
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 删除选中的图片
|
||||
* @param $ids
|
||||
* @author 张无忌(2021/2/20 10:24)
|
||||
* @return bool|int|string
|
||||
*/
|
||||
public static function del($ids)
|
||||
{
|
||||
try {
|
||||
return Db::name('file')
|
||||
->where('id', 'in', $ids)
|
||||
->update(['del' => 1]);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function videokkk($save_dir = '',$ext = 'mp3,mp4,wav,AVI,mov,rmvb,rm,FLV,3GP'){
|
||||
try {
|
||||
if (!file_exists($save_dir)) {
|
||||
mkdir($save_dir, 0775, true);
|
||||
}
|
||||
|
||||
$file = request()->file('file');
|
||||
$info = $file->validate(['ext' => $ext])->move($save_dir);
|
||||
|
||||
if(empty($info)){
|
||||
throw new Exception($file->getError());
|
||||
}
|
||||
|
||||
$result['url'] = $save_dir . '/' . $info->getSaveName();
|
||||
$result['name'] = $info->getSaveName();
|
||||
$result['save_name'] = $info->getFilename();
|
||||
$file_data = $info->getInfo();
|
||||
if (isset($file_data['name'])){
|
||||
$result['name'] = $file_data['name'];
|
||||
}
|
||||
return self::dataSuccess('上传文件成功', $result);
|
||||
|
||||
} catch (Exception $e) {
|
||||
$messge = $e->getMessage();
|
||||
$messge = lang($messge) ?? $messge;
|
||||
return self::dataError('上传文件失败:' . $messge);
|
||||
}
|
||||
}
|
||||
|
||||
public static function videoNew($cate_id, $save_dir='uploads/video')
|
||||
{
|
||||
try {
|
||||
$config = [
|
||||
'default' => ConfigServer::get('storage', 'default', 'local'),
|
||||
'engine' => ConfigServer::get('storage_engine')
|
||||
];
|
||||
|
||||
if (empty($config['engine']['local'])) {
|
||||
$config['engine']['local'] = [];
|
||||
}
|
||||
|
||||
$StorageDriver = new StorageDriver($config);
|
||||
$StorageDriver->setUploadFile('file');
|
||||
|
||||
if (!$StorageDriver->upload($save_dir)) {
|
||||
throw new Exception('视频上传失败' . $StorageDriver->getError());
|
||||
}
|
||||
|
||||
// 视频上传路径
|
||||
$fileName = $StorageDriver->getFileName();
|
||||
// 视频信息
|
||||
$fileInfo = $StorageDriver->getFileInfo();
|
||||
|
||||
//名字长度太长
|
||||
if (strlen($fileInfo['name']) > 128) {
|
||||
$file_name = substr($fileInfo['name'], 0, 123);
|
||||
$file_end = substr($fileInfo['name'], strlen($fileInfo['name'])-5, strlen($fileInfo['name']));
|
||||
$fileInfo['name'] = $file_name.$file_end;
|
||||
}
|
||||
|
||||
// 记录视频信息
|
||||
$data = [
|
||||
'cate_id' => $cate_id,
|
||||
'name' => $fileInfo['name'],
|
||||
'type' => File::type_video,
|
||||
'uri' => $save_dir . '/' . str_replace("\\","/", $fileName),
|
||||
'create_time' => time(),
|
||||
];
|
||||
Db::name('file')->insert($data);
|
||||
return self::dataSuccess('上传视频成功', $data);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$message = lang($e->getMessage()) ?? $e->getMessage();
|
||||
return self::dataError('上传视频失败:' . $message);
|
||||
}
|
||||
}
|
||||
}
|
||||
39
application/common/server/ServerBase.php
Normal file
39
application/common/server/ServerBase.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\server;
|
||||
|
||||
|
||||
class ServerBase
|
||||
{
|
||||
|
||||
|
||||
public static function dataSuccess($msg = '', $data = [], $code = 1, $show = 1)
|
||||
{
|
||||
return data_success($msg, $data, $code, $show);
|
||||
}
|
||||
|
||||
|
||||
public static function dataError($msg = '', $data = [], $code = 0, $show = 1)
|
||||
{
|
||||
return data_error($msg, $data, $code, $show);
|
||||
}
|
||||
|
||||
}
|
||||
100
application/common/server/TencentSms.php
Normal file
100
application/common/server/TencentSms.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\server;
|
||||
|
||||
|
||||
use TencentCloud\Common\Credential;
|
||||
use TencentCloud\Common\Exception\TencentCloudSDKException;
|
||||
use TencentCloud\Common\Profile\ClientProfile;
|
||||
use TencentCloud\Common\Profile\HttpProfile;
|
||||
use TencentCloud\Sms\V20190711\Models\SendSmsRequest;
|
||||
use TencentCloud\Sms\V20190711\SmsClient;
|
||||
|
||||
class TencentSms
|
||||
{
|
||||
private $app_key = ''; //AppKey
|
||||
private $secret_key = ''; //SecretKey
|
||||
private $appid = ''; //Appid
|
||||
private $sign = ''; //签名
|
||||
private $mobile = ''; //手机号
|
||||
private $template_code = ''; //模板编码
|
||||
private $template_param = ''; //模板参数
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
* TencentSms constructor.
|
||||
* @param $config
|
||||
*/
|
||||
public function __construct($config)
|
||||
{
|
||||
$this->sign = $config['sign'];
|
||||
$this->appid = $config['app_id'];
|
||||
$this->app_key = $config['app_key'];
|
||||
$this->secret_key = $config['secret_key'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 设置模板编码
|
||||
* @Author: 张无忌
|
||||
* @param $template_code
|
||||
* @return $this
|
||||
*/
|
||||
public function setTemplateCode($template_code){
|
||||
$this->template_code = $template_code;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 设置手机号
|
||||
* @Author: 张无忌
|
||||
* @param $mobile
|
||||
* @return $this
|
||||
*/
|
||||
public function setMobile($mobile){
|
||||
$this->mobile = $mobile;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 设置模板参数
|
||||
* @Author: 张无忌
|
||||
* @param string $template_param
|
||||
* @return $this
|
||||
*/
|
||||
public function setTemplateParam($template_param = ''){
|
||||
$this->template_param = $template_param;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 发送短信
|
||||
* @Author: 张无忌
|
||||
*/
|
||||
public function sendSms()
|
||||
{
|
||||
$cred = new Credential($this->app_key, $this->secret_key);
|
||||
$httpProfile = new HttpProfile();
|
||||
$httpProfile->setEndpoint('sms.tencentcloudapi.com');
|
||||
|
||||
$clientProfile = new ClientProfile();
|
||||
$clientProfile->setHttpProfile($httpProfile);
|
||||
|
||||
$client = new SmsClient($cred, "", $clientProfile);
|
||||
$req = new SendSmsRequest();
|
||||
|
||||
$params = [
|
||||
'Sign' => $this->sign,
|
||||
'SmsSdkAppid' => $this->appid,
|
||||
'TemplateID' => $this->template_code,
|
||||
'PhoneNumberSet' => ['+86'.$this->mobile],
|
||||
'TemplateParamSet' => $this->template_param,
|
||||
];
|
||||
|
||||
$req->fromJsonString(json_encode($params));
|
||||
$resp = $client->SendSms($req);
|
||||
|
||||
// return $resp->toJsonString();
|
||||
return json_decode($resp->toJsonString(), true);
|
||||
}
|
||||
}
|
||||
86
application/common/server/UrlServer.php
Normal file
86
application/common/server/UrlServer.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\server;
|
||||
|
||||
|
||||
class UrlServer
|
||||
{
|
||||
/**
|
||||
* User: 意象信息科技 lr
|
||||
* Desc: 获取文件全路径
|
||||
* @param string $uri
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
public static function getFileUrl($uri = '', $type = '')
|
||||
{
|
||||
if (empty($uri)) {
|
||||
return '';
|
||||
}
|
||||
if (strstr($uri,'http://') || strstr($uri,'https://')) {
|
||||
return $uri;
|
||||
}
|
||||
|
||||
if ($uri && $uri !== '/' && substr($uri, 0, 1) !== '/') {
|
||||
$uri = '/' . $uri;
|
||||
}
|
||||
// 获取存储引擎信息
|
||||
$engine = ConfigServer::get('storage', 'default', 'local');
|
||||
if ($engine === 'local') {
|
||||
//图片分享处理
|
||||
if ($type && $type == 'share') {
|
||||
return ROOT_PATH . $uri;
|
||||
}
|
||||
|
||||
if (isset($uri[0])) {
|
||||
$uri[0] != '/' && $uri = '/'.$uri;
|
||||
}
|
||||
|
||||
$protocol = is_https() ? 'https://' : 'http://';
|
||||
$file_url = config('project.file_domain');
|
||||
return $protocol . $file_url .$uri;
|
||||
|
||||
} else {
|
||||
$config = ConfigServer::get('storage_engine', $engine);
|
||||
$domain = trim(isset($config['domain']) ? $config['domain']:'http://');
|
||||
return $domain . $uri;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE: 设置文件路径转相对路径
|
||||
* @author: 张无忌
|
||||
* @param string $uri
|
||||
* @return mixed
|
||||
*/
|
||||
public static function setFileUrl($uri='')
|
||||
{
|
||||
$engine = ConfigServer::get('storage', 'default', 'local');
|
||||
if ($engine === 'local') {
|
||||
$domain = request()->domain();
|
||||
return str_replace($domain.'/', '', $uri);
|
||||
} else {
|
||||
$config = ConfigServer::get('storage_engine', $engine);
|
||||
return str_replace($config['domain'], '', $uri);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
338
application/common/server/WeChatPayServer.php
Normal file
338
application/common/server/WeChatPayServer.php
Normal file
@@ -0,0 +1,338 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\server;
|
||||
|
||||
|
||||
use app\common\logic\PaymentLogic;
|
||||
use app\common\logic\PayNotifyLogic;
|
||||
use app\common\model\Client_;
|
||||
use app\common\model\Pay;
|
||||
use EasyWeChat\Factory;
|
||||
use EasyWeChat\Payment\Application;
|
||||
use Endroid\QrCode\QrCode;
|
||||
use http\Client;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
|
||||
class WeChatPayServer
|
||||
{
|
||||
|
||||
protected static $error = '未知错误';
|
||||
protected static $return_code = 0;
|
||||
|
||||
/**
|
||||
* Notes: 错误信息
|
||||
* @return string
|
||||
* @author 段誉(2021/2/1 11:19)
|
||||
*/
|
||||
public static function getError()
|
||||
{
|
||||
return self::$error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 返回状态码
|
||||
* @return int
|
||||
* @author 段誉(2021/2/1 11:19)
|
||||
*/
|
||||
public static function getReturnCode()
|
||||
{
|
||||
return self::$return_code;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 微信统一下单
|
||||
* @param $from
|
||||
* @param $order
|
||||
* @param $order_source
|
||||
* @return array|bool|string
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
* @author 段誉(2021/2/1 11:19)
|
||||
*/
|
||||
public static function unifiedOrder($from, $order, $order_source)
|
||||
{
|
||||
try {
|
||||
$wechat_config = self::getWeChatConfig($order, $order_source);
|
||||
$auth = $wechat_config['auth'];
|
||||
$config = $wechat_config['config'];
|
||||
$notify_url = $wechat_config['notify_url'];
|
||||
|
||||
//jsapi需要验证openID
|
||||
$check_source = [Client_::mnp, Client_::oa];
|
||||
if (!$auth && in_array($order_source, $check_source)) {
|
||||
throw new Exception('授权信息失效');
|
||||
}
|
||||
|
||||
$app = Factory::payment($config);
|
||||
$attributes = self::getAttributes($from, $order, $order_source, $auth, $notify_url);
|
||||
$result = $app->order->unify($attributes);
|
||||
|
||||
if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
|
||||
|
||||
//小程序,公众号
|
||||
if (in_array($order_source, [Client_::mnp, Client_::oa])) {
|
||||
$data = $app->jssdk->bridgeConfig($result['prepay_id'], false);
|
||||
}
|
||||
|
||||
//app客户端
|
||||
if (in_array($order_source, [Client_::ios, Client_::android])) {
|
||||
$data = $app->jssdk->appConfig($result['prepay_id'], false);
|
||||
}
|
||||
|
||||
//pc端
|
||||
if ($order_source == Client_::pc) {
|
||||
$data = self::getNativeCode($result, $order);
|
||||
}
|
||||
|
||||
//h5(非微信环境)
|
||||
if ($order_source == Client_::h5) {
|
||||
$redirect_url = request()->domain().'/mobile/pages/user_order/user_order';
|
||||
$redirect_url = urlencode($redirect_url);
|
||||
$data = $result['mweb_url'].'&redirect_url='.$redirect_url;
|
||||
}
|
||||
|
||||
return $data;
|
||||
} else {
|
||||
if (isset($result['return_code']) && $result['return_code'] == 'FAIL') {
|
||||
throw new Exception($result['return_msg']);
|
||||
}
|
||||
if (isset($result['err_code_des'])) {
|
||||
throw new Exception($result['err_code_des']);
|
||||
}
|
||||
throw new Exception('未知原因');
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
self::$error = '支付失败:' . $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: NATIVE 支付二维码
|
||||
* @param $result
|
||||
* @param $order
|
||||
* @author 段誉(2021/3/17 14:41)
|
||||
* @return string
|
||||
* @throws \Endroid\QrCode\Exception\InvalidWriterException
|
||||
*/
|
||||
public static function getNativeCode($result, $order)
|
||||
{
|
||||
$save_dir = 'uploads/pay_code/';
|
||||
$qr_src = md5($order['order_sn'].mt_rand(10000, 99999)) . '.png';
|
||||
$code_url = ROOT_PATH.'/'.$save_dir . $qr_src;
|
||||
|
||||
$qrCode = new QrCode();
|
||||
$qrCode->setText($result['code_url']);
|
||||
$qrCode->setSize(200);
|
||||
$qrCode->setWriterByName('png');
|
||||
!file_exists($save_dir) && mkdir($save_dir, 777, true);
|
||||
$qrCode->writeFile($code_url);
|
||||
|
||||
//生成base64临时图片
|
||||
if ($fp = fopen($code_url, "rb", 0)) {
|
||||
$gambar = fread($fp, filesize($code_url));
|
||||
fclose($fp);
|
||||
$base64 = chunk_split(base64_encode($gambar));
|
||||
$base64 = 'data:image/png;base64,' . $base64;
|
||||
}
|
||||
//删除文件
|
||||
if (strstr($code_url, $save_dir)) {
|
||||
unlink($code_url);
|
||||
}
|
||||
return $base64;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 支付参数
|
||||
* @param $from
|
||||
* @param $order
|
||||
* @param $order_source
|
||||
* @param $auth
|
||||
* @param $notify_url
|
||||
* @author 段誉(2021/2/24 10:15)
|
||||
* @return array
|
||||
*/
|
||||
public static function getAttributes($from, $order, $order_source, $auth, $notify_url)
|
||||
{
|
||||
switch ($from) {
|
||||
case 'order':
|
||||
$attributes = [
|
||||
'trade_type' => 'JSAPI',
|
||||
'body' => '商品',
|
||||
// 'out_trade_no' => $order['order_sn'],
|
||||
'total_fee' => $order['order_amount'] * 100, // 单位:分
|
||||
'notify_url' => $notify_url,
|
||||
'openid' => $auth['openid'],
|
||||
'attach' => 'order'
|
||||
];
|
||||
break;
|
||||
case 'recharge':
|
||||
$attributes = [
|
||||
'trade_type' => 'JSAPI',
|
||||
'body' => '充值',
|
||||
// 'out_trade_no' => $order['order_sn'],
|
||||
'total_fee' => $order['order_amount'] * 100, // 单位:分
|
||||
'notify_url' => $notify_url,
|
||||
'openid' => $auth['openid'],
|
||||
'attach' => 'recharge'
|
||||
];
|
||||
break;
|
||||
}
|
||||
|
||||
//app支付类型
|
||||
if ($order_source == Client_::android || $order_source == Client_::ios) {
|
||||
$attributes['trade_type'] = 'APP';
|
||||
}
|
||||
|
||||
//NATIVE模式设置
|
||||
if ($order_source == Client_::pc) {
|
||||
$attributes['trade_type'] = 'NATIVE';
|
||||
$attributes['product_id'] = $order['order_sn'];
|
||||
}
|
||||
|
||||
//h5支付类型
|
||||
if ($order_source == Client_::h5) {
|
||||
$attributes['trade_type'] = 'MWEB';
|
||||
}
|
||||
|
||||
//在白名单内,一分钱
|
||||
if (PaymentLogic::isPayWhiteList($order['user_id'])) {
|
||||
$attributes['total_fee'] = 1;
|
||||
}
|
||||
|
||||
//修改微信统一下单,订单编号 -> 支付回调时截取前面的单号 18个
|
||||
//修改原因:回调时使用了不同的回调地址,导致跨客户端支付时(例如小程序,公众号)可能出现201,商户订单号重复错误
|
||||
$attributes['out_trade_no'] = $order['order_sn'].$attributes['trade_type'].$order_source;
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 获取微信配置
|
||||
* @param $order
|
||||
* @param $order_source
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @author 段誉(2021/2/1 11:20)
|
||||
*/
|
||||
public static function getWeChatConfig($order, $order_source)
|
||||
{
|
||||
$pay_config = WeChatServer::getPayConfigBySource($order_source);
|
||||
|
||||
$where[] = ['user_id', '=', $order['user_id']];
|
||||
$where[] = ['client', '=', $order_source];
|
||||
$auth = Db::name('user_auth')->where($where)->find();
|
||||
|
||||
$data = [
|
||||
'auth' => $auth,
|
||||
'config' => $pay_config['config'],
|
||||
'notify_url' => $pay_config['notify_url'],
|
||||
'order_source' => $order_source,
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 支付回调
|
||||
* @param $config
|
||||
* @author 段誉(2021/2/24 10:02)
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\Exception
|
||||
*/
|
||||
public static function notify($config)
|
||||
{
|
||||
$app = new Application($config);
|
||||
$response = $app->handlePaidNotify(function ($message, $fail) {
|
||||
|
||||
if ($message['return_code'] !== 'SUCCESS') {
|
||||
return $fail('通信失败');
|
||||
}
|
||||
|
||||
// 用户是否支付成功
|
||||
if ($message['result_code'] === 'SUCCESS') {
|
||||
$extra['transaction_id'] = $message['transaction_id'];
|
||||
$attach = $message['attach'];
|
||||
$message['out_trade_no'] = mb_substr($message['out_trade_no'], 0, 18);
|
||||
switch ($attach) {
|
||||
case 'order':
|
||||
$order = Db::name('order')->where(['order_sn' => $message['out_trade_no']])->find();
|
||||
if (!$order || $order['pay_status'] >= Pay::ISPAID) {
|
||||
return true;
|
||||
}
|
||||
PayNotifyLogic::handle('order', $message['out_trade_no'], $extra);
|
||||
break;
|
||||
|
||||
case 'recharge':
|
||||
$order = Db::name('recharge_order')->where(['order_sn' => $message['out_trade_no']])->find();
|
||||
if (!$order || $order['pay_status'] >= Pay::ISPAID) {
|
||||
return true;
|
||||
}
|
||||
PayNotifyLogic::handle('recharge', $message['out_trade_no'], $extra);
|
||||
break;
|
||||
}
|
||||
} elseif ($message['result_code'] === 'FAIL') {
|
||||
// 用户支付失败
|
||||
|
||||
}
|
||||
|
||||
return true; // 返回处理完成
|
||||
|
||||
});
|
||||
$response->send();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 退款
|
||||
* @param $config
|
||||
* @param $data //微信订单号、商户退款单号、订单金额、退款金额、其他参数
|
||||
* @return array|bool|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
|
||||
* @author 段誉(2021/2/1 11:19)
|
||||
*/
|
||||
public static function refund($config, $data)
|
||||
{
|
||||
if (!empty($data["transaction_id"])) {
|
||||
$app = Factory::payment($config);
|
||||
$result = $app->refund->byTransactionId(
|
||||
$data['transaction_id'],
|
||||
$data['refund_sn'],
|
||||
$data['total_fee'],
|
||||
$data['refund_fee']
|
||||
);
|
||||
return $result;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
189
application/common/server/WeChatServer.php
Normal file
189
application/common/server/WeChatServer.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\server;
|
||||
|
||||
|
||||
|
||||
|
||||
use app\common\model\Client_;
|
||||
use app\common\model\Pay;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
|
||||
class WeChatServer
|
||||
{
|
||||
/**
|
||||
* 获取小程序配置
|
||||
* @return array
|
||||
*/
|
||||
public static function getMnpConfig()
|
||||
{
|
||||
$config = [
|
||||
'app_id' => ConfigServer::get('mnp', 'app_id'),
|
||||
'secret' => ConfigServer::get('mnp', 'secret' ),
|
||||
'mch_id' => ConfigServer::get('mnp', 'mch_id'),
|
||||
'key' => ConfigServer::get('mnp', 'key'),
|
||||
'response_type' => 'array',
|
||||
'log' => [
|
||||
'level' => 'debug',
|
||||
'file' => '../runtime/log/wechat.log'
|
||||
],
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信公众号配置
|
||||
* @return array
|
||||
*/
|
||||
public static function getOaConfig()
|
||||
{
|
||||
$config = [
|
||||
'app_id' => ConfigServer::get('oa', 'app_id'),
|
||||
'secret' => ConfigServer::get('oa', 'secret'),
|
||||
'mch_id' => ConfigServer::get('oa', 'mch_id'),
|
||||
'key' => ConfigServer::get('oa', 'key'),
|
||||
'token' => ConfigServer::get('oa', 'token',''),
|
||||
'response_type' => 'array',
|
||||
'log' => [
|
||||
'level' => 'debug',
|
||||
'file' => '../runtime/log/wechat.log'
|
||||
],
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信开放平台应用配置
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpConfig()
|
||||
{
|
||||
$config = [
|
||||
'app_id' => ConfigServer::get('op', 'app_id'),
|
||||
'secret' => ConfigServer::get('op', 'secret'),
|
||||
'response_type' => 'array',
|
||||
'log' => [
|
||||
'level' => 'debug',
|
||||
'file' => '../runtime/log/wechat.log'
|
||||
],
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据不同来源获取支付配置
|
||||
*/
|
||||
public static function getPayConfigBySource($order_source)
|
||||
{
|
||||
$notify_url = '';
|
||||
switch ($order_source) {
|
||||
case Client_::mnp:
|
||||
$notify_url = url('payment/notifyMnp', '', '', true);
|
||||
break;
|
||||
case Client_::oa:
|
||||
case Client_::pc:
|
||||
case Client_::h5:
|
||||
$notify_url = url('payment/notifyOa', '', '', true);
|
||||
break;
|
||||
case Client_::android:
|
||||
case Client_::ios:
|
||||
$notify_url = url('payment/notifyApp', '', '', true);
|
||||
break;
|
||||
}
|
||||
|
||||
$config = self::getPayConfig($order_source);
|
||||
|
||||
if (empty($config) ||
|
||||
empty($config['key']) ||
|
||||
empty($config['mch_id']) ||
|
||||
empty($config['app_id']) ||
|
||||
empty($config['secret'])
|
||||
) {
|
||||
throw new Exception('请在后台配置好微信支付');
|
||||
}
|
||||
|
||||
return [
|
||||
'config' => $config,
|
||||
'notify_url' => $notify_url,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//===================================支付配置=======================================================
|
||||
|
||||
//微信支付设置 H5支付 appid 可以是公众号appid
|
||||
public static function getPayConfig($client)
|
||||
{
|
||||
switch ($client) {
|
||||
case Client_::mnp:
|
||||
$appid = ConfigServer::get('mnp', 'app_id');
|
||||
$secret = ConfigServer::get('mnp', 'secret');
|
||||
break;
|
||||
case Client_::oa:
|
||||
case Client_::pc:
|
||||
case Client_::h5:
|
||||
$appid = ConfigServer::get('oa', 'app_id');
|
||||
$secret = ConfigServer::get('oa', 'secret');
|
||||
break;
|
||||
case Client_::android:
|
||||
case Client_::ios:
|
||||
$appid = ConfigServer::get('op', 'app_id');
|
||||
$secret = ConfigServer::get('op', 'secret');
|
||||
break;
|
||||
default:
|
||||
$appid = '';
|
||||
$secret = '';
|
||||
}
|
||||
|
||||
$pay = Pay::where(['code' => 'wechat'])->find()->toArray();
|
||||
|
||||
$config = [
|
||||
'app_id' => $appid,
|
||||
'secret' => $secret,
|
||||
'mch_id' => $pay['config']['mch_id'] ?? '',
|
||||
'key' => $pay['config']['pay_sign_key'] ?? '',
|
||||
'cert_path' => $pay['config']['apiclient_cert'] ?? '',
|
||||
'key_path' => $pay['config']['apiclient_key'] ?? '',
|
||||
'response_type' => 'array',
|
||||
'log' => [
|
||||
'level' => 'debug',
|
||||
'file' => '../runtime/log/wechat.log'
|
||||
],
|
||||
];
|
||||
|
||||
if (is_cli()) {
|
||||
$config['cert_path'] = ROOT_PATH.'/public/'.$pay['config']['apiclient_cert'];
|
||||
$config['key_path'] = ROOT_PATH.'/public/'.$pay['config']['apiclient_key'];
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
}
|
||||
146
application/common/server/WxMessageServer.php
Normal file
146
application/common/server/WxMessageServer.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\server;
|
||||
|
||||
|
||||
use app\common\logic\NoticeLogic;
|
||||
use app\common\model\Client_;
|
||||
use app\common\model\NoticeSetting;
|
||||
use EasyWeChat\Factory;
|
||||
use think\Db;
|
||||
|
||||
class WxMessageServer
|
||||
{
|
||||
protected $config = null; // 配置信息
|
||||
protected $app = null; // easyechat实例
|
||||
protected $openid = null; // openid
|
||||
protected $template_id = null; // 消息模板ID
|
||||
protected $platform = null; //平台[公众号, 小程序]
|
||||
protected $notice_id = null; //通知记录id
|
||||
|
||||
// 初始化
|
||||
public function __construct($user_id, $platform)
|
||||
{
|
||||
// 获取用户信息
|
||||
$this->platform = $platform;
|
||||
$where = ['user_id' => (int)$user_id, 'client' => $platform];
|
||||
$user_model = Db::name('user_auth')->where($where)->find();
|
||||
$this->openid = $user_model['openid'];
|
||||
|
||||
if ($this->platform === Client_::oa) {
|
||||
$this->config = WeChatServer::getOaConfig();
|
||||
$this->app = Factory::officialAccount($this->config);
|
||||
} else if ($this->platform === Client_::mnp) {
|
||||
$this->config = WeChatServer::getMnpConfig();
|
||||
$this->app = Factory::miniProgram($this->config);
|
||||
}
|
||||
}
|
||||
|
||||
// 发送消息
|
||||
public function send($params)
|
||||
{
|
||||
if (empty($this->openid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取template_id
|
||||
$scene = NoticeSetting::where(['scene' => $params['scene']])->find()->toArray();
|
||||
if ($this->platform == Client_::oa) {
|
||||
$scene_model = $scene['oa_notice'];
|
||||
$send_type = NoticeSetting::OA_NOTICE;
|
||||
} else {
|
||||
$scene_model = $scene['mnp_notice'];
|
||||
$send_type = NoticeSetting::MNP_NOTICE;
|
||||
}
|
||||
|
||||
if (!$scene_model || $scene_model['status'] == 0 || $scene_model['template_id'] == '') {
|
||||
return false;
|
||||
} else {
|
||||
$this->template_id = $scene_model['template_id'];
|
||||
}
|
||||
|
||||
if ($this->platform == Client_::oa) {
|
||||
$template = $this->oaTemplate($params, $scene_model);
|
||||
} else {
|
||||
$template = $this->mnpTemplate($params, $scene_model);
|
||||
}
|
||||
|
||||
$this->notice_id = NoticeLogic::addNoticeLog($params, $scene_model, $send_type, json_encode($template, true));
|
||||
|
||||
// 发送消息
|
||||
try {
|
||||
|
||||
if ($this->platform === Client_::oa) {
|
||||
$res = $this->app->template_message->send($template);
|
||||
} else if ($this->platform === Client_::mnp) {
|
||||
$res = $this->app->subscribe_message->send($template);
|
||||
}
|
||||
NoticeLogic::updateNotice($this->notice_id, json_encode($res, true));
|
||||
return true;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
NoticeLogic::updateNotice($this->notice_id, $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 公众号消息模板
|
||||
public function oaTemplate($params, $scene_model)
|
||||
{
|
||||
$domain = request()->domain();
|
||||
$tpl = [
|
||||
'touser' => $this->openid,
|
||||
'template_id' => $this->template_id,
|
||||
'url' => $domain.$params['url'],
|
||||
'data' => [
|
||||
'first' => $scene_model['first'],
|
||||
'remark' => $scene_model['remark']
|
||||
]
|
||||
];
|
||||
return $this->tplformat($scene_model, $params, $tpl);
|
||||
}
|
||||
|
||||
// 小程序消息模板
|
||||
public function mnpTemplate($params, $scene_model)
|
||||
{
|
||||
$tpl = [
|
||||
'touser' => $this->openid,
|
||||
'template_id' => $this->template_id,
|
||||
'page' => $params['page']
|
||||
];
|
||||
return $this->tplformat($scene_model, $params, $tpl);
|
||||
}
|
||||
|
||||
|
||||
// 调换变量
|
||||
public function tplformat($scene_model, $params, $tpl)
|
||||
{
|
||||
foreach ($scene_model['tpl'] as $item) {
|
||||
foreach ($params as $k => $v) {
|
||||
$search_replace = '{'.$k.'}';
|
||||
$item['tpl_content'] = str_replace($search_replace, $v, $item['tpl_content']);
|
||||
}
|
||||
$tpl['data'][$item['tpl_keyword']] = $item['tpl_content'];
|
||||
}
|
||||
return $tpl;
|
||||
}
|
||||
|
||||
}
|
||||
196
application/common/server/YlyPrinter.php
Normal file
196
application/common/server/YlyPrinter.php
Normal file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\server;
|
||||
use App\Api\PrinterService;
|
||||
use App\Api\PrintService;
|
||||
use App\Oauth\YlyOauthClient;
|
||||
use App\Config\YlyConfig;
|
||||
use Exception;
|
||||
use think\facade\Cache;
|
||||
|
||||
class YlyPrinter{
|
||||
private $client_id = '';
|
||||
private $client_secret = '';
|
||||
private $yly_config = '';
|
||||
protected $access_token = '';
|
||||
|
||||
|
||||
public function __construct($client_id = '',$client_secret = ''){
|
||||
|
||||
$this->client_id = $client_id; //应用id
|
||||
$this->client_secret = $client_secret; // 应用密钥
|
||||
|
||||
$this->yly_config = new YlyConfig($this->client_id, $this->client_secret);
|
||||
|
||||
$this->access_token = Cache::get('yly_access_token');
|
||||
//没有access_token时获取
|
||||
if(empty($this->access_token)){
|
||||
$this->getToken();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:获取access_token
|
||||
* @return mixed
|
||||
*/
|
||||
public function getToken(){
|
||||
$client = new YlyOauthClient($this->yly_config);
|
||||
$token = $client->getToken();
|
||||
|
||||
|
||||
$this->access_token = $token->access_token;
|
||||
Cache::tag('yly_printer')->set('yly_access_token',$this->access_token);
|
||||
//刷新token、有效期35天(自用型刷新token作用不大)
|
||||
Cache::tag('yly_printer')->set('yly_refresh_token',$token->refresh_token,35*24*3600);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:刷新access_token
|
||||
* @return mixed
|
||||
*/
|
||||
public function refreshToken(){
|
||||
|
||||
$client = new YlyOauthClient($this->yly_config);
|
||||
$token = $client->refreshToken(Cache::get('yly_refresh_token'));
|
||||
|
||||
$this->access_token = $token->access_token;
|
||||
//重置token
|
||||
Cache::tag('yly_printer')->set('yly_access_token',$this->access_token);
|
||||
Cache::tag('yly_printer')->set('yly_refresh_token',$token->refresh_token,35*24*3600);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 添加打印机
|
||||
* @param string $machine_code 终端号
|
||||
* @param string $msign 秘钥
|
||||
* @param string $print_name 打印机名称
|
||||
* @return bool|string
|
||||
*/
|
||||
public function addPrinter($machine_code,$msign,$print_name){
|
||||
|
||||
|
||||
$print = new PrinterService($this->access_token,$this->yly_config);
|
||||
$response = $print->addPrinter($machine_code,$msign,$print_name);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:删除打印机
|
||||
* @param sting $machine_code 终端号
|
||||
* @return bool|string
|
||||
*/
|
||||
public function deletePrinter($machine_code){
|
||||
|
||||
$print = new PrinterService($this->access_token,$this->yly_config);
|
||||
$print->deletePrinter($machine_code);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 设置logo
|
||||
* @param sting $machine_code 终端号
|
||||
* @param sting $url logo
|
||||
*/
|
||||
public function setIcon($machine_code,$url){
|
||||
$print = new PrinterService($this->access_token,$this->yly_config);
|
||||
$print->setIcon($machine_code,$url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:获取终端状态
|
||||
* @param sting $machine_code 终端号
|
||||
*/
|
||||
public function getPrintStatus($machine_code){
|
||||
$print = new PrinterService($this->access_token,$this->yly_config);
|
||||
$response = $print->getPrintStatus($machine_code);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:打印机接口
|
||||
* @param array $machine_list 打印机信息
|
||||
* @param $order 订单信息
|
||||
* @return bool|string
|
||||
*/
|
||||
public function ylyPrint($printer_list = [] , $order,$template_config){
|
||||
|
||||
|
||||
$print = new PrintService($this->access_token, $this->yly_config);
|
||||
|
||||
|
||||
$order['title'] = $template_config['title'] ?? '';
|
||||
$order['qr_code'] = $template_config['qr_code_link'] ?? '';
|
||||
$order['remark'] = $template_config['remark'] ?? '';
|
||||
|
||||
foreach ($printer_list as $printer){
|
||||
|
||||
if($printer['machine_code']){
|
||||
$content = "<MN>".$printer['print_number']."</MN>";
|
||||
if($order['title']){
|
||||
$content .= "<FS2><center>".$order['title']."</center></FS2>";
|
||||
}
|
||||
$content .= PHP_EOL;
|
||||
$content .= "下单时间:".date("Y-m-d H:i").PHP_EOL;
|
||||
$content .= "订单编号:".$order['order_sn'].PHP_EOL;
|
||||
$content .= PHP_EOL;
|
||||
$content .= "<FS2>收货信息</FS2>".PHP_EOL;
|
||||
$content .= PHP_EOL;
|
||||
$content .= "联系人:".$order['consignee'].PHP_EOL;
|
||||
$content .= "手机号码:".$order['mobile'].PHP_EOL;
|
||||
$content .= "收货地址:".$order['delivery_address'].PHP_EOL;
|
||||
$content .= PHP_EOL;
|
||||
$content .= "<FS2>商品信息</FS2>".PHP_EOL;
|
||||
$content .= str_repeat('-', 32).PHP_EOL;
|
||||
|
||||
foreach ($order['order_goods'] as $goods){
|
||||
$content .= $goods['name'].PHP_EOL;
|
||||
$content .= $goods['spec_value_str']." "."x".$goods['goods_num']." ".$goods['goods_price'].PHP_EOL;
|
||||
$content .= PHP_EOL;
|
||||
}
|
||||
|
||||
$content .= str_repeat('-', 32).PHP_EOL;
|
||||
|
||||
$content .= "商品金额:¥".$order['total_amount'].PHP_EOL;
|
||||
$content .= "优惠:¥".$order['discount_amount'].PHP_EOL;
|
||||
$content .= "运费:¥".$order['shipping_price'].PHP_EOL;
|
||||
$content .= "合计:¥".$order['total_amount'].PHP_EOL;
|
||||
$content .= PHP_EOL;
|
||||
if($order['user_remark']){
|
||||
$content .= '订单备注:'.$order['user_remark'].PHP_EOL;
|
||||
}
|
||||
|
||||
$content .= PHP_EOL;
|
||||
//二维码
|
||||
if($order['qr_code']){
|
||||
$content .= "<QR>".$order['qr_code']."</QR>".PHP_EOL;
|
||||
}
|
||||
if($order['remark']){
|
||||
$content .= "<center>".$order['remark']."</center>".PHP_EOL;
|
||||
}
|
||||
|
||||
$print->index($printer['machine_code'], $content, $order['order_sn']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
125
application/common/server/storage/Driver.php
Normal file
125
application/common/server/storage/Driver.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\server\storage;
|
||||
|
||||
use think\Exception;
|
||||
|
||||
/**
|
||||
* 存储模块驱动
|
||||
* Class driver
|
||||
* @package app\common\library\storage
|
||||
*/
|
||||
class Driver
|
||||
{
|
||||
private $config; // upload 配置
|
||||
private $engine; // 当前存储引擎类
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* Driver constructor.
|
||||
* @param $config
|
||||
* @param null|string $storage 指定存储方式,如不指定则为系统默认
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct($config, $storage = null)
|
||||
{
|
||||
$this->config = $config;
|
||||
// 实例化当前存储引擎
|
||||
$this->engine = $this->getEngineClass($storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置上传的文件信息
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function setUploadFile($name = 'iFile')
|
||||
{
|
||||
return $this->engine->setUploadFile($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置上传的文件信息
|
||||
* @param string $filePath
|
||||
* @return mixed
|
||||
*/
|
||||
public function setUploadFileByReal($filePath)
|
||||
{
|
||||
return $this->engine->setUploadFileByReal($filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行文件上传
|
||||
* @param $save_dir (保存路径)
|
||||
* @return mixed
|
||||
*/
|
||||
public function upload($save_dir)
|
||||
{
|
||||
return $this->engine->upload($save_dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 抓取网络资源
|
||||
* @param $url
|
||||
* @param $key
|
||||
* @author 张无忌(2021/3/2 14:16)
|
||||
* @return mixed
|
||||
*/
|
||||
public function fetch($url, $key) {
|
||||
return $this->engine->fetch($url, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行文件删除
|
||||
* @param $fileName
|
||||
* @return mixed
|
||||
*/
|
||||
public function delete($fileName)
|
||||
{
|
||||
return $this->engine->delete($fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取错误信息
|
||||
* @return mixed
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
return $this->engine->getError();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件路径
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFileName()
|
||||
{
|
||||
return $this->engine->getFileName();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回文件信息
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFileInfo()
|
||||
{
|
||||
return $this->engine->getFileInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前的存储引擎
|
||||
* @param null|string $storage 指定存储方式,如不指定则为系统默认
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
private function getEngineClass($storage = null)
|
||||
{
|
||||
$engineName = is_null($storage) ? $this->config['default'] : $storage;
|
||||
$classSpace = __NAMESPACE__ . '\\engine\\' . ucfirst($engineName);
|
||||
if (!class_exists($classSpace)) {
|
||||
throw new Exception('未找到存储引擎类: ' . $engineName);
|
||||
}
|
||||
return new $classSpace($this->config['engine'][$engineName]);
|
||||
}
|
||||
|
||||
}
|
||||
115
application/common/server/storage/engine/Aliyun.php
Normal file
115
application/common/server/storage/engine/Aliyun.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\server\storage\engine;
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
/**
|
||||
* 阿里云存储引擎 (OSS)
|
||||
* Class Qiniu
|
||||
* @package app\common\library\storage\engine
|
||||
*/
|
||||
class Aliyun extends Server
|
||||
{
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* Aliyun constructor.
|
||||
* @param $config
|
||||
*/
|
||||
public function __construct($config)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行上传
|
||||
* @param $save_dir (保存路径)
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function upload($save_dir)
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient(
|
||||
$this->config['access_key_id'],
|
||||
$this->config['access_key_secret'],
|
||||
$this->config['domain'],
|
||||
true
|
||||
);
|
||||
$ossClient->uploadFile(
|
||||
$this->config['bucket'],
|
||||
$save_dir . '/' . $this->fileName,
|
||||
$this->getRealPath()
|
||||
);
|
||||
} catch (OssException $e) {
|
||||
$this->error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 抓取远程资源
|
||||
* @param $url
|
||||
* @param null $key
|
||||
* @return mixed|void
|
||||
* @author 张无忌(2021/3/2 14:36)
|
||||
*/
|
||||
public function fetch($url, $key = null)
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient(
|
||||
$this->config['access_key_id'],
|
||||
$this->config['access_key_secret'],
|
||||
$this->config['domain'],
|
||||
true
|
||||
);
|
||||
|
||||
$content = file_get_contents($url);
|
||||
$ossClient->putObject(
|
||||
$this->config['bucket'],
|
||||
$key,
|
||||
$content
|
||||
);
|
||||
} catch (OssException $e) {
|
||||
$this->error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param $fileName
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function delete($fileName)
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient(
|
||||
$this->config['access_key_id'],
|
||||
$this->config['access_key_secret'],
|
||||
$this->config['domain'],
|
||||
true
|
||||
);
|
||||
$ossClient->deleteObject($this->config['bucket'], $fileName);
|
||||
} catch (OssException $e) {
|
||||
$this->error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回文件路径
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFileName()
|
||||
{
|
||||
return $this->fileName;
|
||||
}
|
||||
|
||||
}
|
||||
57
application/common/server/storage/engine/Local.php
Normal file
57
application/common/server/storage/engine/Local.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\server\storage\engine;
|
||||
|
||||
|
||||
/**
|
||||
* 本地文件驱动
|
||||
* Class Local
|
||||
* @package app\common\library\storage\drivers
|
||||
*/
|
||||
class Local extends Server
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传
|
||||
* @param $save_dir (保存路径)
|
||||
* @return bool
|
||||
*/
|
||||
public function upload($save_dir)
|
||||
{
|
||||
// 验证文件并上传
|
||||
$info = $this->file->move($save_dir, $this->fileName);
|
||||
if (empty($info)) {
|
||||
$this->error = $this->file->getError();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function fetch($url, $key=null) {}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param $fileName
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function delete($fileName)
|
||||
{
|
||||
// 文件所在目录
|
||||
$filePath = ROOT_PATH . "/{$fileName}";
|
||||
return !file_exists($filePath) ?: unlink($filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回文件路径
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFileName()
|
||||
{
|
||||
return $this->fileName;
|
||||
}
|
||||
|
||||
}
|
||||
116
application/common/server/storage/engine/Qcloud.php
Normal file
116
application/common/server/storage/engine/Qcloud.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\server\storage\engine;
|
||||
|
||||
use Qcloud\Cos\Client;
|
||||
|
||||
/**
|
||||
* 腾讯云存储引擎 (COS)
|
||||
* Class Qiniu
|
||||
* @package app\common\library\storage\engine
|
||||
*/
|
||||
class Qcloud extends Server
|
||||
{
|
||||
private $config;
|
||||
private $cosClient;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* Qcloud constructor.
|
||||
* @param $config
|
||||
*/
|
||||
public function __construct($config)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->config = $config;
|
||||
// 创建COS控制类
|
||||
$this->createCosClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建COS控制类
|
||||
*/
|
||||
private function createCosClient()
|
||||
{
|
||||
$this->cosClient = new Client([
|
||||
'region' => $this->config['region'],
|
||||
'credentials' => [
|
||||
'secretId' => $this->config['secret_id'],
|
||||
'secretKey' => $this->config['secret_key'],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行上传
|
||||
* @param $save_dir (保存路径)
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function upload($save_dir)
|
||||
{
|
||||
// 上传文件
|
||||
// putObject(上传接口,最大支持上传5G文件)
|
||||
try {
|
||||
$result = $this->cosClient->putObject([
|
||||
'Bucket' => $this->config['bucket'],
|
||||
'Key' => $save_dir . '/' . $this->fileName,
|
||||
'Body' => fopen($this->getRealPath(), 'rb')
|
||||
]);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$this->error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 抓取远程资源
|
||||
* @param $url
|
||||
* @param null $key
|
||||
* @author 张无忌(2021/3/2 14:36)
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function fetch($url, $key=null) {
|
||||
// putObject(上传接口,最大支持上传5G文件)
|
||||
try {
|
||||
$result = $this->cosClient->putObject([
|
||||
'Bucket' => $this->config['bucket'],
|
||||
'Key' => $key,
|
||||
'Body' => fopen($url, 'rb')
|
||||
]);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$this->error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param $fileName
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function delete($fileName)
|
||||
{
|
||||
try {
|
||||
$result = $this->cosClient->deleteObject(array(
|
||||
'Bucket' => $this->config['bucket'],
|
||||
'Key' => $fileName
|
||||
));
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$this->error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回文件路径
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFileName()
|
||||
{
|
||||
return $this->fileName;
|
||||
}
|
||||
|
||||
}
|
||||
131
application/common/server/storage/engine/Qiniu.php
Normal file
131
application/common/server/storage/engine/Qiniu.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\server\storage\engine;
|
||||
|
||||
use Qiniu\Auth;
|
||||
use Qiniu\Storage\UploadManager;
|
||||
use Qiniu\Storage\BucketManager;
|
||||
|
||||
/**
|
||||
* 七牛云存储引擎
|
||||
* Class Qiniu
|
||||
* @package app\common\library\storage\engine
|
||||
*/
|
||||
class Qiniu extends Server
|
||||
{
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* Qiniu constructor.
|
||||
* @param $config
|
||||
*/
|
||||
public function __construct($config)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行上传
|
||||
* @param $save_dir (保存路径)
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function upload($save_dir)
|
||||
{
|
||||
// 要上传图片的本地路径
|
||||
$realPath = $this->getRealPath();
|
||||
|
||||
// 构建鉴权对象
|
||||
$auth = new Auth($this->config['access_key'], $this->config['secret_key']);
|
||||
|
||||
// 要上传的空间
|
||||
$token = $auth->uploadToken($this->config['bucket']);
|
||||
|
||||
// 初始化 UploadManager 对象并进行文件的上传
|
||||
$uploadMgr = new UploadManager();
|
||||
|
||||
try {
|
||||
// 调用 UploadManager 的 putFile 方法进行文件的上传
|
||||
$key = $save_dir . '/' . $this->fileName;
|
||||
list(, $error) = $uploadMgr->putFile($token, $key, $realPath);
|
||||
|
||||
if ($error !== null) {
|
||||
$this->error = $error->message();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$this->error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 抓取远程资源
|
||||
* @param $url
|
||||
* @param null $key
|
||||
* @author 张无忌(2021/3/2 14:03)
|
||||
* @return bool
|
||||
*/
|
||||
public function fetch($url, $key=null)
|
||||
{
|
||||
try {
|
||||
if (substr($url, 0, 1) !== '/' || strstr($url, 'http://') || strstr($url, 'https://')) {
|
||||
$auth = new Auth($this->config['access_key'], $this->config['secret_key']);
|
||||
$bucketManager = new BucketManager($auth);
|
||||
list(, $err) = $bucketManager->fetch($url, $this->config['bucket'], $key);
|
||||
} else {
|
||||
$auth = new Auth($this->config['access_key'], $this->config['secret_key']);
|
||||
$token = $auth->uploadToken($this->config['bucket']);
|
||||
$uploadMgr = new UploadManager();
|
||||
list(, $err) = $uploadMgr->putFile($token, $key, $url);
|
||||
}
|
||||
|
||||
if ($err !== null) {
|
||||
$this->error = $err->message();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$this->error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param $fileName
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function delete($fileName)
|
||||
{
|
||||
// 构建鉴权对象
|
||||
$auth = new Auth($this->config['access_key'], $this->config['secret_key']);
|
||||
// 初始化 UploadManager 对象并进行文件的上传
|
||||
$bucketMgr = new BucketManager($auth);
|
||||
|
||||
try {
|
||||
$error = $bucketMgr->delete($this->config['bucket'], $fileName);
|
||||
// if ($error !== null) {
|
||||
// $this->error = $error->message();
|
||||
// return false;
|
||||
// }
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$this->error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回文件路径
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFileName()
|
||||
{
|
||||
return $this->fileName;
|
||||
}
|
||||
|
||||
}
|
||||
134
application/common/server/storage/engine/Server.php
Normal file
134
application/common/server/storage/engine/Server.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\server\storage\engine;
|
||||
|
||||
use think\Request;
|
||||
use think\Exception;
|
||||
|
||||
/**
|
||||
* 存储引擎抽象类
|
||||
* Class server
|
||||
* @package app\common\library\storage\drivers
|
||||
*/
|
||||
abstract class Server
|
||||
{
|
||||
protected $file;
|
||||
protected $error;
|
||||
protected $fileName;
|
||||
protected $fileInfo;
|
||||
|
||||
// 是否为内部上传
|
||||
protected $isInternal = false;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* Server constructor.
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置上传的文件信息
|
||||
* @param string $name
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setUploadFile($name)
|
||||
{
|
||||
// 接收上传的文件
|
||||
$this->file = request()->file($name);
|
||||
if (empty($this->file)) {
|
||||
throw new Exception('未找到上传文件的信息');
|
||||
}
|
||||
// 文件信息
|
||||
$this->fileInfo = $this->file->getInfo();
|
||||
// 生成保存文件名
|
||||
$this->fileName = $this->buildSaveName();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置上传的文件信息
|
||||
* @param string $filePath
|
||||
*/
|
||||
public function setUploadFileByReal($filePath)
|
||||
{
|
||||
// 设置为系统内部上传
|
||||
$this->isInternal = true;
|
||||
// 文件信息
|
||||
$this->fileInfo = [
|
||||
'name' => basename($filePath),
|
||||
'size' => filesize($filePath),
|
||||
'tmp_name' => $filePath,
|
||||
'error' => 0,
|
||||
];
|
||||
// 生成保存文件名
|
||||
$this->fileName = $this->buildSaveName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 抓取网络资源
|
||||
* @param $url
|
||||
* @param $key
|
||||
* @author 张无忌(2021/3/2 14:15)
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function fetch($url, $key);
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
* @param $save_dir (保存路径)
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function upload($save_dir);
|
||||
|
||||
/**
|
||||
* 文件删除
|
||||
* @param $fileName
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function delete($fileName);
|
||||
|
||||
/**
|
||||
* 返回上传后文件路径
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function getFileName();
|
||||
|
||||
/**
|
||||
* 返回文件信息
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFileInfo()
|
||||
{
|
||||
return $this->fileInfo;
|
||||
}
|
||||
|
||||
protected function getRealPath()
|
||||
{
|
||||
return $this->getFileInfo()['tmp_name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回错误信息
|
||||
* @return mixed
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成保存文件名
|
||||
*/
|
||||
private function buildSaveName()
|
||||
{
|
||||
// 要上传图片的本地路径
|
||||
$realPath = $this->getRealPath();
|
||||
// 扩展名
|
||||
$ext = pathinfo($this->getFileInfo()['name'], PATHINFO_EXTENSION);
|
||||
// 自动生成文件名
|
||||
return date('YmdHis') . substr(md5($realPath), 0, 5)
|
||||
. str_pad(rand(0, 9999), 4, '0', STR_PAD_LEFT) . ".{$ext}";
|
||||
}
|
||||
|
||||
}
|
||||
114
application/common/validate/Coupon.php
Normal file
114
application/common/validate/Coupon.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\validate;
|
||||
use think\Db;
|
||||
use think\Validate;
|
||||
|
||||
|
||||
class Coupon extends Validate{
|
||||
protected $rule = [
|
||||
'name' => 'require|max:16',
|
||||
'send_time_start' => 'require|checkSendTime',
|
||||
'send_time_end' => 'require',
|
||||
'money' => 'require|gt:0',
|
||||
'scene_type' => 'require|in:1',
|
||||
'platform_ratio' => 'require',
|
||||
'shop_ratio' => 'require',
|
||||
'send_total_type' => 'require|in:1,2',
|
||||
'send_total' => 'requireIf:send_total_type,2|gt:0',
|
||||
'condition_type' => 'require|in:1,2',
|
||||
'condition_money' => 'requireIf:condition_type,2|gt:0',
|
||||
'use_time_type' => 'require|in:1,2,3',
|
||||
'use_time_start' => 'requireIf:use_time_type,1|checkUseTime',
|
||||
'use_time_end' => 'requireIf:use_time_type,1',
|
||||
'use_time' => 'requireIf:use_time_type,2',
|
||||
'tomorrow_use_time' => 'requireIf:use_time_type,3',
|
||||
'get_type' => 'require|in:1,2',
|
||||
'get_num_type' => 'require|in:1,2,3',
|
||||
'get_num' => 'requireIf:get_num_type,2',
|
||||
'day_get_num' => 'requireIf:get_num_type,3',
|
||||
'use_goods_type' => 'require|in:1,2,3',
|
||||
'goods_ids' => 'checkGoods',
|
||||
];
|
||||
protected $message = [
|
||||
'name.require' => '请输入优惠券名称',
|
||||
'name.max' => '优惠券名称长度最多16个字符',
|
||||
'send_time_start.require' => '请选择优惠券开始发放时间',
|
||||
'send_time_end.require' => '请选择优惠券结束发放时间',
|
||||
'money.require' => '请输入优惠券面额',
|
||||
'money.gt' => '优惠券面额必须大于零',
|
||||
'scene_type.require' => '请选择使用场景',
|
||||
'scene_type.in' => '使用场景类型错误',
|
||||
'platform_ratio.require' => '请输入平台分摊比例',
|
||||
'shop_ratio.require' => '请输入店铺分摊比例',
|
||||
'send_total_type.require' => '请选择发放总量',
|
||||
'send_total_type.in' => '发放总量类型错误',
|
||||
'condition_type.require' => '请选择使用门槛',
|
||||
'condition_type.in' => '使用门槛类型错误',
|
||||
'use_time_type.require' => '请选择用券时间',
|
||||
'use_time_start.requireIf' => '请选择优惠券使用时间',
|
||||
'use_time_end.requireIf' => '请选择优惠券使用时间',
|
||||
'use_time.requireIf' => '请选择优惠券使用时间',
|
||||
'tomorrow_use_time.requireIf' => '请选择优惠券使用时间',
|
||||
'get_type.require' => '请选择领取方式',
|
||||
'get_type.in' => '领取方式类型错误',
|
||||
'get_num_type.require' => '请选择领取次数',
|
||||
'get_num_type.in' => '领取次数类型错误',
|
||||
'get_num.requireIf' => '请输入领取次数',
|
||||
'day_get_num.requireIf' => '请输入领取次数',
|
||||
'use_goods_type.require' => '请选择适用商品',
|
||||
'use_goods_type.in' => '适用商品类型错误',
|
||||
];
|
||||
|
||||
protected function scenePlatfrom(){
|
||||
$this->remove(['use_goods_type','goods_ids']);
|
||||
}
|
||||
|
||||
protected function sceneShop(){
|
||||
$this->remove(['scene_type','platform_ratio','shop_ratio']);
|
||||
}
|
||||
|
||||
public function checkGoods($value,$rule,$data){
|
||||
if($data['use_goods_type'] !=1 ){
|
||||
$shop_goods_list = Db::name('goods')->where(['del'=>0,'shop_id'=>$data['shop_id']])->column('id');
|
||||
foreach ($value as $item){
|
||||
if (!in_array($item,$shop_goods_list)){
|
||||
return '商品ID:'.$item.'不可使用';
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkUseTime($value,$rule,$data){
|
||||
if($value && $value == $data['use_time_end']){
|
||||
return '用券时间开始时间和结束时间不能相同';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkSendTime($value,$rule,$data){
|
||||
if($value && $value == $data['send_time_end']){
|
||||
return '发放开始时间和结束时间不能相同';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
45
application/common/validate/Crontab.php
Normal file
45
application/common/validate/Crontab.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop100%开源免费商用商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshopTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use think\Validate;
|
||||
|
||||
class Crontab extends Validate
|
||||
{
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
protected $message = [
|
||||
];
|
||||
|
||||
|
||||
public function ruleFormat($rule)
|
||||
{
|
||||
$arr = explode(' ', $rule);
|
||||
if (count($arr) != 5) {
|
||||
return false;
|
||||
}
|
||||
list($minute, $hour, $day_of_month, $month, $day_of_week) = $arr;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user