12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace app\common\model;
- use app\common\library\Redis;
- use app\main\constants\AdminConstants;
- use think\Model;
- class AdminExtend extends Model
- {
- // 表名
- protected $table = 'admin_extend';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
-
- // 追加属性
- protected $append = [
- 'pay_method_text'
- ];
- public function getPayMethodList()
- {
- return ['1' => '单位', '2' => '云支付', '3' => '微信', '4' => '支付宝'];
- }
- public function getPayMethodTextAttr($value, $data)
- {
- $value = $value ? $value : $data['pay_method'];
- $list = $this->getPayMethodList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function checkAgent($admin_id,$checkDis = true){
- $group_id = model('AdminGroupAccess')->getGroupId($admin_id);
- if(!$checkDis && $group_id == AdminConstants::ADMIN_GROUP_ID_AGENT){
- //不检查配号
- return true;
- }else if($checkDis && $group_id == AdminConstants::ADMIN_GROUP_ID_AGENT){
- //检查配号
- $ex_info = $this->getInfo($admin_id);
- if(intval($ex_info['distribute'])){
- return true;
- }else{
- return false;
- }
- }else{
- return false;
- }
- }
- public function getInfo($adminId){
- $redis = Redis::instance();
- $key = 'AE:'.$adminId;
- if($redis->exists($key)){
- $info = $redis->hgetall($key);
- if (!array_key_exists('benefit_app', $info)) {
- $redis->del($key);
- return $this->getInfo($adminId);
- }
- }else{
- $info = $this->where('admin_id',$adminId)->find();
- if($info){
- $info = $info->toArray();
- $redis->hmset($key,$info);
- $redis->expire($key,86400);
- }else{
- $info = null;
- }
- }
- return $info;
- }
- /**
- * 获取对应的渠道
- * @param $channel_id
- * @return mixed
- */
- public function getChannelId($channel_id)
- {
- $adminInfo = $this->getInfo($channel_id);
- if ($adminInfo['distribute']) {
- return $adminInfo['create_by'];
- } else {
- return $adminInfo['admin_id'];
- }
- }
- }
|