AdminExtend.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace app\common\model;
  3. use app\common\library\Redis;
  4. use app\main\constants\AdminConstants;
  5. use think\Model;
  6. class AdminExtend extends Model
  7. {
  8. // 表名
  9. protected $table = 'admin_extend';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = 'int';
  12. // 定义时间戳字段名
  13. protected $createTime = 'createtime';
  14. protected $updateTime = 'updatetime';
  15. // 追加属性
  16. protected $append = [
  17. 'pay_method_text'
  18. ];
  19. public function getPayMethodList()
  20. {
  21. return ['1' => '单位', '2' => '云支付', '3' => '微信', '4' => '支付宝'];
  22. }
  23. public function getPayMethodTextAttr($value, $data)
  24. {
  25. $value = $value ? $value : $data['pay_method'];
  26. $list = $this->getPayMethodList();
  27. return isset($list[$value]) ? $list[$value] : '';
  28. }
  29. public function checkAgent($admin_id,$checkDis = true){
  30. $group_id = model('AdminGroupAccess')->getGroupId($admin_id);
  31. if(!$checkDis && $group_id == AdminConstants::ADMIN_GROUP_ID_AGENT){
  32. //不检查配号
  33. return true;
  34. }else if($checkDis && $group_id == AdminConstants::ADMIN_GROUP_ID_AGENT){
  35. //检查配号
  36. $ex_info = $this->getInfo($admin_id);
  37. if(intval($ex_info['distribute'])){
  38. return true;
  39. }else{
  40. return false;
  41. }
  42. }else{
  43. return false;
  44. }
  45. }
  46. public function getInfo($adminId){
  47. $redis = Redis::instance();
  48. $key = 'AE:'.$adminId;
  49. if($redis->exists($key)){
  50. $info = $redis->hgetall($key);
  51. if (!array_key_exists('benefit_app', $info)) {
  52. $redis->del($key);
  53. return $this->getInfo($adminId);
  54. }
  55. }else{
  56. $info = $this->where('admin_id',$adminId)->find();
  57. if($info){
  58. $info = $info->toArray();
  59. $redis->hmset($key,$info);
  60. $redis->expire($key,86400);
  61. }else{
  62. $info = null;
  63. }
  64. }
  65. return $info;
  66. }
  67. /**
  68. * 获取对应的渠道
  69. * @param $channel_id
  70. * @return mixed
  71. */
  72. public function getChannelId($channel_id)
  73. {
  74. $adminInfo = $this->getInfo($channel_id);
  75. if ($adminInfo['distribute']) {
  76. return $adminInfo['create_by'];
  77. } else {
  78. return $adminInfo['admin_id'];
  79. }
  80. }
  81. }