重构:升级经销商赠送画

This commit is contained in:
wuhui_zzw 2023-10-17 09:53:41 +08:00
parent eaea295d6c
commit d784c030cf
5 changed files with 128 additions and 20 deletions

View File

@ -106,5 +106,12 @@ class IndexController extends BaseController{
}
public function test(){
CollectionRoomModel::addInfo(1,2);
}
}

View File

@ -10,6 +10,8 @@ namespace Yunshop\CollectionRoom\models;
use app\common\models\BaseModel;
use app\common\models\Member;
use Illuminate\Support\Facades\DB;
use Yunshop\TeamDividend\models\TeamDividendLevelModel;
class CollectionRoomModel extends BaseModel{
@ -64,27 +66,76 @@ class CollectionRoomModel extends BaseModel{
return $list ? $list->toArray() : [];
}
/**
* Common: 给指定用户添加一幅
* Common: 给指定用户添加指定数量的
* Author: wu-hui
* Time: 2023/09/27 18:57
* @param $memberId
* Time: 2023/10/17 9:51
* @param int $memberId
* @param int $sourceId
* @param int $source
* @param int $num
* @param int $type
*/
public static function addInfo($memberId){
// 判断:当前用户是否已经持有 未持有赠送 持有则不管
$isHas = (int)self::uniacid()->where('member_id',$memberId)->value('id');
\Log::debug('给指定用户添加一幅画 - 查询结果 - 典藏室id',$isHas);
if($isHas <= 0){
self::insert([
'uniacid' => \YunShop::app()->uniacid,
'member_id' => $memberId,
'created_at' => time()
]);
public static function addInfo(int $memberId,int $sourceId,int $source = 0,int $num = 1,int $type=0){
\Log::debug('添加画 - 开始处理:',[
'member_id' => $memberId,
'sourceId' => $sourceId,
'source' => $source,
'num' => $num,
'type' => $type,
]);
DB::beginTransaction();
try{
$uniacid = \YunShop::app()->uniacid;
// 判断:当来源为【成为经销商赠送】时 判断当前等级是否已经赠送,已经赠送则不在重复赠送
if($source == 0){
$isHas = CollectionRoomRecordModel::getFirst([
'member_id' => $memberId,
'source_id' => $sourceId,
'source' => $source,
'type' => 0
]);
if($isHas) throw new \Exception("经销商升级奖励已经发放,不在重复发放!");
// 未领取 可以赠送,获取当前等级赠送的数量
$num = (int)TeamDividendLevelModel::uniacid()->where('id',$sourceId)->value('upgrade_reward_draw');
if($num <= 0) throw new \Exception('当前经销商等级不赠送数藏画');
}
// 添加对应数量的画及其变更记录
$recordData = [];
for($i = 1;$i <= $num;$i++){
// 添加画
$id = self::insertGetId([
'uniacid' => $uniacid,
'member_id' => $memberId,
'created_at' => time()
]);
// 添加画变更记录
$recordData[] = [
'uniacid' => $uniacid,
'member_id' => $memberId,
'collection_room_id' => $id,
'type' => $type,
'source' => $source,
'source_id' => $sourceId,
'created_at' => time(),
];
}
CollectionRoomRecordModel::insert($recordData);
DB::commit();
}catch(\Exception $e){
\Log::debug('添加画 - 成为:',$e->getMessage());
DB::rollBack();
}
return;
}
/**
* Common: 一对一关联 - 用户信息表
* Author: wu-hui

View File

@ -0,0 +1,53 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/3/18
* Time: 14:27
*/
namespace Yunshop\CollectionRoom\models;
use app\common\models\BaseModel;
use app\common\models\Member;
class CollectionRoomRecordModel extends BaseModel{
public $table = 'yz_collection_room_record';
public $timestamps = false;
public $casts = [
'created_at' => 'datetime:Y-m-d H:i:s'
];
protected $fillable = [
'uniacid',
'member_id',
'collection_room_id',
'type',
'source',
'source_id',
'created_at',
];
/**
* Common: 根据条件获取一条数据
* Author: wu-hui
* Time: 2023/10/17 9:23
* @param $where
* @return array
*/
public static function getFirst($where){
$first = self::uniacid()->where($where)->first();
return $first ? $first->toArray() : [];
}
}

View File

@ -431,7 +431,7 @@ class NewUpgrateJob implements ShouldQueue
// 升级赠送权重值
(new WeightValue())->upgradeGiveInit($uid,(int)$level->id);
// 升级赠送画
// CollectionRoomModel::addInfo($member->uid);
CollectionRoomModel::addInfo($uid,(int)$level->id);
}
/**

View File

@ -46,12 +46,9 @@ class DealerObserver extends BaseObserver{
// 经销商等级变更
if((int)$model->uid > 0 && (int)$model->getOriginal('level') != (int)$model->level){
// 经销商升级赠送权重值处理
(new WeightValue())->upgradeGiveInit($model->uid,(int)$model->level);
// 会员升级经销商 赠送一幅画
// CollectionRoomModel::addInfo((int)$model->uid);
(new WeightValue())->upgradeGiveInit((int)$model->uid,(int)$model->level);
// 会员升级经销商 赠送画
CollectionRoomModel::addInfo((int)$model->uid,(int)$model->level);
}
}