167 lines
6.2 KiB
PHP
167 lines
6.2 KiB
PHP
<?php
|
||
namespace Yunshop\WeightValue\models;
|
||
|
||
use app\common\models\BaseModel;
|
||
use app\common\models\Member;
|
||
use Yunshop\TeamDividend\models\TeamDividendLevelModel;
|
||
|
||
class WeightValueLog extends BaseModel{
|
||
|
||
public $timestamps = false;
|
||
public $table = 'yz_weight_value_log';
|
||
public $casts = [
|
||
'created_at' => 'datetime:Y-m-d H:i:s'
|
||
];
|
||
protected $fillable = [
|
||
'uniacid',
|
||
'member_id',
|
||
'team_dividend_agency_level_id',
|
||
'goods_id',
|
||
'order_id',
|
||
'order_goods_id',
|
||
'change_type',
|
||
'change_quantity',
|
||
'change_front',
|
||
'change_after',
|
||
'remark',
|
||
'created_at',
|
||
'source'
|
||
];
|
||
|
||
/**
|
||
* Common: 权重值变更记录
|
||
* Author: wu-hui
|
||
* Time: 2023/10/12 17:48
|
||
* @param $pageSize
|
||
* @param $search
|
||
* @param string[] $field
|
||
* @return array
|
||
*/
|
||
public function getList($pageSize,$search,$field = ['*']){
|
||
// 条件生成
|
||
$where = [];
|
||
if($search['member_id'] > 0) $where[] = ['member_id','=',$search['member_id']];
|
||
if($search['team_dividend_agency_level_id'] > 0) $where[] = ['team_dividend_agency_level_id','=',$search['team_dividend_agency_level_id']];
|
||
if($search['change_type'] >= 0 && $search['change_type'] != '') $where[] = ['change_type','=',$search['change_type']];
|
||
// 列表获取
|
||
$list = self::uniacid()
|
||
->select($field)
|
||
->where($where)
|
||
->with([
|
||
'member' => function($query){
|
||
$query->select(['uid','nickname','realname','avatar']);
|
||
},
|
||
'level' => function($query){
|
||
$query->select(['id','level_name']);
|
||
},
|
||
])
|
||
->orderBy('created_at','DESC')
|
||
->orderBy('id','DESC')
|
||
->paginate($pageSize);
|
||
|
||
return $list ? $list->toArray() : [];
|
||
}
|
||
/**
|
||
* Common: 转赠后权重值变更处理
|
||
* Author: wu-hui
|
||
* Time: 2023/10/20 17:59
|
||
* @param int $uid
|
||
* @param float $money
|
||
* @param int $changeType
|
||
* @param string $remark
|
||
* @param int $teamLevelId
|
||
*/
|
||
public function transferHandle(int $uid,float $money,int $changeType,string $remark,int $teamLevelId){
|
||
// 获取当前用户持有数量
|
||
$changeFront = (float)WeightValue::getWeightValueQuantity((int)$uid,(int)$teamLevelId);
|
||
// 变更后的数量
|
||
$changeAfter = $changeType == 1 ? $changeFront + $money : $changeFront - $money;
|
||
// 变更记录
|
||
$data = [
|
||
'uniacid' => \YunShop::app()->uniacid,
|
||
'member_id' => $uid,// 用户id
|
||
'team_dividend_agency_level_id' => $teamLevelId,// 经销商等级id
|
||
'goods_id' => 0,// 商品id
|
||
'order_id' => 0,// 订单id
|
||
'order_goods_id' => 0,// 订单商品id
|
||
'change_type' => $changeType,// 变更类型:0=减少,1=增加
|
||
'change_quantity' => $money,// 变更数量
|
||
'change_front' => (float)$changeFront,// 变更前拥有的数量
|
||
'change_after' => sprintf("%.2f",$changeAfter),// 变更后拥有的数量
|
||
'remark' => $remark,// 备注
|
||
'created_at' => time(),// 变更时间
|
||
'source' => 2,// 变更时间
|
||
];
|
||
$this->insert($data);
|
||
// 修改用户持有
|
||
WeightValue::uniacid()
|
||
->where('member_id',$uid)
|
||
->where('team_dividend_agency_level_id',$teamLevelId)
|
||
->update(['quantity' => $changeAfter]);
|
||
}
|
||
/**
|
||
* Common: 后台处理 权重值变更处理
|
||
* Author: wu-hui
|
||
* Time: 2023/12/05 18:16
|
||
* @param int $uid
|
||
* @param float $money
|
||
* @param int $changeType
|
||
* @param string $remark
|
||
* @param int $teamLevelId
|
||
*/
|
||
public function changeHandle(int $uid,float $money,int $changeType,string $remark,int $teamLevelId){
|
||
// 获取当前用户持有数量
|
||
$changeFront = (float)WeightValue::getWeightValueQuantity((int)$uid,(int)$teamLevelId);
|
||
// 变更后的数量
|
||
$changeAfter = $changeType == 1 ? $changeFront + $money : $changeFront - $money;
|
||
// 变更记录
|
||
$data = [
|
||
'uniacid' => \YunShop::app()->uniacid,
|
||
'member_id' => $uid,// 用户id
|
||
'team_dividend_agency_level_id' => $teamLevelId,// 经销商等级id
|
||
'goods_id' => 0,// 商品id
|
||
'order_id' => 0,// 订单id
|
||
'order_goods_id' => 0,// 订单商品id
|
||
'change_type' => $changeType,// 变更类型:0=减少,1=增加
|
||
'change_quantity' => $money,// 变更数量
|
||
'change_front' => (float)$changeFront,// 变更前拥有的数量
|
||
'change_after' => sprintf("%.2f",$changeAfter),// 变更后拥有的数量
|
||
'remark' => $remark,// 备注
|
||
'created_at' => time(),// 变更时间
|
||
'source' => 4,// 变更时间
|
||
];
|
||
$this->insert($data);
|
||
// 修改用户持有
|
||
WeightValue::uniacid()
|
||
->where('member_id',$uid)
|
||
->where('team_dividend_agency_level_id',$teamLevelId)
|
||
->update(['quantity' => $changeAfter]);
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/**
|
||
* Common: 一对一关联 用户信息
|
||
* Author: wu-hui
|
||
* Time: 2023/10/12 17:49
|
||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||
*/
|
||
public function member(){
|
||
return $this->hasOne(Member::class, 'uid', 'member_id');
|
||
}
|
||
/**
|
||
* Common: 一对一关联 经销商等级信息
|
||
* Author: wu-hui
|
||
* Time: 2023/10/12 15:36
|
||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||
*/
|
||
public function level(){
|
||
return $this->hasOne(TeamDividendLevelModel::class, 'id', 'team_dividend_agency_level_id');
|
||
}
|
||
|
||
|
||
|
||
}
|