AdminScore.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Support\Facades\DB;
  5. class AdminScore extends Model
  6. {
  7. const TABLE = 'agent.dbo.admin_score';
  8. protected $table = self::TABLE;
  9. public $timestamps = false;
  10. protected $guarded = [];
  11. // 添加记录
  12. public static function add_score($admin, $change_score, $type)
  13. {
  14. switch ($type) {
  15. case 1:
  16. $before_score = $admin->lottery_amount;
  17. // 减少管理员金额
  18. $after_score = $before_score - $change_score;
  19. $admin_data = ['lottery_amount' => $after_score];
  20. break;
  21. case 2:
  22. $before_score = $admin->recharge_amount;
  23. // 减少管理员金额
  24. $after_score = $before_score - $change_score;
  25. $admin_data = ['recharge_amount' => $after_score];
  26. break;
  27. default:
  28. return;
  29. }
  30. // 添加记录
  31. $data = [
  32. 'before_score' => $before_score,
  33. 'after_score' => $after_score,
  34. 'change_score' => $change_score,
  35. 'admin_id' => $admin->id,
  36. 'type' => $type,
  37. 'created_at' => date('Y-m-d H:i:s')
  38. ];
  39. self::create($data);
  40. DB::table('agent.dbo.admin_users')->where('id', $admin->id)->update($admin_data);
  41. }
  42. }