1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace app\common\model;
- use library\tools\Data;
- use think\Model;
- // 用户开关
- class PlatformSwitch extends Model
- {
- static $type_desc = [
- 1=>'问答通知开关', 2=>'视频追更', 3=>'图文追更', 4=>'资料追更', 5=>'供应商追更', 6=>'招聘追更'
- ];
- /**
- * 验证开关状态
- * @param $user_id
- * @param $id
- * @param $type 1问答
- * @return int
- */
- public static function checkSwitch($user_id,$id,$type){
- $switch_value = self::where(['user_id'=>$user_id,'switch_id'=>$id,'type'=>$type])->value('switch_value');
- return $switch_value === 0 ? 0 : 1;
- }
- /**
- * @param $user_id
- * @param $id
- * @param $type 1问答
- */
- public static function userSwitch($user_id,$id,$type)
- {
- $check_tags = self::checkSwitch($user_id,$id,$type);
- $switch_value = $check_tags ? 0:1;
- Data::save('PlatformSwitch',
- ['user_id'=>$user_id,'switch_id'=>$id,'type'=>$type,'switch_value'=>$switch_value],'user_id',
- ['user_id'=>$user_id,'switch_id'=>$id,'type'=>$type]);
- return $switch_value;
- }
- }
|