1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace app\common\model;
- use app\common\library\Redis;
- use app\main\constants\CacheConstants;
- use think\Model;
- class BookChargeSetting extends Model
- {
- // 表名
- protected $table = 'book_charge_setting';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
-
- // 追加属性
- protected $append = [
- 'status_text'
- ];
-
-
- public function getStatusList()
- {
- return ['normal' => __('Status normal'),'hide' => __('Status hide')];
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : $data['status'];
- $list = $this->getStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- /**
- * 获取收费书籍信息
- * @param $channel_id
- * @param $book_id
- * @return array
- */
- public function getInfo($channel_id, $book_id)
- {
- $cache = CacheConstants::getChapterFeeCache($channel_id, $book_id);
- $data = Redis::instance()->hGetAll($cache);
- if (!$data) {
- $info = $this->where('book_id', $book_id)
- ->where('admin_id', $channel_id)
- ->where('status', 'normal')
- ->find();
- if ($info) {
- $data = [
- 'id' => $info['id'],
- 'chapter_charge_start' => $info->getData('chapter_charge_start'),
- 'chapter_kandian' => $info->getData('chapter_kandian'),
- ];
- } else {
- $data = ['id' => 0];
- }
- Redis::instance()->hMSet($cache, $data);
- Redis::instance()->expire($cache, 600);
- }
- if (!$data['id']) {
- return [];
- } else {
- return $data;
- }
- }
- /**
- * 清除缓存
- * @param $channel_id
- * @param $book_id
- */
- public function clearInfo($channel_id, $book_id)
- {
- $cache = CacheConstants::getChapterFeeCache($channel_id, $book_id);
- Redis::instance()->del($cache);
- }
- }
|