CompanyGameBind.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * 公司游戏绑定表
  4. *
  5. */
  6. namespace app\common\model;
  7. use think\Model;
  8. class CompanyGameBind extends Model
  9. {
  10. protected $pk = 'id';
  11. protected $table = 'cy_company_game_bind';
  12. protected $autoWriteTimestamp = false; // 手动处理时间,因为字段是 datetime 类型
  13. protected static function init()
  14. {
  15. // 插入前自动设置创建时间和更新时间
  16. self::beforeInsert(function ($companyGameBind) {
  17. if (empty($companyGameBind->created_at)) {
  18. $companyGameBind->created_at = date('Y-m-d H:i:s');
  19. }
  20. if (empty($companyGameBind->updated_at)) {
  21. $companyGameBind->updated_at = date('Y-m-d H:i:s');
  22. }
  23. });
  24. // 更新前自动设置更新时间
  25. self::beforeUpdate(function ($companyGameBind) {
  26. $companyGameBind->updated_at = date('Y-m-d H:i:s');
  27. });
  28. }
  29. /**
  30. * 获取游戏数量
  31. */
  32. public function getGameCountAttr($value, $data)
  33. {
  34. if (empty($data['game_ids'])) {
  35. return 0;
  36. }
  37. $gameIds = explode(',', $data['game_ids']);
  38. return count(array_filter($gameIds));
  39. }
  40. }