| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- /**
- * 公司游戏绑定表
- *
- */
- namespace app\common\model;
- use think\Model;
- class CompanyGameBind extends Model
- {
- protected $pk = 'id';
- protected $table = 'cy_company_game_bind';
- protected $autoWriteTimestamp = false; // 手动处理时间,因为字段是 datetime 类型
-
- protected static function init()
- {
- // 插入前自动设置创建时间和更新时间
- self::beforeInsert(function ($companyGameBind) {
- if (empty($companyGameBind->created_at)) {
- $companyGameBind->created_at = date('Y-m-d H:i:s');
- }
- if (empty($companyGameBind->updated_at)) {
- $companyGameBind->updated_at = date('Y-m-d H:i:s');
- }
- });
-
- // 更新前自动设置更新时间
- self::beforeUpdate(function ($companyGameBind) {
- $companyGameBind->updated_at = date('Y-m-d H:i:s');
- });
- }
-
- /**
- * 获取游戏数量
- */
- public function getGameCountAttr($value, $data)
- {
- if (empty($data['game_ids'])) {
- return 0;
- }
- $gameIds = explode(',', $data['game_ids']);
- return count(array_filter($gameIds));
- }
- }
|