init
- 框架初始化 - 安装插件 - 修复PHP8.4报错
This commit is contained in:
407
application/admin/model/shopro/activity/Activity.php
Normal file
407
application/admin/model/shopro/activity/Activity.php
Normal file
@@ -0,0 +1,407 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\activity;
|
||||
|
||||
use app\admin\model\shopro\Common;
|
||||
use traits\model\SoftDelete;
|
||||
use app\admin\model\shopro\goods\Goods;
|
||||
use addons\shopro\facade\Activity as ActivityFacade;
|
||||
use app\admin\model\shopro\activity\SkuPrice as ActivitySkuPriceModel;
|
||||
|
||||
class Activity extends Common
|
||||
{
|
||||
use SoftDelete;
|
||||
|
||||
protected $name = 'shopro_activity';
|
||||
|
||||
protected $deleteTime = 'deletetime';
|
||||
|
||||
protected $type = [
|
||||
'rules' => 'json',
|
||||
'prehead_time' => 'timestamp',
|
||||
'start_time' => 'timestamp',
|
||||
'end_time' => 'timestamp',
|
||||
];
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'status',
|
||||
'status_text',
|
||||
'type_text',
|
||||
// 'end_time_unix' // 不需要了
|
||||
];
|
||||
|
||||
|
||||
public function classifies()
|
||||
{
|
||||
return [
|
||||
'activity' => [
|
||||
'groupon' => '拼团',
|
||||
'groupon_ladder' => '阶梯拼团',
|
||||
// 'groupon_lucky' => '幸运拼团',
|
||||
'seckill' => '秒杀',
|
||||
],
|
||||
'promo' => [
|
||||
'full_reduce' => '满减',
|
||||
'full_discount' => '满折',
|
||||
'full_gift' => '满赠',
|
||||
'free_shipping' => '满邮',
|
||||
],
|
||||
'app' => [
|
||||
'signin' => '签到'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function typeList()
|
||||
{
|
||||
return [
|
||||
'groupon' => '拼团',
|
||||
'groupon_ladder' => '阶梯拼团',
|
||||
// 'groupon_lucky' => '幸运拼团',
|
||||
'seckill' => '秒杀',
|
||||
'full_reduce' => '满减',
|
||||
'full_discount' => '满折',
|
||||
'full_gift' => '满赠',
|
||||
'free_shipping' => '满邮',
|
||||
'signin' => '签到',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取活动的互斥活动
|
||||
*
|
||||
* @param string $current_activity_type
|
||||
* @return array
|
||||
*/
|
||||
public function getMutexActivityTypes($current_activity_type)
|
||||
{
|
||||
$activityTypes = [];
|
||||
switch ($current_activity_type) {
|
||||
case 'groupon':
|
||||
$activityTypes = ['groupon'];
|
||||
break;
|
||||
case 'groupon_ladder':
|
||||
$activityTypes = ['groupon_ladder'];
|
||||
break;
|
||||
case 'groupon_lucky':
|
||||
$activityTypes = ['groupon_lucky'];
|
||||
break;
|
||||
case 'seckill':
|
||||
$activityTypes = ['seckill'];
|
||||
break;
|
||||
case 'full_reduce':
|
||||
$activityTypes = ['full_reduce', 'full_discount'];
|
||||
break;
|
||||
case 'full_discount':
|
||||
$activityTypes = ['full_reduce', 'full_discount'];
|
||||
break;
|
||||
case 'free_shipping':
|
||||
$activityTypes = ['free_shipping'];
|
||||
break;
|
||||
case 'full_gift':
|
||||
$activityTypes = ['full_gift'];
|
||||
break;
|
||||
case 'signin':
|
||||
$activityTypes = ['signin'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $activityTypes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据类型获取 classify
|
||||
*
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
public function getClassify($type)
|
||||
{
|
||||
$classifys = $this->classifies();
|
||||
$activitys = array_keys($classifys['activity']);
|
||||
$promos = array_keys($classifys['promo']);
|
||||
$apps = array_keys($classifys['app']);
|
||||
|
||||
$classify = null;
|
||||
if (in_array($type, $activitys)) {
|
||||
$classify = 'activity';
|
||||
} else if (in_array($type, $promos)) {
|
||||
$classify = 'promo';
|
||||
} else if (in_array($type, $apps)) {
|
||||
$classify = 'app';
|
||||
}
|
||||
|
||||
return $classify;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* status 组合 (在thinkphp5 where Closure 中,不能直接使用 scope,特殊场景下用来代替下面的 scopeNostart scopePrehead 等)
|
||||
*
|
||||
* @param [type] $query
|
||||
* @param [type] $status
|
||||
* @return void
|
||||
*/
|
||||
public function scopeStatusComb($query, $status)
|
||||
{
|
||||
return $query->where(function ($query) use ($status) {
|
||||
foreach ($status as $st) {
|
||||
$query->whereOr(function ($query) use ($st) {
|
||||
switch($st) {
|
||||
case 'nostart':
|
||||
$query->where('start_time', '>', time());
|
||||
break;
|
||||
case 'prehead':
|
||||
$query->where('prehead_time', '<=', time())->where('start_time', '>', time());
|
||||
break;
|
||||
case 'ing':
|
||||
$query->where('start_time', '<=', time())->where('end_time', '>=', time());
|
||||
break;
|
||||
case 'show':
|
||||
$query->where('prehead_time', '<=', time())->where('end_time', '>=', time());
|
||||
break;
|
||||
case 'ended':
|
||||
$query->where('end_time', '<', time());
|
||||
break;
|
||||
default:
|
||||
error_stop('status 状态错误');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 未开始的活动
|
||||
*
|
||||
* @param think\query\Query $query
|
||||
* @return void
|
||||
*/
|
||||
public function scopeNostart($query)
|
||||
{
|
||||
return $query->where('start_time', '>', time());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 预售的活动
|
||||
*
|
||||
* @param think\query\Query $query
|
||||
* @return void
|
||||
*/
|
||||
public function scopePrehead($query)
|
||||
{
|
||||
return $query->where('prehead_time', '<=', time())->where('start_time', '>', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* 进行中的活动
|
||||
*
|
||||
* @param think\query\Query $query
|
||||
* @return void
|
||||
*/
|
||||
public function scopeIng($query)
|
||||
{
|
||||
return $query->where('start_time', '<=', time())->where('end_time', '>=', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* 已经开始预售,并且没有结束的活动
|
||||
*
|
||||
* @param think\query\Query $query
|
||||
* @return void
|
||||
*/
|
||||
public function scopeShow($query)
|
||||
{
|
||||
return $query->where('prehead_time', '<=', time())->where('end_time', '>=', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* 已经结束的活动
|
||||
*
|
||||
* @param think\query\Query $query
|
||||
* @return void
|
||||
*/
|
||||
public function scopeEnded($query)
|
||||
{
|
||||
return $query->where('end_time', '<', time());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 修改器 classify
|
||||
*
|
||||
* @param string $value
|
||||
* @param array $data
|
||||
* @return integer|null
|
||||
*/
|
||||
public function setClassifyAttr($value, $data)
|
||||
{
|
||||
$classify = $value ?: ($data['classify'] ?? null);
|
||||
if (!$classify) {
|
||||
$type = $data['type'] ?? null; // 活动类型
|
||||
|
||||
$classify = $this->getClassify($type);
|
||||
}
|
||||
|
||||
return $classify;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改器 预热时间
|
||||
*
|
||||
* @param string $value
|
||||
* @param array $data
|
||||
* @return integer|null
|
||||
*/
|
||||
public function setPreheadTimeAttr($value, $data)
|
||||
{
|
||||
// promo 类型 prehead_time 永远等于 start_time
|
||||
$value = (isset($data['classify']) && $data['classify'] == 'promo') ? $data['start_time'] : ($value ?: $data['start_time']);
|
||||
return $this->attrFormatUnix($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改器 开始时间
|
||||
*
|
||||
* @param string $value
|
||||
* @return integer|null
|
||||
*/
|
||||
public function setStartTimeAttr($value)
|
||||
{
|
||||
return $this->attrFormatUnix($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改器 结束时间
|
||||
*
|
||||
* @param string $value
|
||||
* @return integer|null
|
||||
*/
|
||||
public function setEndTimeAttr($value)
|
||||
{
|
||||
return $this->attrFormatUnix($value);
|
||||
}
|
||||
|
||||
|
||||
public function getStatusAttr($value, $data)
|
||||
{
|
||||
return $this->getStatusCode($data['prehead_time'], $data['start_time'], $data['end_time']);
|
||||
}
|
||||
|
||||
|
||||
public function getStatusTextAttr($value, $data)
|
||||
{
|
||||
return $this->getStatusText($this->status);
|
||||
}
|
||||
|
||||
|
||||
public function getGoodsListAttr($value, $data)
|
||||
{
|
||||
if ($data['goods_ids']) {
|
||||
|
||||
$goods = Goods::field('id,title,price,sales,image,status')->whereIn('id', $data['goods_ids'])->select();
|
||||
$goods = collection($goods)->toArray(); // 全部转数组
|
||||
|
||||
$goodsIds = array_column($goods, 'id');
|
||||
$activitySkuPrices = ActivitySkuPriceModel::where('activity_id', $data['id'])->whereIn('goods_id', $goodsIds)->order('id', 'asc')->select();
|
||||
$activitySkuPrices = collection($activitySkuPrices)->toArray();
|
||||
|
||||
// 后台编辑活动时,防止不编辑规格无法提交问题
|
||||
foreach ($goods as &$gd) {
|
||||
// 处理 $gd['activity_sku_prices']
|
||||
$gd['activity_sku_prices'] = [];
|
||||
foreach ($activitySkuPrices as $skuPrice) {
|
||||
if ($skuPrice['goods_id'] == $gd['id']) {
|
||||
$gd['activity_sku_prices'][] = $skuPrice;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理活动规格,数据
|
||||
foreach ($gd['activity_sku_prices'] as $key => $skuPrice) {
|
||||
$skuPrice = ActivityFacade::showSkuPrice($data['type'], $skuPrice);
|
||||
$gd['activity_sku_prices'][$key] = $skuPrice;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $goods ?? [];
|
||||
}
|
||||
|
||||
|
||||
public function getRulesAttr($value, $data)
|
||||
{
|
||||
$rules = $data['rules'] ? json_decode($data['rules'], true) : [];
|
||||
$type = $data['type'];
|
||||
|
||||
// 获取各个活动规则相关的特殊数据
|
||||
$rules = ActivityFacade::rulesInfo($type, $rules);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过时间判断活动状态
|
||||
*
|
||||
* @param integer $prehead_time 预热时间
|
||||
* @param integer $start_time 开始时间
|
||||
* @param integer $end_time 结束时间
|
||||
* @return string
|
||||
*/
|
||||
public static function getStatusCode($prehead_time, $start_time, $end_time)
|
||||
{
|
||||
// 转为时间戳,(从 redis 中取出来的是 时间格式)
|
||||
if (($prehead_time && $prehead_time > time()) || (!$prehead_time && $start_time > time())) {
|
||||
$status = 'nostart'; // 未开始
|
||||
} else if ($prehead_time && $prehead_time < time() && $start_time > time()) {
|
||||
$status = 'prehead'; // 预热
|
||||
} else if ($start_time < time() && $end_time > time()) {
|
||||
$status = 'ing';
|
||||
} else if ($end_time < time()) {
|
||||
$status = 'ended';
|
||||
}
|
||||
|
||||
return $status ?? 'ended';
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断活动状态中文
|
||||
*
|
||||
* @param string $status 活动状态
|
||||
* @return string
|
||||
*/
|
||||
public static function getStatusText($status)
|
||||
{
|
||||
if ($status == 'nostart') {
|
||||
$status_text = '未开始';
|
||||
} elseif ($status == 'prehead') {
|
||||
$status_text = '预热中';
|
||||
} elseif ($status == 'ing') {
|
||||
$status_text = '进行中';
|
||||
} elseif ($status == 'ended') {
|
||||
$status_text = '已结束';
|
||||
}
|
||||
|
||||
return $status_text ?? '已结束';
|
||||
}
|
||||
|
||||
|
||||
public function getEndTimeUnixAttr($value, $data)
|
||||
{
|
||||
return isset($data['end_time']) ? $this->getData('end_time') : 0;
|
||||
}
|
||||
|
||||
|
||||
public function activitySkuPrices()
|
||||
{
|
||||
return $this->hasMany(SkuPrice::class, 'activity_id');
|
||||
}
|
||||
}
|
||||
73
application/admin/model/shopro/activity/GiftLog.php
Normal file
73
application/admin/model/shopro/activity/GiftLog.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\activity;
|
||||
|
||||
use app\admin\model\shopro\Common;
|
||||
|
||||
class GiftLog extends Common
|
||||
{
|
||||
protected $name = 'shopro_activity_gift_log';
|
||||
|
||||
protected $type = [
|
||||
'rules' => 'json',
|
||||
'errors' => 'json'
|
||||
];
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'type_text',
|
||||
'status_text'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 默认状态列表
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function typeList()
|
||||
{
|
||||
return [
|
||||
'coupon' => '优惠券',
|
||||
'score' => '积分',
|
||||
'money' => '余额',
|
||||
'goods' => '商品',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 默认状态列表
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function statusList()
|
||||
{
|
||||
return [
|
||||
'waiting' => '等待赠送',
|
||||
'finish' => '赠送完成',
|
||||
'fail' => '赠送失败',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function scopeWaiting($query)
|
||||
{
|
||||
return $query->where('status', 'waiting');
|
||||
}
|
||||
|
||||
public function scopeOpered($query)
|
||||
{
|
||||
return $query->whereIn('status', ['finish', 'fail']);
|
||||
}
|
||||
|
||||
public function scopeFinish($query)
|
||||
{
|
||||
return $query->where('status', 'finish');
|
||||
}
|
||||
|
||||
public function scopeFail($query)
|
||||
{
|
||||
return $query->where('status', 'fail');
|
||||
}
|
||||
}
|
||||
98
application/admin/model/shopro/activity/Groupon.php
Normal file
98
application/admin/model/shopro/activity/Groupon.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\activity;
|
||||
|
||||
use app\admin\model\shopro\Common;
|
||||
use app\admin\model\shopro\user\User;
|
||||
use app\admin\model\shopro\goods\Goods;
|
||||
use app\admin\model\shopro\order\OrderItem;
|
||||
|
||||
class Groupon extends Common
|
||||
{
|
||||
protected $name = 'shopro_activity_groupon';
|
||||
|
||||
protected $type = [
|
||||
'finish_time' => 'timestamp',
|
||||
'expire_time' => 'timestamp'
|
||||
];
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'status_text',
|
||||
];
|
||||
|
||||
|
||||
public function statusList()
|
||||
{
|
||||
return [
|
||||
'invalid' => '拼团失败',
|
||||
'ing' => '进行中',
|
||||
'finish' => '已成团',
|
||||
'finish_fictitious' => '虚拟成团',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询正在进行中的团
|
||||
*/
|
||||
public function scopeIng($query)
|
||||
{
|
||||
return $query->where('status', 'ing');
|
||||
}
|
||||
|
||||
|
||||
public function getStatusTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ?: ($data['status'] ?? '');
|
||||
|
||||
$list = $this->statusList();
|
||||
$value = ($value == 'finish_fictitious' && strpos(request()->url(), 'addons/shopro') !== false) ? 'finish' : $value;
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
|
||||
public function getExpireTimeUnixAttr($value, $data)
|
||||
{
|
||||
return isset($data['expire_time']) ? $this->getData('expire_time') : 0;
|
||||
}
|
||||
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
|
||||
public function goods()
|
||||
{
|
||||
return $this->belongsTo(Goods::class, 'goods_id', 'id');
|
||||
}
|
||||
|
||||
public function activity()
|
||||
{
|
||||
return $this->belongsTo(Activity::class, 'activity_id', 'id');
|
||||
}
|
||||
|
||||
public function grouponLogs()
|
||||
{
|
||||
return $this->hasMany(GrouponLog::class, 'groupon_id', 'id');
|
||||
}
|
||||
|
||||
|
||||
public function leader()
|
||||
{
|
||||
return $this->hasOne(GrouponLog::class, 'groupon_id', 'id')->where('is_leader', 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 前端拼团详情用
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function my()
|
||||
{
|
||||
$user = auth_user();
|
||||
return $this->hasOne(GrouponLog::class, 'groupon_id', 'id')->where('user_id', ($user ? $user->id : 0))->where('is_fictitious', 0);
|
||||
}
|
||||
}
|
||||
43
application/admin/model/shopro/activity/GrouponLog.php
Normal file
43
application/admin/model/shopro/activity/GrouponLog.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\activity;
|
||||
|
||||
use app\admin\model\shopro\Common;
|
||||
use app\admin\model\shopro\user\User;
|
||||
use app\admin\model\shopro\goods\Goods;
|
||||
use app\admin\model\shopro\order\Order;
|
||||
use app\admin\model\shopro\order\OrderItem;
|
||||
|
||||
class GrouponLog extends Common
|
||||
{
|
||||
protected $name = 'shopro_activity_groupon_log';
|
||||
|
||||
public function getNicknameAttr($value, $data)
|
||||
{
|
||||
$value = $value ?: ($data['nickname'] ?? '');
|
||||
return $value ? string_hide($value, 2) : $value;
|
||||
}
|
||||
|
||||
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(Order::class, 'order_id');
|
||||
}
|
||||
|
||||
|
||||
public function groupon()
|
||||
{
|
||||
return $this->belongsTo(Groupon::class, 'groupon_id');
|
||||
}
|
||||
|
||||
public function goods()
|
||||
{
|
||||
return $this->belongsTo(Goods::class, 'goods_id');
|
||||
}
|
||||
|
||||
|
||||
public function orderItem()
|
||||
{
|
||||
return $this->hasOne(OrderItem::class, 'order_id', 'order_id');
|
||||
}
|
||||
}
|
||||
93
application/admin/model/shopro/activity/Order.php
Normal file
93
application/admin/model/shopro/activity/Order.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\activity;
|
||||
|
||||
use app\admin\model\shopro\Common;
|
||||
use addons\shopro\facade\Activity as ActivityFacade;
|
||||
|
||||
class Order extends Common
|
||||
{
|
||||
|
||||
protected $name = 'shopro_activity_order';
|
||||
|
||||
protected $type = [
|
||||
'ext' => 'json',
|
||||
];
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'status_text',
|
||||
'activity_type_text',
|
||||
'discount_text'
|
||||
];
|
||||
|
||||
const STATUS_UNPAID = 'unpaid';
|
||||
const STATUS_PAID = 'paid';
|
||||
|
||||
public function statusList()
|
||||
{
|
||||
return [
|
||||
'unpaid' => '未支付',
|
||||
'paid' => '已支付',
|
||||
];
|
||||
}
|
||||
|
||||
// 未支付
|
||||
public function scopeUnpaid($query)
|
||||
{
|
||||
return $query->where('status', self::STATUS_UNPAID);
|
||||
}
|
||||
|
||||
// 已支付
|
||||
public function scopePaid($query)
|
||||
{
|
||||
return $query->whereIn('status', [self::STATUS_PAID]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getActivityTypeTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ?: ($data['activity_type'] ?? null);
|
||||
$ext = $this->ext;
|
||||
|
||||
$list = (new Activity)->typeList();
|
||||
$text = isset($list[$value]) ? $list[$value] : '';
|
||||
|
||||
if (in_array($value, ['groupon', 'groupon_ladder'])) {
|
||||
if (in_array($data['status'], [self::STATUS_PAID]) && (!isset($ext['groupon_id']) || !$ext['groupon_id'])) {
|
||||
// 已支付,并且没有团 id,就是单独购买
|
||||
$text .= '-单独购买';
|
||||
}
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
|
||||
public function getDiscountTextAttr($value, $data)
|
||||
{
|
||||
$ext = $this->ext;
|
||||
$discount_text = '';
|
||||
if ($ext && isset($ext['rules']) && $ext['rules']) {
|
||||
$tags = ActivityFacade::formatRuleTags([
|
||||
'type' => $ext['rules']['rule_type'],
|
||||
'discounts' => [$ext['rules']['discount_rule']]
|
||||
], $data['activity_type']);
|
||||
|
||||
$discount_text = $tags[0] ?? '';
|
||||
}
|
||||
|
||||
return $discount_text ?: $this->activity_type_text;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getGoodsIdsAttr($value, $data)
|
||||
{
|
||||
return $this->attrFormatComma($value, $data, 'goods_ids', true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
21
application/admin/model/shopro/activity/Signin.php
Normal file
21
application/admin/model/shopro/activity/Signin.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\activity;
|
||||
|
||||
use app\admin\model\shopro\Common;
|
||||
|
||||
class Signin extends Common
|
||||
{
|
||||
|
||||
protected $name = 'shopro_activity_signin';
|
||||
|
||||
protected $type = [
|
||||
'rules' => 'json'
|
||||
];
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
|
||||
];
|
||||
|
||||
}
|
||||
128
application/admin/model/shopro/activity/SkuPrice.php
Normal file
128
application/admin/model/shopro/activity/SkuPrice.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\activity;
|
||||
|
||||
use app\admin\model\shopro\Common;
|
||||
|
||||
class SkuPrice extends Common
|
||||
{
|
||||
protected $name = 'shopro_activity_sku_price';
|
||||
|
||||
protected $type = [
|
||||
'ext' => 'json',
|
||||
];
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'status_text',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 普通拼团,团长价
|
||||
*
|
||||
* @param string $value
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
public function getLeaderPriceAttr($value, $data)
|
||||
{
|
||||
$ext = $data['ext'];
|
||||
$is_leader_discount = $ext['is_leader_discount'] ?? 0;
|
||||
$leader_price = $ext['leader_price'] ?? 0;
|
||||
|
||||
$leader_price = $is_leader_discount ? $leader_price : $data['price'];
|
||||
return $leader_price;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function currentLadder($data, $level, $is_leader = false)
|
||||
{
|
||||
$ext = $data['ext'];
|
||||
$is_leader_discount = $ext['is_leader_discount'] ?? 0;
|
||||
$ladders = $ext['ladders'] ?? [];
|
||||
$ladders = array_column($ladders, null, 'ladder_level');
|
||||
$currentLadder = $ladders[$level] ?? []; // 当前阶梯的 价格数据
|
||||
|
||||
$key = ($is_leader && $is_leader_discount) ? 'leader_ladder_price' : 'ladder_price';
|
||||
return $currentLadder[$key] ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 阶梯拼团,第一阶梯价
|
||||
*
|
||||
* @param string $value
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
public function getLadderOneAttr($value, $data)
|
||||
{
|
||||
return $this->currentLadder($data, 'ladder_one');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 阶梯拼团,第二阶梯价
|
||||
*
|
||||
* @param string $value
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
public function getLadderTwoAttr($value, $data)
|
||||
{
|
||||
return $this->currentLadder($data, 'ladder_two');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 阶梯拼团,第二阶梯价
|
||||
*
|
||||
* @param string $value
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
public function getLadderThreeAttr($value, $data)
|
||||
{
|
||||
return $this->currentLadder($data, 'ladder_three');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 阶梯拼团,第一阶梯团长价
|
||||
*
|
||||
* @param string $value
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
public function getLadderOneLeaderAttr($value, $data)
|
||||
{
|
||||
return $this->currentLadder($data, 'ladder_one', true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 阶梯拼团,第二阶团长梯价
|
||||
*
|
||||
* @param string $value
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
public function getLadderTwoLeaderAttr($value, $data)
|
||||
{
|
||||
return $this->currentLadder($data, 'ladder_two', true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 阶梯拼团,第二阶团长梯价
|
||||
*
|
||||
* @param string $value
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
public function getLadderThreeLeaderAttr($value, $data)
|
||||
{
|
||||
return $this->currentLadder($data, 'ladder_three', true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user