123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- // +----------------------------------------------------------------------
- // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: 萤火科技 <admin@yiovo.com>
- // +----------------------------------------------------------------------
- declare (strict_types = 1);
- namespace app\common\model\user;
- use app\common\model\BaseModel;
- use app\common\enum\user\balanceLog\Scene as SceneEnum;
- use app\common\model\User;
- use Exception;
- use think\facade\Db;
- use think\facade\Log;
- /**
- * 用户余额变动明细模型
- * Class BalanceLog
- * @package app\common\model\user
- */
- class WithdrawMoneyLog extends BaseModel
- {
- // 定义表名
- protected $name = 'withdraw_money_log';
- // 定义主键
- protected $pk = 'log_id';
- protected $updateTime = false;
- /**
- * 关联会员记录表
- * @return \think\model\relation\BelongsTo
- */
- public function user()
- {
- $module = self::getCalledModule();
- return $this->belongsTo("app\\{$module}\\model\\User");
- }
- /**
- * 新增记录
- * @param int $scene
- * @param array $data
- * @param array $describeParam
- */
- public static function add(int $scene, array $data, array $describeParam)
- {
- $model = new static;
- $model->save(array_merge([
- 'scene' => $scene,
- 'describe' => vsprintf(SceneEnum::data()[$scene]['describe'], $describeParam),
- 'store_id' => $model::$storeId
- ], $data));
- }
- /**
- * 记录分佣明细
- * @param $userId
- * @param $scene
- * @param $money
- * @param string $describe
- * @param string $remark
- * @return bool
- * @throws Exception
- */
- public static function addNewLog($userId,$scene,$money,$describe='',$remark=''){
- $log = new self();
- $user = User::find($userId);
- if ($money == 0){
- return $user?$user->can_withdraw_money:0;
- }
- try {
- if (!$user){
- throw new Exception('用户不存在'.$userId);
- }
- $log->save([
- 'user_id' => $userId,
- 'scene' => $scene,
- 'money' => $money,
- 'describe' => $describe,
- 'remark' => $remark,
- ]);
- //提现余额也要累加计算
- $user->can_withdraw_money = Db::raw('can_withdraw_money+'.$money);
- //可提现金额
- $user->ktxyj_amount = Db::raw('ktxyj_amount+'.$money);
- $user->save();
- }catch (Exception $e){
- Log::error('order_id::'.$remark.',desc::'.$describe.','.$e->getMessage());
- //throw $e;
- return false;
- }
- $user = User::find($userId);
- return $user->can_withdraw_money;
- }
- }
|