12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace app\admin\model;
- use think\db\Query;
- use think\Model;
- /**
- * @method static Query|self filterTypeCommission()
- */
- class AdminMoneyLog extends Model
- {
- const T_COMMISSION=1;
- protected $autoWriteTimestamp=true;
- protected $updateTime=null;
- public static $money_types=[
- self::T_COMMISSION=>'销售提成',
- ];
- /**
- * @return string[]
- */
- public static function getMoneyTypes(): array
- {
- return self::$money_types;
- }
- #退款中的或已退款的
- public function scopeFilterTypeCommission(Query $query){
- $query->where($this->__('type'),self::T_COMMISSION);
- }
- public function admin(){
- return $this->belongsTo(Admin::class)->setEagerlyType(0);
- }
- public static function money($admin_id,$amount,$type,$from_user_id,$target_id=null,$remark=null){
- $admin=Admin::where('id',$admin_id)->lock(true)->find();
- if(!$admin){
- return false;
- }
- $before=$admin['money'];
- $admin['money']=bcadd($admin['money'],$amount);
- if($admin['money']<0){
- throw_user('余额不足');
- }
- $admin->moneyLog()->save([
- 'type'=>$type,
- 'amount'=>$amount,
- 'before'=>$before,
- 'after'=>$admin['money'],
- 'target_id'=>$target_id,
- 'remark'=>$remark,
- 'from_user_id'=>$from_user_id
- ]);
- }
- }
|