ControlRecord.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Models;
  3. use App\Http\helper\NumConfig;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Support\Facades\DB;
  6. class ControlRecord extends Model
  7. {
  8. const TABLE = 'agent.dbo.control_record';
  9. protected $table = self::TABLE;
  10. public $timestamps = false;
  11. protected $guarded = [];
  12. // 添加记录
  13. public static function record_add($user_id, $admin_id, $content, $score)
  14. {
  15. // 查找之前有没有配置过
  16. $query = DB::table('QPTreasureDB.dbo.UserScoreControl')->where('UserID', $user_id)->first();
  17. if ($query) {
  18. $EffectiveScore = number_float($query->EffectiveScore / NumConfig::NUM_VALUE);
  19. $ControlScore = number_float($query->ControlScore / NumConfig::NUM_VALUE);
  20. $prefix = $ControlScore < 0 ? $EffectiveScore . '/' . $ControlScore . '输' : '赢' . $EffectiveScore . '/' . $ControlScore;
  21. $UserControlKind = DB::connection('write')->table('QPTreasureDB.dbo.UserControlKind')->where('UserID', $user_id)->get();
  22. $data = [];
  23. $GameData = (new Control())->GameData;
  24. $GameData = array_flip($GameData);
  25. foreach ($UserControlKind as $value) {
  26. if (!isset($GameData[$value->KindID])) {
  27. continue;
  28. }
  29. $data[$GameData[$value->KindID]] = number_float($value->ControlRadian) . '%';
  30. // if ($value->KindID == 1005) {
  31. // $data['TP'] = number_float($value->ControlRadian) . '%';
  32. // }
  33. // if ($value->KindID == 2061) {
  34. // $data['TPAK47'] = number_float($value->ControlRadian) . '%';
  35. // }
  36. // if ($value->KindID == 2060) {
  37. // $data['TPJOKER'] = number_float($value->ControlRadian) . '%';
  38. // }
  39. // if ($value->KindID == 2030) {
  40. // $data['Rummy5'] = number_float($value->ControlRadian ) . '%';
  41. // }
  42. // if ($value->KindID == 2050) {
  43. // $data['Rummy2'] = number_float($value->ControlRadian) . '%';
  44. // }
  45. }
  46. $str = '';
  47. foreach ($data as $key => $value) {
  48. $str .= $key . ':' . $value . ',';
  49. }
  50. $before_config = $prefix . '/' . rtrim( $str,',');
  51. }
  52. $before_config = $before_config ?? '';
  53. $data = [
  54. 'user_id' => $user_id,
  55. 'admin_id' => $admin_id,
  56. 'contents' => $content,
  57. 'before_config' => $before_config,
  58. 'created_at' => date('Y-m-d H:i:s'),
  59. 'score' => $score
  60. ];
  61. DB::connection('write')->table('agent.dbo.control_record')->insert($data);
  62. // 大于5条以外的数据删除 -- 只保留最新的5条记录
  63. DB::connection('write')->table('agent.dbo.control_record')
  64. ->whereNotIn('id', function ($query) use ($user_id) {
  65. $query->from('agent.dbo.control_record')
  66. ->selectRaw('id')
  67. ->where('user_id', $user_id)
  68. ->orderBy('created_at', 'desc')
  69. ->limit(5);
  70. })->where('user_id', $user_id)
  71. ->delete();
  72. }
  73. }