123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace app\admin\model;
- use think\Log;
- use think\Model;
- use app\common\constants\OfficialAccount;
- use app\common\constants\Message;
- use app\common\constants\Common;
- use app\common\constants\Custom;
- class CustomMediaPush extends Model
- {
- // 表名
- protected $table = 'custom_media_push';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
-
- // 追加属性
- protected $append = [
- 'message_type_text',
- 'official_account_type_text',
- 'sendtime_text',
- 'status_text'
- ];
-
-
- public function getMessageTypeList()
- {
- return ['0' => __('Message_type 0'),'1' => __('Message_type 1')];
- }
- public function getOfficialAccountTypeList()
- {
- return ['0' => __('Official_account_type 0'),'1' => __('Official_account_type 1')];
- }
- public function getStatusList()
- {
- return ['0' => __('Status 0'),'1' => __('Status 1'),'2' => __('Status 2')];
- }
- public function getMessageTypeTextAttr($value, $data)
- {
- $value = $value ? $value : $data['message_type'];
- $list = $this->getMessageTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getOfficialAccountTypeTextAttr($value, $data)
- {
- $value = $value ? $value : $data['official_account_type'];
- $list = $this->getOfficialAccountTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getSendtimeTextAttr($value, $data)
- {
- $value = $value ? $value : $data['sendtime'];
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : $data['status'];
- $list = $this->getStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- protected function setSendtimeAttr($value)
- {
- return $value && !is_numeric($value) ? strtotime($value) : $value;
- }
- /**
- * 逻辑删除素材
- * @param $mediaId 素材ID
- * @return int|bool
- */
- public function deleteMediaPush($mediaPushId)
- {
- return $this->save(['status' => Custom::CUSTOM_MEDIA_PUSH_STATUS_DELETE], ['id' => $mediaPushId]);
- }
- /**
- * @param $id custom_media_push 表中的ID
- * @return array
- * @throws \think\Exception
- * @throws \think\exception\DbException
- */
- public function getCustomInfoById($id)
- {
- $data = $this->get(['id'=>$id])->toArray();
- return $data;
- }
- }
|