0, 'mobile' => 0], $value); return (object)$value; } /** * 设置验证字段 * @param mixed $value * @return string */ public function setVerificationAttr($value) { $value = is_object($value) || is_array($value) ? json_encode($value) : $value; return $value; } /** * 变更会员余额 * @param int $money 余额 * @param int $user_id 会员ID * @param string $memo 备注 */ public static function money($money, $user_id, $memo) { Db::startTrans(); try { $user = self::lock(true)->find($user_id); if ($user && $money != 0) { $before = $user->money; //$after = $user->money + $money; $after = function_exists('bcadd') ? bcadd($user->money, $money, 2) : $user->money + $money; //更新会员信息 $user->save(['money' => $after]); //写入日志 MoneyLog::create(['user_id' => $user_id, 'money' => $money, 'before' => $before, 'after' => $after, 'memo' => $memo]); } Db::commit(); } catch (\Exception $e) { Db::rollback(); } } /** * 变更会员积分 * @param int $score 积分 * @param int $user_id 会员ID * @param string $memo 备注 */ public static function score($score, $user_id, $memo) { Db::startTrans(); try { $user = self::lock(true)->find($user_id); if ($user && $score != 0) { $before = $user->score; $after = $user->score + $score; $level = self::nextlevel($after); //更新会员信息 $user->save(['score' => $after, 'level' => $level]); //写入日志 ScoreLog::create(['user_id' => $user_id, 'score' => $score, 'before' => $before, 'after' => $after, 'memo' => $memo]); } Db::commit(); } catch (\Exception $e) { Db::rollback(); } } /** * 根据积分获取等级 * @param int $score 积分 * @return int */ public static function nextlevel($score = 0) { $lv = array(1 => 0, 2 => 30, 3 => 100, 4 => 500, 5 => 1000, 6 => 2000, 7 => 3000, 8 => 5000, 9 => 8000, 10 => 10000); $level = 1; foreach ($lv as $key => $value) { if ($score >= $value) { $level = $key; } } return $level; } /**是否有核销权限 * @return boolean */ public static function verificationAuth($user_id){ $have_auth = false; //判断用户是否有核销权限 //判断是否是员工 $verification = Verification::where("user_id",$user_id)->where("status",'1')->find(); if($verification)$have_auth = true; //判断是否是教师 $teacher = Teacher::where("user_id",$user_id)->find(); if($teacher)$have_auth = true; return $have_auth; } /**是否有老师权限 * @return boolean */ public static function teacherAuth($user_id){ $have_auth = false; //判断是否是教师 $teacher = Teacher::where("user_id",$user_id)->find(); if($teacher)$have_auth = true; return $have_auth; } }