// +---------------------------------------------------------------------- declare (strict_types = 1); namespace app\common\model\user; use app\common\model\BaseModel; use app\common\service\Message; /** * 用户余额变动明细模型 * Class BalanceLog * @package app\common\model\user */ class BonusHistory extends BaseModel { // 定义表名 protected $name = 'bonus_history'; // 定义主键 protected $pk = 'id'; /** * 新增记录 * @param $userId * @param $year * @param $month * @param $salesVolume * @param $refundVolume * @param $refundCount * @param $countOvertimeSign * @param $sumOvertimeSign * @param $bonusRate * @param $bonusMoney * @param bool $monthly * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public static function add($userId, $year,$month,$salesVolume,$refundVolume,$refundCount,$countOvertimeSign,$sumOvertimeSign,$bonusRate,$bonusMoney,$monthly =false) { $old = self::where(['user_id'=>$userId,'year'=>$year,'month'=>$month])->find(); try { if ($old){ if ($old->clearing_status == 1){ log_record('已结userId::'.$userId.'-'.$year.$month); return false; } $data = ['sales_volume' => $salesVolume, 'refund_volume' => $refundVolume, 'refund_count' => $refundCount, 'overtime_receipt_count' => $countOvertimeSign, 'overtime_receipt_sum' => $sumOvertimeSign, 'bonus_rate' => $bonusRate, 'bonus_money' => $bonusMoney]; if ($monthly == true){ /* if ($old->clearing_status == 1){ log_record('已结userId::'.$userId.'-'.$year.$month); return false; }*/ $data['clearing_status'] = 1; } self::update($data,['id'=>$old->id]); }else{ /* if ($bonusMoney == 0){ return true; }*/ $new = [ 'user_id' => $userId, 'year' => $year, 'month' => $month, 'year_month' => $year.$month, 'sales_volume' => $salesVolume, 'refund_count' => $refundCount, 'overtime_receipt_count' => $countOvertimeSign, 'overtime_receipt_sum' => $sumOvertimeSign, 'bonus_rate' => $bonusRate, 'bonus_money' => $bonusMoney, 'create_time' => time() ]; if ($monthly == true){ $new['clearing_status'] = 1; } BonusHistory::create($new); //['user_id','year','month','sales_volume','refund_count','overtime_receipt_count','bonus_rate','bonus_money','create_time'] } }catch (\Exception $e){ $error = __METHOD__.',userid::'.$userId.",".$e->getMessage(); log_record($error,'error'); Message::wxRobot($error); return false; } return true; } /** * v1.3.6版本区分门店角色 * @param $userId * @param $year * @param $month * @param $shopId * @param $role * @param $salesVolume * @param $refundVolume * @param $refundCount * @param $countOvertimeSign * @param $sumOvertimeSign * @param $bonusRate * @param $bonusMoney * @param $orderCount * @param $bonusLadder * @param false $monthly * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public static function add36($userId, $year,$month,$shopId,$role,$salesVolume,$refundVolume,$refundCount,$countOvertimeSign,$sumOvertimeSign,$bonusRate,$bonusMoney,$orderCount,$bonusLadder,$monthly =false) { $old = self::where(['user_id'=>$userId,'year'=>$year,'month'=>$month,'shop_id'=>$shopId,'role'=>$role])->find(); try { if ($old){ if ($old->clearing_status == 1){ log_record('已结userId::'.$userId.'-'.$year.$month); return false; } $data = [ 'sales_volume' => $salesVolume, 'refund_volume' => $refundVolume, 'refund_count' => $refundCount, 'overtime_receipt_count' => $countOvertimeSign, 'overtime_receipt_sum' => $sumOvertimeSign, 'bonus_rate' => $bonusRate, 'bonus_money' => $bonusMoney, 'order_count' => $orderCount, 'bonus_ladder' => $bonusLadder, ]; if ($monthly == true){ $data['clearing_status'] = 1; } self::update($data,['id'=>$old->id]); }else{ $new = [ 'user_id' => $userId, 'year' => $year, 'month' => $month, 'year_month' => $year.($month < 10?('0'.$month):$month), 'shop_id' =>$shopId, 'role' =>$role, 'sales_volume' => $salesVolume, 'refund_volume' => $refundVolume, 'refund_count' => $refundCount, 'overtime_receipt_count' => $countOvertimeSign, 'overtime_receipt_sum' => $sumOvertimeSign, 'bonus_rate' => $bonusRate, 'bonus_money' => $bonusMoney, 'order_count' => $orderCount, 'bonus_ladder' => $bonusLadder, 'create_time' => time() ]; if ($monthly == true){ $new['clearing_status'] = 1; } BonusHistory::create($new); //['user_id','year','month','sales_volume','refund_count','overtime_receipt_count','bonus_rate','bonus_money','create_time'] } }catch (\Exception $e){ $error = __METHOD__.',userid::'.$userId.",".$e->getMessage(); log_record($error,'error'); Message::wxRobot($error); return false; } return true; } }