first commit

This commit is contained in:
云泽网
2025-07-27 21:42:34 +08:00
commit c1cce5ccb4
2779 changed files with 340042 additions and 0 deletions
@@ -0,0 +1,115 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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;
}
}
@@ -0,0 +1,113 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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;
}
}
@@ -0,0 +1,128 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\behavior;
use app\common\logic\AccountLogLogic;
use app\common\model\AccountLog;
use app\common\model\Order;
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);
// 自提订单没有发货操作。
// 当订单为自提方式,赠送机制为订单发货赠送且传入场景为 3=订单完成(自提核销操作) 时
// 调整场景值为2,便于通过后续场景值验证
if ($order['delivery_type'] == Order::DELIVERY_STATUS_SELF && $attach['give_growth_scene'] == 2 && $scene == 3) {
$scene = 2;
}
$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_goods_give_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;
}
}
@@ -0,0 +1,149 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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'];
if (empty($params['time'])) {
$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;
}
}
@@ -0,0 +1,89 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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;
}
}
@@ -0,0 +1,225 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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;
}
}
@@ -0,0 +1,66 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\behavior;
use think\Db;
/**
* 更新商品收藏夹
* Class UpdateCollect
* @package app\common\behavior
*/
class UpdateCollect
{
public function run($params)
{
try {
$goods_ids = $params['goods_id'] ?? '';
if (empty($goods_ids)) {
return true;
}
if (!is_array($goods_ids)) {
$goods_ids = [$goods_ids];
}
$map1 = [
['id', 'in', $goods_ids],
['status', '<>', 1],
];
$map2 = [
['id', 'in', $goods_ids],
['del', '=', 1],
];
$goods_ids = Db::name('goods')->whereOr([$map1, $map2])->column('id');
if (empty($goods_ids)) {
return true;
}
Db::name('goods_collect')->whereIn('goods_id', $goods_ids)->delete();
return true;
} catch (\Exception $e) {
return $e->getMessage();
}
}
}
+125
View File
@@ -0,0 +1,125 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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
View File
@@ -0,0 +1,43 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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');
}
}
@@ -0,0 +1,102 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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());
}
}
}
@@ -0,0 +1,103 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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]);
}
}
}
}
@@ -0,0 +1,176 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\command;
use app\admin\logic\DistributionLevelLogic;
use app\common\logic\AccountLogLogic;
use app\common\model\{AccountLog,
AfterSale,
Distribution,
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)
{
//售后时间(未过售后时间的分销订单不处理)
$after_sale_time = ConfigServer::get('distribution', 'settlement_days', 7);
$after_sale_time = intval($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) {
$distribution = Distribution::where('user_id', $order['user_id'])->findOrEmpty()->toArray();
//当前分佣订单是否可结算 //非分销会员或已被冻结的分销会员不参与分佣
if ( false === self::isSettle($order) || empty($distribution)
|| $distribution['is_distribution'] != 1
|| $distribution['is_freeze'] == 1
) {
continue;
}
//增加佣金
$user = User::findOrEmpty($order['user_id']);
$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);
// 更新分销会员等级
DistributionLevelLogic::updateDistributionLevel($order['user_id']);
//通知会员
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;
}
}
@@ -0,0 +1,143 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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);
}
}
}
@@ -0,0 +1,97 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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();
}
}
}
@@ -0,0 +1,54 @@
<?php
namespace app\common\command;
use app\admin\logic\MyLogic;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;
use think\Db;
class Password extends Command
{
/**
* @notes
* @author 令狐冲
* @date 2021/11/24 10:56
*/
protected function configure()
{
$this->setName('password')
->addArgument('password', Argument::OPTIONAL, "your name")
->setDescription('修改超级管理密码');
}
/**
* @notes
* @param \think\console\Input $input
* @param \think\console\Output $output
* @return int|void|null
* @author 令狐冲
* @date 2021/11/22 17:15
*/
protected function execute(Input $input, Output $output)
{
$password = trim($input->getArgument('password'));
if (empty($password)) {
$output->error('请输入密码');
return;
}
$adminInfo = Db::name('admin')
->where('root', 1)
->find();
MyLogic::updatePassword($password, $adminInfo['id']);
$output->info('超级管理修改密码成功!');
$output->info('账号:' . $adminInfo['account']);
$output->info('密码:' . $password);
}
}
@@ -0,0 +1,153 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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)
->where('del', '=', 0)
->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());
}
}
}
@@ -0,0 +1,63 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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]);
}
}
@@ -0,0 +1,94 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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);
}
}
}
@@ -0,0 +1,95 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\command;
use app\admin\logic\WechatMerchantTransferLogic;
use app\admin\model\WithdrawApply;
use app\common\logic\AccountLogLogic;
use app\common\model\AccountLog;
use app\common\model\User;
use app\common\model\Withdraw;
use app\common\server\ConfigServer;
use think\console\Command;
use think\console\Output;
use think\console\Input;
use think\facade\Log;
class WechatMerchantTransfer extends Command
{
protected function configure()
{
$this->setName('wechat_merchant_transfer')
->setDescription('商家转账到零钱查询');
}
protected function execute(Input $input, Output $output)
{
//微信零钱接口:1-企业付款到零钱;2-商家转账到零钱
$transfer_way = ConfigServer::get('withdraw', 'transfer_way',1);
//选择了商家转账到零钱再进行查询
if ($transfer_way == 1) {
return false;
}
$lists = WithdrawApply::where(['type'=>Withdraw::TYPE_WECHAT_CHANGE,'status'=>Withdraw::STATUS_ING])
->field('id,sn,batch_no,user_id,money')
->select();
foreach ($lists as $list) {
$result = WechatMerchantTransferLogic::details($list);
// 记录查询结果
WithdrawApply::update(['update_time'=>time(),'pay_search_desc'=>json_encode($result, JSON_UNESCAPED_UNICODE)],['id'=>$list['id']]);
if(isset($result['detail_status'])) {
if ($result['detail_status'] == 'SUCCESS') {
// 转账成功,标记提现申请单为提现成功,记录支付信息
WithdrawApply::update(['status'=>3,'payment_no'=>$result['detail_id'],'payment_time'=>strtotime($result['update_time'])],['id'=>$list['id']]);
}
if ($result['detail_status'] == 'FAIL') {
// 转账失败
WithdrawApply::update(['status'=>4],['id'=>$list['id']]);
//回退佣金
$user = User::find($list['user_id']);
$user->earnings = ['inc', $list['money']];
$user->save();
//增加佣金变动记录
AccountLogLogic::AccountRecord(
$list['user_id'],
$list['money'],
1,
AccountLog::withdraw_back_earnings,
'',
$list['id'],
$list['sn']
);
}
if ($result['detail_status'] == 'PROCESSING') {
return ['code' => 0, 'msg' => '正在处理中'];
}
}else{
Log::write($result['message'] ?? '商家转账到零钱查询失败');
return null;
}
}
return true;
}
}
@@ -0,0 +1,73 @@
<?php
namespace app\common\command;
use app\common\model\Order;
use app\common\model\Pay;
use app\common\model\RechargeOrder;
use app\common\server\WechatMiniExpressSendSyncServer;
use think\console\Command;
use think\console\Input;
use think\console\Output;
class WechatMiniExpressSendSync extends Command
{
protected function configure()
{
$this->setName('wechat_mini_express_send_sync')->setDescription('微信小程序发货同步');
}
protected function execute(Input $input, Output $output)
{
// 订单
static::order();
// 用户充值
static::user_recharge();
}
private static function order()
{
// 快递
$list = Order::where('delivery_type', Order::DELIVERY_STATUS_EXPRESS)
->where('shipping_status', 1)
->where('pay_status', 1)
->where('pay_way', Pay::WECHAT_PAY)
->where('wechat_mini_express_sync', 0)
->where('order_status', 'in', [ Order::STATUS_WAIT_RECEIVE, Order::STATUS_FINISH ])
->limit(60)
->order('id desc')
->select()->toArray();
// 自提
$list2 = Order::where('delivery_type', Order::DELIVERY_STATUS_SELF)
->where('pay_status', 1)
->where('pay_way', Pay::WECHAT_PAY)
->where('wechat_mini_express_sync', 0)
->where('order_status', 'in', [ Order::STATUS_WAIT_DELIVERY, Order::STATUS_WAIT_RECEIVE, Order::STATUS_FINISH ])
->limit(20)
->order('id desc')
->select()->toArray();
// dump([ $list, $list2 ]);
foreach ([ $list, $list2 ] as $items) {
foreach ($items as $item) {
WechatMiniExpressSendSyncServer::_sync_order($item);
}
}
}
private static function user_recharge()
{
$list = RechargeOrder::where('pay_status', 1)
->where('pay_way', Pay::WECHAT_PAY)
->where('wechat_mini_express_sync', 0)
->limit(60)
->order('id desc')
->select()->toArray();
// dump($list);
foreach ($list as $item) {
WechatMiniExpressSendSyncServer::_sync_recharge($item);
}
}
}
@@ -0,0 +1,36 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用,保留版权即可
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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\http\middleware;
/**
* 基础中间件
* Class BaseMiddleware
* @package app\common\http\middleware
*/
class BaseMiddleware
{
public function handle($request, \Closure $next)
{
//过滤前后空格
$request->filter(['trim']);
return $next($request);
}
}
@@ -0,0 +1,81 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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;
}
}
@@ -0,0 +1,51 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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();
}
}
@@ -0,0 +1,44 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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);
}
}
@@ -0,0 +1,96 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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);
}
}
@@ -0,0 +1,60 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\logic;
use app\common\model\Distribution;
use app\common\model\DistributionLevel;
use app\common\server\ConfigServer;
/**
* 分销基础信息逻辑层
* Class DistributionLogic
* @package app\common\logic
*/
class DistributionLogic
{
/**
* @notes 添加分销基础信息记录
* @param $userId
* @author Tab
*/
public static function add($userId)
{
// 默认分销会员等级
$defaultLevelId = DistributionLevel::where('is_default', 1)->value('id');
// 分销会员开通方式
$apply_condition = ConfigServer::get('distribution', 'apply_condition', 2);
$isDistribution = $apply_condition == 1 ? 1 : 0;
$data = [
'user_id' => $userId,
'level_id' => $defaultLevelId,
'is_distribution' => $isDistribution,
'is_freeze' => 0,
'remark' => '',
];
if($isDistribution) {
// 成为分销会员时间
$data['distribution_time'] = time();
}
Distribution::create($data);
}
}
@@ -0,0 +1,265 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\logic;
use app\common\model\DistributionGoods;
use app\common\model\DistributionLevel;
use app\common\model\DistributionOrderGoods;
use app\common\model\Order;
use app\common\model\OrderGoods;
use app\common\model\User;
use app\common\server\ConfigServer;
class DistributionOrderGoodsLogic extends LogicBase
{
/**
* @notes 生成分销订单
* @param $order_id
* @param $user_id
* @author Tab
*/
public static function add($orderId)
{
// 获取分销配置
$distributionConfig = [
'is_open' => ConfigServer::get('distribution', 'is_open', 0),
'level' => ConfigServer::get('distribution', 'level', 2),
];
if(!$distributionConfig['is_open']) {
return false;
}
// 用户信息
$order = Order::where('id', $orderId)->findOrEmpty()->toArray();
$userInfo = self::userInfo($order['user_id']);
// 订单信息
$orderInfo = self::orderInfo($orderId);
// 遍历子订单
foreach($orderInfo as $item) {
// 判断商品是否参与分销
$goodsDistribution = self::checkGoodsDistribution($item['goods_id']);
if(empty($goodsDistribution) || !$goodsDistribution['is_distribution']) {
// 商品未参与分销
continue;
}
// 分销层级
switch($distributionConfig['level'])
{
case 1: // 一级分销
self::firstLevelCommission($userInfo, $item, $goodsDistribution);
break;
case 2: // 一级、二级分销
self::firstLevelCommission($userInfo, $item, $goodsDistribution);
self::secondLevelCommission($userInfo, $item, $goodsDistribution);
break;
}
}
}
/**
* @notes 用户信息
* @param $userId
* @return mixed
* @author Tab
*/
public static function userInfo($userId)
{
$userInfo = User::alias('u')
->leftJoin('distribution d', 'd.user_id = u.id')
->field('u.id,u.nickname,u.first_leader,u.second_leader,d.level_id,d.is_distribution,d.is_freeze')
->where('u.id', $userId)
->findOrEmpty()
->toArray();
return $userInfo;
}
/**
* @notes 订单信息
* @param $orderId
* @return mixed
* @author Tab
*/
public static function orderInfo($orderId)
{
$orderInfo = OrderGoods::alias('og')
->leftJoin('order o', 'o.id = og.order_id')
->field('og.id as order_goods_id,og.order_id,og.goods_id,og.item_id,og.goods_num,og.total_pay_price,o.user_id')
->where('og.order_id', $orderId)
->select()
->toArray();
return $orderInfo;
}
/**
* @notes 校验商品是否参与分销
* @param $goodsId
* @return array
* @author Tab
*/
public static function checkGoodsDistribution($goodsId)
{
$distributionGoods = DistributionGoods::field('goods_id,item_id,level_id,first_ratio,second_ratio,is_distribution,rule')
->where('goods_id', $goodsId)
->select()
->toArray();
if(empty($distributionGoods)) {
return [];
}
return [
'goods_id' => $distributionGoods[0]['goods_id'],
'is_distribution' => $distributionGoods[0]['is_distribution'],
'rule' => $distributionGoods[0]['rule']
];
}
/**
* @notes 一级分佣
* @param $userInfo
* @param $item
* @param $goodsDistribution
* @return false
* @author Tab
*/
public static function firstLevelCommission($userInfo, $item, $goodsDistribution)
{
if(!$userInfo['first_leader']) {
// 没有上级,无需分佣
return false;
}
$firstLeaderInfo = self::userInfo($userInfo['first_leader']);
if(!$firstLeaderInfo['is_distribution'] || $firstLeaderInfo['is_freeze']) {
// 上级不是分销会员 或 分销资格已冻结
return false;
}
$ratioArr = self::getRatio($goodsDistribution, $item, $firstLeaderInfo);
$firstLeaderInfo['ratio'] = $ratioArr['first_ratio'];
$firstLeaderInfo['level'] = 1;
self::addDistributionOrderGoods($item, $firstLeaderInfo);
}
/**
* @notes 获取分佣比例
* @param $goodsDistribution
* @param $item
* @param $userInfo
* @return array
* @author Tab
*/
public static function getRatio($goodsDistribution, $item, $userInfo)
{
// 按分销会员等级对应的比例
if($goodsDistribution['rule'] == 1) {
$ratioArr = DistributionLevel::field('first_ratio,second_ratio')
->where('id', $userInfo['level_id'])
->findOrEmpty()
->toArray();
return $ratioArr;
}
// 单独设置的比例
if($goodsDistribution['rule'] == 2) {
$ratioArr = DistributionGoods::field('first_ratio,second_ratio')
->where([
'goods_id' => $item['goods_id'],
'item_id' => $item['item_id'],
'level_id' => $userInfo['level_id']
])
->findOrEmpty()
->toArray();
return $ratioArr;
}
}
/**
* @notes 二级分佣
* @param $userInfo
* @param $item
* @param $goodsDistribution
* @return false
* @author Tab
*/
public static function secondLevelCommission($userInfo, $item, $goodsDistribution)
{
if(!$userInfo['second_leader']) {
// 没有上上级,无需分佣
return false;
}
$secondLeaderInfo = self::userInfo($userInfo['second_leader']);
if(!$secondLeaderInfo['is_distribution'] || $secondLeaderInfo['is_freeze']) {
// 上上级不是分销会员 或 分销资格已冻结
return false;
}
$ratioArr = self::getRatio($goodsDistribution, $item, $secondLeaderInfo);
$secondLeaderInfo['ratio'] = $ratioArr['second_ratio'];
$secondLeaderInfo['level'] = 2;
self::addDistributionOrderGoods($item, $secondLeaderInfo);
}
/**
* @notes 生成分销订单
* @param $item
* @param $userInfo
* @return false
* @author Tab
*/
public static function addDistributionOrderGoods($item, $userInfo)
{
$earnings = 0;
$earnings = self::calByPaymentAmount($item, $userInfo);
if($earnings < 0.01) {
return false;
}
$data = [
'sn' => createSn('distribution_order_goods', 'sn'),
'user_id' => $userInfo['id'],
'real_name' => $userInfo['nickname'],
'level_id' => $userInfo['level_id'],
'level' => $userInfo['level'],
'ratio' => $userInfo['ratio'],
'order_id' => $item['order_id'],
'order_goods_id' => $item['order_goods_id'],
'goods_num' => $item['goods_num'],
'money' => $earnings,
'status' => 1,
'create_time' => time(),
];
DistributionOrderGoods::create($data);
}
/**
* @notes 根据商品实际支付金额计算佣金
* @param $item
* @param $userInfo
* @return float
* @author Tab
*/
public static function calByPaymentAmount($item, $userInfo)
{
$earnings = round(($item['total_pay_price'] * $userInfo['ratio'] / 100), 2);
return $earnings;
}
}
@@ -0,0 +1,179 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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'] = $v['name'];
$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;
}
}
@@ -0,0 +1,236 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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;
}
}
@@ -0,0 +1,43 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\logic;
class LogicBase
{
public static $error;
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);
}
public static function getError()
{
return self::$error;
}
}
@@ -0,0 +1,203 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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;
}
}
@@ -0,0 +1,191 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\logic;
use app\api\logic\SeckillLogic;
use app\common\model\AfterSale;
use app\common\model\Order;
use app\common\model\OrderGoods;
use app\common\model\Pay;
use app\common\server\ConfigServer;
use think\Db;
use think\facade\Hook;
/**
* 订单商品逻辑
* 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]);
// 下架或删除商品,更新商品收藏
Hook::listen('update_collect', ['goods_id' => $need_handle_ids]);
} catch (\Exception $e) {}
}
/**
* @notes 获取订单商品 退款运费
* @return integer|float
* @author lbzy
* @datetime 2023-06-26 09:20:21
*/
static function getRefundExpressMoney($id)
{
$orderGoods = OrderGoods::find($id);
$order = Order::find($orderGoods['order_id'] ?? 0);
// 不是待发货 不退运费
if (empty($order['id']) || $order['order_status'] != Order::STATUS_WAIT_DELIVERY) {
return 0;
}
$after_sales = AfterSale::where('order_id', $order['id'])->select()->toArray();
$aids = [];
foreach ($after_sales as $after_sale) {
if (! in_array($after_sale['order_goods_id'], $aids)) {
$aids[] = $after_sale['order_goods_id'];
}
}
$orderGoodsList = OrderGoods::where('order_id', $order['id'])->select()->toArray();
if (count($aids) != count($orderGoodsList)) {
if (in_array($id, $aids)) {
return 0;
} else {
// 没有记录,是否是最后一个订单商品
return count($aids) == (count($orderGoodsList) - 1) ? $order['shipping_price'] : 0;
}
}
// 有记录,是否是在最后申请的
return $aids[count($aids) - 1] == $id ? $order['shipping_price'] : 0;
}
}
@@ -0,0 +1,50 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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();
}
}
@@ -0,0 +1,361 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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;
use think\facade\Log;
/**
* 订单退款逻辑
* 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
* @return bool
* @throws Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
* @author 段誉
* @date 2021/12/20 14:48
*/
public static function refund($order, $order_amount, $refund_amount)
{
// 退款记录
$refund_id = self::addRefundLog($order, $order_amount, $refund_amount);
// 退款金额为0
if ($refund_amount <= 0) {
return false;
}
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;
}
return true;
}
/**
* 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' => intval(strval($refund_log['order_amount'] * 100)),//订单金额,单位为分
'refund_fee' => intval(strval($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)
{
$refund_log = Db::name('order_refund')->where(['id' => $refund_id])->find();
$result = (new AliPayServer())->refund($order['order_sn'], $refund_log['refund_amount'], [ 'out_request_no' => $refund_log['refund_sn'] ]);
$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 {
Log::write($result, 'alipay_refund_error');
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);
}
}
@@ -0,0 +1,203 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\logic;
use app\admin\logic\DistributionLevelLogic;
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']];
$user->save();
// 更改订单状态
$orderData = [
'pay_status' => Pay::ISPAID,
'pay_time' => $time,
'order_status' => Order::STATUS_WAIT_DELIVERY,
'transaction_id' => $extra['transaction_id'] ?? '',
];
if (! Order::where('id', $order->id)->where('pay_status', Pay::UNPAID)->update($orderData)) {
throw new \Exception('订单更改状态失败');
}
//扣除库存
$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){
// 生成分销订单
DistributionOrderGoodsLogic::add($order['id']);
// 更新分销会员等级
DistributionLevelLogic::updateDistributionLevel($order['user_id']);
}
//下单奖励积分(每天首单)
IntegralLogic::rewardIntegral($user['id'], $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' => date('Y-m-d H:i', strtotime($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);
}
}
@@ -0,0 +1,203 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\logic;
use app\common\server\AliPayServer;
use app\common\server\BalancePayServer;
use app\common\server\WeChatPayServer;
use app\common\model\{Client_, Order, Pay, User};
use think\facade\Env;
use think\Db;
class PaymentLogic extends LogicBase
{
public static $error = '';
public 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)
{
// 更新订单支付方式
if($from == 'order') {
Order::update([
'id' => $order['id'],
'pay_way' => $order['pay_way']
]);
}
if($from == 'recharge') {
Db::name('recharge_order')->where('id', $order['id'])->update(['pay_way' => $order['pay_way']]);
}
// 订单金额为0的情况,直接走支付回调接口
if($order['order_amount'] == 0) {
PayNotifyLogic::handle('order', $order['order_sn'], []);
return $order['id'];
}
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 = 10001;//特殊状态码,用于前端判断
}
break;
case Pay::BALANCE_PAY:
$balancePay = new BalancePayServer();
$res = $balancePay->pay($from, $order, $order_source);
if($res !== false) {
PayNotifyLogic::handle('order', $order['order_sn'], []);
self::$return_code = 20001;//特殊状态码,用于前端判断
}else{
self::$error = $balancePay->getError();
}
break;
default:
self::$error = '订单异常';
$res = false;
}
return $res;
}
/**
* Notes: pc预支付
* @param $order
* @author 段誉(2021/3/17 14:56)
* @return array|bool|string
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public static function pcPay($order, $order_source = Client_::pc)
{
$res = [];
// 更新订单支付方式
Order::update([
'id' => $order['id'],
'pay_way' => $order['pay_way']
]);
// 订单金额为0的情况,直接走支付回调接口
if($order['order_amount'] == 0) {
PayNotifyLogic::handle('order', $order['order_sn'], []);
self::$return_code = 10001;//特殊状态码,用于前端判断
return $order['id'];
}
switch ($order['pay_way']) {
case Pay::WECHAT_PAY:
$res = WeChatPayServer::unifiedOrder('order', $order, $order_source);
if (false === $res) {
self::$error = WeChatPayServer::getError();
return false;
}
break;
case Pay::BALANCE_PAY:
$user = User::get($order['user_id']);
if ($user['user_money'] < $order['order_amount']) {
self::$error = '余额不足';
return false;
}
$balancePay = new BalancePayServer();
$res = $balancePay->pay('order', $order, '5');
if($res !== false) {
PayNotifyLogic::handle('order', $order['order_sn'], []);
self::$return_code = 10001;//特殊状态码,用于前端判断
}else{
self::$error = $balancePay->getError();
return false;
}
break;
case Pay::ALI_PAY:
if ($order_source != Client_::pc) {
self::$error = '支付类型错误';
return false;
}
$aliPay = new AliPayServer();
$res = $aliPay->pay('order', $order, $order_source);
if (false === $res) {
self::$error = $aliPay->getError();
return false;
}
self::$return_code = 20001;//特殊状态码,用于前端判断
break;
default:
self::$error = '无效的支付方式';
return false;
}
return $res;
}
/**
* 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;
}
}
@@ -0,0 +1,594 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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('invite', '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;
}
}
@@ -0,0 +1,75 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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();
}
}
@@ -0,0 +1,64 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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()]);
}
}
@@ -0,0 +1,170 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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 luck_draw_inc_balance = 109;
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 luck_draw_dec_integral = 212;
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 admin_inc_earnings = 403; //后台增加佣金
const admin_reduce_earnings = 404; //后台减少佣金
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, self::luck_draw_inc_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, self::luck_draw_dec_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, self::admin_inc_earnings, self::admin_reduce_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 => '下单赠送成长值',
self::admin_inc_earnings => '后台增加佣金',
self::admin_reduce_earnings => '后台减少佣金',
self::luck_draw_dec_integral => '积分抽奖消耗积分',
self::luck_draw_inc_balance => '积分抽奖中奖余额',
];
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 '';
}
}
+173
View File
@@ -0,0 +1,173 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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,
],
[
'name' => '积分签到',
'path' => '/bundle/pages/user_sign/user_sign',
'is_tab' => 0,
],
[
'name' => '会员中心',
'path' => '/pages/user_vip/user_vip',
'is_tab' => 0,
],
[
'name' => '积分抽奖',
'path' => '/bundle/pages/luckly_wheel/luckly_wheel',
'is_tab' => 0,
],
[
'name' => '限时秒杀',
'path' => '/bundle/pages/goods_seckill/goods_seckill',
'is_tab' => 0,
],
[
'name' => '拼团活动',
'path' => '/bundle/pages/goods_combination/goods_combination',
'is_tab' => 0,
],
[
'name' => '砍价活动',
'path' => '/bundle/pages/bargain/bargain',
'is_tab' => 0,
],
[
'name' => '热销榜单',
'path' => '/bundle/pages/hot_list/hot_list',
'is_tab' => 0,
],
[
'name' => '商城资讯',
'path' => '/pages/news_list/news_list',
'is_tab' => 0,
],
[
'name' => '帮助中心',
'path' => '/pages/news_list/news_list?type=1',
'is_tab' => 0,
],
],
self::pc => [
[
'name' => '商品分类',
'path' => '/category',
'is_tab' => 0,
],
[
'name' => '领券中心',
'path' => '/get_coupons',
'is_tab' => 0,
],
[
'name' => '个人中心',
'path' => '/user/profile',
'is_tab' => 0,
],
[
'name' => '热销榜单',
'path' => '/goods_list/1',
'is_tab' => 0,
],
[
'name' => '新品推荐',
'path' => '/goods_list/2',
'is_tab' => 0,
],
[
'name' => '好物优选',
'path' => '/goods_list/3',
'is_tab' => 0,
],
[
'name' => '限时秒杀',
'path' => '/seckill',
'is_tab' => 0,
],
[
'name' => '商城资讯',
'path' => '/news_list',
'is_tab' => 0,
],
[
'name' => '帮助中心',
'path' => '/help_center',
'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] ?? '';
}
}
@@ -0,0 +1,138 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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;//退款退货
/**
* @notes 不能核销的状态
* @return array
* @author lbzy
* @datetime 2023-06-21 11:48:32
*/
static function CanNotVerificationStatusArr() : array
{
return [
self::STATUS_APPLY_REFUND,
self::STATUS_WAIT_RETURN_GOODS,
self::STATUS_WAIT_RECEIVE_GOODS,
self::STATUS_WAIT_REFUND,
];
}
//售后状态描述
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;
}
function getConfirmTakeTimeAttr($fieldValue, $data)
{
return $fieldValue ? date('Y-m-d H:i:s', $fieldValue) : '';
}
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,delivery_type');
}
public function logs()
{
return $this->hasMany('after_sale_log', 'after_sale_id', 'id')->order('id desc');
}
}
@@ -0,0 +1,67 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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;
}
}
@@ -0,0 +1,62 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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]);
}
}
@@ -0,0 +1,38 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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');
}
}
@@ -0,0 +1,40 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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');
}
}
@@ -0,0 +1,227 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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'];
}
}
@@ -0,0 +1,30 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model;
class Capital_
{
public static function getData()
{
return range('A','Z');
}
}
@@ -0,0 +1,70 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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)
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;
}
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] ?? '未知';
}
}
@@ -0,0 +1,30 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model;
class Crontab_
{
public static $type = [
1=>'定时任务',
//2=>'守护进程'
];
}
@@ -0,0 +1,13 @@
<?php
namespace app\common\model;
use think\Model;
use think\model\concern\SoftDelete;
class Delivery extends Model
{
use SoftDelete;
protected $deleteTime = 'del';
protected $defaultSoftDelete = 0;
}
@@ -0,0 +1,32 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model;
use think\Model;
class DevMessage extends Model{
//需要验证码的短信key
const CODE_KEY = [
'ZCYZ', //注册验证
'ZHMM', //找回密码
'YZMDL', //验证码登录
'BGSJHM', //变更手机号码
'BDSJHM', //绑定手机号码
'ZHZFMM', //找回支付密码
];
}
@@ -0,0 +1,28 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model;
use think\Model;
class DevRegion extends Model
{
}
@@ -0,0 +1,16 @@
<?php
namespace app\common\model;
use think\Model;
use think\model\concern\SoftDelete;
class Distribution extends Model
{
use SoftDelete;
protected $deleteTime = 'delete_time';
public function getDistributionTimeAttr($value)
{
return empty($value) ? '' : date('Y-m-d H:i:s', $value);
}
}
@@ -0,0 +1,11 @@
<?php
namespace app\common\model;
use think\Model;
use think\model\concern\SoftDelete;
class DistributionGoods extends Model
{
use SoftDelete;
protected $deleteTime = 'delete_time';
}
@@ -0,0 +1,63 @@
<?php
namespace app\common\model;
use think\Model;
use think\model\concern\SoftDelete;
class DistributionLevel extends Model
{
use SoftDelete;
protected $deleteTime = 'delete_time';
/**
* 升级条件允许的字段
* singleConsumptionAmount 单笔消费金额
* cumulativeConsumptionAmount 累计消费金额
* cumulativeConsumptionTimes 累计消费次数
* returnedCommission 已结算佣金收入
*/
const UPDATE_CONDITION_FIELDS = ['singleConsumptionAmount', 'cumulativeConsumptionAmount', 'cumulativeConsumptionTimes', 'returnedCommission'];
public static function getValueFiled($key)
{
switch($key) {
case 'singleConsumptionAmount':
case 'cumulativeConsumptionAmount':
case 'returnedCommission':
return 'value_decimal';
case 'cumulativeConsumptionTimes':
return 'value_int';
default:
return 'value_text';
}
}
public function getWeightsDescAttr($value, $data)
{
return $data['is_default'] ? $value . '级(默认等级)' : $value . '级';
}
public function getMembersNumAttr($value, $data)
{
$num = Distribution::where('level_id', $data['id'])->count();
return $num;
}
public static function getLevelName($levelId)
{
$level = self::field('name,weights')->findOrEmpty($levelId)->toArray();
if (empty($level)) {
return '';
}
return $level['name']. '(' . $level['weights'] . ')级';
}
public static function getLevelNameTwo($levelId)
{
$level = self::field('name,weights')->findOrEmpty($levelId)->toArray();
if (empty($level)) {
return '';
}
return $level['name'];
}
}
@@ -0,0 +1,11 @@
<?php
namespace app\common\model;
use think\Model;
use think\model\concern\SoftDelete;
class DistributionLevelUpdate extends Model
{
use SoftDelete;
protected $deleteTime = 'delete_time';
}
@@ -0,0 +1,53 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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] ?? '未知';
}
}
@@ -0,0 +1,80 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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)
{
$time = time();
return self::where('id', $distribution_id)
->update([
'status' => $status,
'settlement_time' => $time,
'update_time' => $time
]);
}
//用户
public function user()
{
return $this->hasOne('user', 'id', 'user_id')
->field('id,sn,nickname,avatar,level,mobile,sex,create_time');
}
}
@@ -0,0 +1,80 @@
<?php
namespace app\common\model;
use think\Model;
class DistributionOrderGoods extends Model
{
//分销订单状态
const STATUS_WAIT_HANDLE = 1;//待返佣
const STATUS_SUCCESS = 2;//已结算
const STATUS_ERROR = 3;//已失效
public function getStatusDescAttr($value)
{
$statusDesc = [
1 => '待返佣',
2 => '已结算',
3 => '已失效',
];
return $statusDesc[$value];
}
public function getDistributionCreateTimeAttr($value)
{
return date('Y-m-d H:i:s', $value);
}
/**
* 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()
]);
}
/**
* @notes 获取指定用户佣金情况
* @param $userId
* @return array
* @author Tab
* @date 2021/9/2 19:14
*/
public static function getEarnings($userId)
{
// 待返佣
$wait = self::where([
'user_id' => $userId,
'status' => 1,
])->sum('money');
// 已入账
$success = self::where([
'user_id' => $userId,
'status' => 2,
])->sum('money');
// 已失效
$fail = self::where([
'user_id' => $userId,
'status' => 3,
])->sum('money');
return [
'wait' => $wait,
'success' => $success,
'fail' => $fail,
];
}
public function getSettlementTimeAttr($value)
{
return empty($value) ? '' : date('Y-m-d H:i:s', $value);
}
}
@@ -0,0 +1,47 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用,保留版权即可
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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 Express extends Model
{
const ZHONGTONG = 'zhongtong';
const SHENTONG = 'shentong';
/**
* @notes 获取快递100
* @param bool $from
* @return mixed|string
* @author cjhao
* @date 2022/9/29 10:46
*/
public static function getkuaidi100code($from = true)
{
$desc = [
// self::ZHONGTONG => 'ztoOpen',
self::SHENTONG => '44',
];
return $desc[$from] ?? '';
}
}
@@ -0,0 +1,33 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用,保留版权即可
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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 FaceSheetSender
* @package app\common\model
*/
class FaceSheetSender extends Model
{
}
@@ -0,0 +1,33 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用,保留版权即可
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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 FaceSheetTemplate
* @package app\common\model
*/
class FaceSheetTemplate extends Model
{
}
+30
View File
@@ -0,0 +1,30 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model;
class File
{
const type_other = 0;//其他
const type_image = 1;//图片
const type_video = 2;//视频
}
@@ -0,0 +1,151 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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();
}
}
@@ -0,0 +1,54 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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;
}
}
@@ -0,0 +1,111 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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(),
]);
}
}
@@ -0,0 +1,62 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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');
}
}
@@ -0,0 +1,30 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model;
use think\Model;
class FreightConfig extends Model
{
protected $name = 'freight_config';
protected $autoWriteTimestamp = true;
}
+51
View File
@@ -0,0 +1,51 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model;
use think\Model;
class Goods extends Model
{
const STATUS_RECYCLE = -1; // 回收站
const STATUS_STORAGE = 0; // 下架(仓库中)
const STATUS_SELL = 1; // 上架 (销售中)
/**
* @notes 获取商品状态
* @param $state
* @return string|string[]
* @author 段誉
* @date 2022/1/12 10:384
*/
public static function getStatusDesc($state)
{
$data = [
self::STATUS_SELL => '上架',
self::STATUS_STORAGE => '下架',
self::STATUS_RECYCLE => '回收站',
];
if ($state === true) {
return $data;
}
return $data[$state] ?? '';
}
}
@@ -0,0 +1,13 @@
<?php
namespace app\common\model;
use think\Model;
use think\model\concern\SoftDelete;
class GoodsBrand extends Model
{
use SoftDelete;
protected $defaultSoftDelete = 0;
protected $deleteTime = 'del';
}
@@ -0,0 +1,29 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model;
use think\Model;
class GoodsItem extends Model
{
}
@@ -0,0 +1,34 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model;
use think\Model;
/**
* 直播商品
* Class LiveGoods
* @package app\common\model
*/
class LiveGoods extends Model
{
}
@@ -0,0 +1,84 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model;
use app\admin\model\Coupon;
use think\Model;
class Luckdraw extends Model
{
//计费方式
const PRIZE_INTEGRAL = 1; //积分
const PRIZE_NOT_WIN = 2; // 谢谢惠顾
const PRIZE_COUPON = 3; //优惠券
const PRIZE_BALANCE = 4;//按件计费
public function getPrizeNameAttr($value, $data)
{
return self::getPrizeNameDesc($data['prize_type'], $data['number']);
}
public static function getPrizeNameDesc($type, $number)
{
switch ($type) {
case self::PRIZE_INTEGRAL:
$str = $number.'积分';
break;
case self::PRIZE_COUPON:
$coupon = Coupon::where('id', $number)->value('name');
$str = $coupon;
break;
case self::PRIZE_BALANCE:
$str = $number.'元';
break;
default:
$str = '谢谢惠顾';
}
return $str;
}
/**
* @notes 获取奖品描述
* @param $type
* @return string|string[]
* @author 段誉
* @date 2022/2/15 10:24
*/
public static function getPrizeDesc($type)
{
$data = [
self::PRIZE_INTEGRAL => '积分',
self::PRIZE_NOT_WIN => '谢谢惠顾',
self::PRIZE_COUPON => '优惠券',
self::PRIZE_BALANCE => '余额',
];
if ($type === true) {
return $data;
}
return $data[$type] ?? '';
}
}
@@ -0,0 +1,56 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model;
use app\api\model\Coupon;
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);
}
public function getSendDescAttr($value, $data)
{
return $data['is_send'] ? '已发放' : '未发放';
}
public function getPrizeNameAttr($value, $data)
{
return Luckdraw::getPrizeNameDesc($data['prize_type'], $data['number']);
}
}
+267
View File
@@ -0,0 +1,267 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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 index_live_room = 14;
/*
* 个人中心菜单
*/
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;
const centre_writeoff_order = 20;
const centre_invitation_poster = 21;
/**
* Notes: 菜单内容
* @param bool $scene 场景:1-首页导航;2-个人中心
* @param bool $from 菜单来源:获取具体的某个菜单
* @return array
* name => '菜单名称'
* link => 调整链接
* is_tab => 是否的tab页
* link_type => 菜单类型:1-跳转;2-web-view3-按钮(微信小程序可调用客服)
* menu_type => 菜单内容类型:1-正常内容;2-分销菜单
*
*/
public static function getMenuContent($scene = true,$from = true){
//首页菜单
$config1 = [
self::index_seckill => [
'name' => '限时秒杀',
'link' => '/bundle/pages/goods_seckill/goods_seckill',
'is_tab' => 0,
'link_type' => 1,
'menu_type' => 1,
],
self::index_team_activity => [
'name' => '拼团活动',
'link' => '/bundle/pages/goods_combination/goods_combination',
'is_tab' => 0,
'link_type' => 1,
'menu_type' => 1,
],
self::index_hot_sell => [
'name' => '热销榜单',
'link' => '/bundle/pages/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' => '/bundle/pages/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' => '/bundle/pages/luckly_wheel/luckly_wheel',
'is_tab' => 0,
'link_type' => 1,
'menu_type' => 1,
],
self::index_bargain => [
'name' => '砍价活动',
'link' => '/bundle/pages/bargain/bargain',
'is_tab' => 0,
'link_type' => 1,
'menu_type' => 1,
],
self::index_live_room => [
'name' => '商城直播',
'link' => '/bundle/pages/live_broadcast/live_broadcast',
'is_tab' => 0,
'link_type' => 1,
'menu_type' => 1,
],
];
//个人中心菜单
$config2 = [
self::centre_my_wallet => [
'name' => '我的钱包',
'link' => '/bundle/pages/user_wallet/user_wallet',
'is_tab' => 0,
'link_type' => 1,
'menu_type' => 1,
],
self::centre_generalize => [
'name' => '分销推广',
'link' => '/bundle/pages/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' => '/bundle/pages/contact_offical/contact_offical',
'is_tab' => 0,
'link_type' => 1,
'menu_type' => 1,
],
self::centre_team_activity => [
'name' => '我的拼团',
'link' => '/bundle/pages/user_group/user_group',
'is_tab' => 0,
'link_type' => 1,
'menu_type' => 1,
],
self::centre_bargain => [
'name' => '砍价记录',
'link' => '/bundle/pages/bargain_code/bargain_code',
'is_tab' => 0,
'link_type' => 1,
'menu_type' => 1,
],
self::centre_writeoff_order => [
'name' => '核销订单',
'link' => '/bundle/pages/writeoff_order/writeoff_order',
'is_tab' => 0,
'link_type' => 1,
'menu_type' => 1,
],
self::centre_invitation_poster => [
'name' => '邀请海报',
'link' => '/bundle/pages/invite_fans/invite_fans',
'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] ?? [];
}
}
@@ -0,0 +1,49 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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;
}
}
@@ -0,0 +1,269 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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);
}
}
+246
View File
@@ -0,0 +1,246 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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 NOT_WRITTEN_OFF = 0;//待核销
const WRITTEN_OFF = 1;//已核销
//订单状态
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 => '上门自提'
];
if ($type === true){
return $desc;
}
return $desc[$type] ?? '未知';
}
/**
* @notes 核销状态
* @param $type
* @return string|string[]
* @author ljj
* @date 2021/8/16 7:31 下午
*/
public static function getVerificationStatus($type)
{
$desc = [
self::NOT_WRITTEN_OFF => '待核销',
self::WRITTEN_OFF => '已核销',
];
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');
}
/**
* @notes 自提门店
* @return \think\model\relation\HasOne
* @author lbzy
* @datetime 2023-10-08 16:48:44
*/
function selffetchShop()
{
return $this->hasOne(SelffetchShop::class, 'id', 'selffetch_shop_id');
}
//收货地址
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'];
}
/**
* @notes 核销状态
* @param $value
* @param $data
* @return string|string[]
* @author ljj
* @date 2021/8/16 7:32 下午
*/
public function getVerificationStatusTextAttr($value, $data)
{
return self::getVerificationStatus($data['verification_status']);
}
}
@@ -0,0 +1,62 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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'];
}
//退款状态
public static function getRefundStatus($type)
{
$data = [
self::REFUND_STATUS_NO => '未申请退款',
self::REFUND_STATUS_APPLY => '申请退款',
self::REFUND_STATUS_WAIT => '等待退款',
self::REFUND_STATUS_SUCCESS => '退款成功',
];
if ($type === true) {
return $data;
}
return $data[$type] ?? '未知';
}
}
@@ -0,0 +1,91 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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 USER_VERIFICATION = 106;//提货核销
const SHOP_CANCEL_ORDER = 201;//商家取消订单
const SHOP_DEL_ORDER = 202;//商家删除订单
const SHOP_DELIVERY_ORDER = 203;//商家发货
const SHOP_CONFIRM_ORDER = 204;//商家确认收货
const SHOP_VERIFICATION = 205;//商家提货核销
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::USER_VERIFICATION => '会员提货核销',
self::SHOP_CANCEL_ORDER => '商家取消订单',
self::SHOP_DEL_ORDER => '商家删除订单',
self::SHOP_DELIVERY_ORDER => '商家发货',
self::SHOP_CONFIRM_ORDER => '商家确认收货',
self::SHOP_VERIFICATION => '商家提货核销',
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
View File
@@ -0,0 +1,106 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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;
}
}
@@ -0,0 +1,11 @@
<?php
namespace app\common\model;
use think\Model;
class RechargeOrder extends Model
{
protected $name = 'recharge_order';
}
@@ -0,0 +1,102 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用,保留版权即可
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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 SelffetchShop extends Model
{
//门店状态
const CLOSE = 0;//停用
const OPEN = 1;//启用
/**
* @notes 门店状态
* @param bool $status
* @return string|string[]
* @author ljj
* @date 2021/8/14 5:22 下午
*/
public static function getShopStatus($status = true)
{
$desc = [
self::CLOSE => '停用',
self::OPEN => '启用',
];
if ($status === true) {
return $desc;
}
return $desc[$status] ?? '未知';
}
/**
* @notes 门店状态获取器
* @param $value
* @param $data
* @return string|string[]
* @author ljj
* @date 2021/8/14 5:24 下午
*/
public function getStatusDescAttr($value,$data)
{
return self::getShopStatus($data['status']);
}
/**
* @notes 创建时间获取器
* @param $value
* @param $data
* @return false|string
* @author ljj
* @date 2021/8/14 5:28 下午
*/
public function getCreateTimeAttr($value,$data)
{
return date('Y-m-d H:i:s',$value);
}
/**
* @notes 门店地址获取器
* @param $value
* @param $data
* @return string
* @author ljj
* @date 2021/8/14 5:29 下午
*/
public function getShopAddressAttr($value,$data)
{
return implode('',DevRegion::where('id', 'in', $data['province'].','.$data['city'].','.$data['district'])->column('name')).$data['address'];
}
/**
* @notes 图片获取器
* @param $value
* @param $data
* @return string
* @author ljj
* @date 2021/8/16 11:39 上午
*/
public function getImageAttr($value,$data)
{
return empty($value) ? '' : UrlServer::getFileUrl($value);
}
}
@@ -0,0 +1,75 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用,保留版权即可
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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 SelffetchVerifier extends Model
{
//核销员状态
const CLOSE = 0;//停用
const OPEN = 1;//启用
/**
* @notes 核销员状态
* @param bool $status
* @return string|string[]
* @author ljj
* @date 2021/8/16 3:27 下午
*/
public static function getVerifierStatus($status = true)
{
$desc = [
self::CLOSE => '停用',
self::OPEN => '启用',
];
if ($status === true) {
return $desc;
}
return $desc[$status] ?? '未知';
}
/**
* @notes 核销员状态获取器
* @param $value
* @param $data
* @return string|string[]
* @author ljj
* @date 2021/8/16 3:35 下午
*/
public function getStatusDescAttr($value,$data)
{
return self::getVerifierStatus($data['status']);
}
/**
* @notes 创建时间获取器
* @param $value
* @param $data
* @return false|string
* @author ljj
* @date 2021/8/16 3:35 下午
*/
public function getCreateTimeAttr($value,$data)
{
return date('Y-m-d H:i:s',$value);
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model;
use think\Model;
class Shop extends Model
{
}
@@ -0,0 +1,47 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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;
}
}
@@ -0,0 +1,69 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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;
}
}
@@ -0,0 +1,24 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model;
use think\Model;
class SmsConfig extends Model{
}
@@ -0,0 +1,56 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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;
}
}
+50
View File
@@ -0,0 +1,50 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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] ?? '';
}
}
@@ -0,0 +1,41 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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');
}
}
@@ -0,0 +1,39 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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');
}
}
@@ -0,0 +1,44 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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');
}
}
@@ -0,0 +1,33 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model;
use think\Model;
/**
* 拼团商品规格模型
* Class TeamGoodsItem
* @package app\common\model
*/
class TeamGoodsItem extends Model
{
}
+137
View File
@@ -0,0 +1,137 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model;
use app\common\server\UrlServer;
use think\Model;
class User extends Model
{
/**
* @notes 统一处理用户nickname
* @param $nickname
* @return mixed|string
* @author lbzy
* @datetime 2023-10-08 18:40:35
*/
function getNicknameAttr($nickname)
{
if (request()->module() == 'admin' && request()->isAjax()) {
$nickname = htmlspecialchars($nickname);
}
return $nickname;
}
//头像
public function getAvatarAttr($value, $data)
{
if ($value) {
return UrlServer::getFileUrl($value);
}
return $value;
}
public function getUserMoneyAttr($value)
{
return $value ? $value : 0;
}
public function getEarningsAttr($value)
{
return $value ? $value : 0;
}
public function getBaseAvatarAttr($value, $data)
{
return $data['avatar'];
}
public function getBirthdayAttr($value)
{
return empty($value) ? '' : date('Y-m-d H:i:s', $value);
}
public function getLoginTimeAttr($value)
{
return empty($value) ? '' : date('Y-m-d H:i:s', $value);
}
//加入时间
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');
}
public static function getUserInfo($userId)
{
$user = self::field('id,sn,nickname,avatar')->findOrEmpty($userId)->toArray();
if (empty($user)) {
return '系统';
}
$user['avatar'] = empty($user['avatar']) ? '' : UrlServer::getFileUrl($user['avatar']);
return $user;
}
public function getDistributionAttr($value)
{
$distribution = Distribution::where('user_id', $value)->findOrEmpty()->toArray();
if (!empty($distribution) && $distribution['is_distribution'] == 1) {
return '是';
}
return '否';
}
public function searchDistributionAttr($query, $value, $params)
{
// 非分销会员
if (isset($params['is_distribution']) && $params['is_distribution'] != 'all' && $params['is_distribution'] == 0) {
$ids = Distribution::where('is_distribution', 1)->column('user_id');
if (!empty($ids)) {
$query->where('id', 'not in', $ids);
}
}
// 分销会员
if (isset($params['is_distribution']) && $params['is_distribution'] != 'all' && $params['is_distribution'] == 1) {
$ids = Distribution::where('is_distribution', 1)->column('user_id');
if (!empty($ids)) {
$query->where('id', 'in', $ids);
}
}
}
}
@@ -0,0 +1,8 @@
<?php
namespace app\common\model;
class UserAuth extends \think\Model
{
}
@@ -0,0 +1,61 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model;
use think\Model;
class UserLevel extends Model
{
/**
* @notes 获取等级选项列表
* @return array
* @author lbzy
* @datetime 2023-09-11 18:36:54
*/
static function getSelectListDefault()
{
return static::where('del', 0)->field('id,name')->select()->toArray();
}
/**
* @notes 获取等级选项列表
* @return array
* @author lbzy
* @datetime 2023-09-11 18:36:54
*/
static function getSelectList()
{
$result = [
[
'id' => 0,
'name' => '无等级',
]
];
$lists = static::where('del', 0)->field('id,name')->select()->toArray();
foreach ($lists as $level) {
$result[] = $level;
}
return $result;
}
}
@@ -0,0 +1,83 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
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' =>'人'
],
];
}
@@ -0,0 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 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系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\model;
use think\Model;
class Verification extends Model
{
//操作人类型
const TYPE_SYSTEM = 0;//系统
const TYPE_ADMIN = 1;//管理员
const TYPE_USER = 2;//会员
//操作人类型
public static function getOrderStatus($status = true)
{
$desc = [
self::TYPE_SYSTEM => '系统',
self::TYPE_ADMIN => '管理员',
self::TYPE_USER => '会员',
];
if ($status === true) {
return $desc;
}
return $desc[$status] ?? '未知';
}
}

Some files were not shown because too many files have changed in this diff Show More