1.提交缺失的东西

This commit is contained in:
2025-05-16 16:15:42 +08:00
parent 40e2dff66a
commit e975b4da98
7 changed files with 2676 additions and 0 deletions

View File

@ -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\account\AccountLog;
use app\common\model\OrderGoods;
use app\common\service\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;
}
}

246
app/common/model/Order.php Normal file
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\facade\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']);
}
}

View File

@ -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\distribution;
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');
}
}