Agent.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. use think\Db;
  5. use think\Exception;
  6. class Agent extends Model
  7. {
  8. // 表名
  9. protected $name = 'user';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = 'int';
  12. // 定义时间戳字段名
  13. protected $createTime = 'createtime';
  14. protected $updateTime = false;
  15. protected $deleteTime = false;
  16. // 追加属性
  17. protected $append = [
  18. 'yaoqingtime_text',
  19. 'gender_text',
  20. 'idcard_status_text',
  21. 'real_status_text',
  22. 'logintime_text',
  23. 'jointime_text',
  24. 'status_text',
  25. 'hide_is_finishinfo_text',
  26. 'is_active_text',
  27. 'open_match_video_text',
  28. 'open_match_audio_text',
  29. 'jinyantime_text',
  30. 'jinyantype_text',
  31. 'is_shouchong_text'
  32. ];
  33. protected static function init()
  34. {
  35. self::beforeUpdate(function ($row) {
  36. //检验 超推上级UID ,intro_uid
  37. if (isset($row['intro_uid'])) {
  38. if ($row['intro_uid']) {
  39. if($row['invite_uid']){
  40. throw new Exception('超推网上级UID 与 直推上级UID 不能共存');
  41. }
  42. $intro_info = Db::name('user')->where('id',$row['intro_uid'])->find();
  43. if(empty($intro_info)){
  44. throw new Exception('不存在的 超推网上级UID用户');
  45. }
  46. if($intro_info['group_id'] == 1){
  47. throw new Exception('超推网上级UID用户 不能是普通用户');
  48. }
  49. }
  50. }
  51. //检验二级超推
  52. if($row['group_id'] == 2){
  53. if(!$row['agent_id']){
  54. throw new Exception('二级超推必须填写 上级一级代理UID');
  55. }
  56. $agent_info = Db::name('user')->where('group_id',3)->where('id',$row['agent_id'])->find();
  57. if(empty($agent_info)){
  58. throw new Exception('不存在的 上级一级代理UID用户');
  59. }
  60. }else{
  61. $row['agent_id'] = '';
  62. }
  63. //检验 直推上级UID ,invite_uid
  64. if (isset($row['invite_uid'])) {
  65. if ($row['invite_uid']) {
  66. if($row['intro_uid']){
  67. throw new Exception('超推网上级UID 与 直推上级UID 不能共存');
  68. }
  69. $invite_info = Db::name('user')->where('id',$row['invite_uid'])->find();
  70. if(empty($invite_info)){
  71. throw new Exception('不存在的 直推上级UID用户');
  72. }
  73. }
  74. }
  75. });
  76. }
  77. public function getGenderList()
  78. {
  79. return ['-1' => __('Gender -1'), '1' => __('Gender 1'), '0' => __('Gender 0')];
  80. }
  81. public function getIdcardStatusList()
  82. {
  83. return ['-1' => __('Idcard_status -1'), '0' => __('Idcard_status 0'), '1' => __('Idcard_status 1'), '2' => __('Idcard_status 2')];
  84. }
  85. public function getRealStatusList()
  86. {
  87. return ['-1' => __('Real_status -1'), '0' => __('Real_status 0'), '1' => __('Real_status 1'), '2' => __('Real_status 2')];
  88. }
  89. public function getStatusList()
  90. {
  91. return ['1' => __('Status 1'), '0' => __('Status 0'), '-1' => __('Status -1')];
  92. }
  93. public function getHideIsFinishinfoList()
  94. {
  95. return ['1' => __('Hide_is_finishinfo 1'), '0' => __('Hide_is_finishinfo 0')];
  96. }
  97. public function getIsActiveList()
  98. {
  99. return ['1' => __('Is_active 1'), '0' => __('Is_active 0')];
  100. }
  101. public function getOpenMatchVideoList()
  102. {
  103. return ['1' => __('Open_match_video 1'), '0' => __('Open_match_video 0')];
  104. }
  105. public function getOpenMatchAudioList()
  106. {
  107. return ['1' => __('Open_match_audio 1'), '0' => __('Open_match_audio 0')];
  108. }
  109. public function getJinyantypeList()
  110. {
  111. return ['1' => __('Jinyantype 1'), '2' => __('Jinyantype 2'), '3' => __('Jinyantype 3')];
  112. }
  113. public function getIsShouchongList()
  114. {
  115. return ['0' => __('Is_shouchong 0'), '1' => __('Is_shouchong 1')];
  116. }
  117. public function getYaoqingtimeTextAttr($value, $data)
  118. {
  119. $value = $value ? $value : (isset($data['yaoqingtime']) ? $data['yaoqingtime'] : '');
  120. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  121. }
  122. public function getGenderTextAttr($value, $data)
  123. {
  124. $value = $value ? $value : (isset($data['gender']) ? $data['gender'] : '');
  125. $list = $this->getGenderList();
  126. return isset($list[$value]) ? $list[$value] : '';
  127. }
  128. public function getIdcardStatusTextAttr($value, $data)
  129. {
  130. $value = $value ? $value : (isset($data['idcard_status']) ? $data['idcard_status'] : '');
  131. $list = $this->getIdcardStatusList();
  132. return isset($list[$value]) ? $list[$value] : '';
  133. }
  134. public function getRealStatusTextAttr($value, $data)
  135. {
  136. $value = $value ? $value : (isset($data['real_status']) ? $data['real_status'] : '');
  137. $list = $this->getRealStatusList();
  138. return isset($list[$value]) ? $list[$value] : '';
  139. }
  140. public function getLogintimeTextAttr($value, $data)
  141. {
  142. $value = $value ? $value : (isset($data['logintime']) ? $data['logintime'] : '');
  143. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  144. }
  145. public function getJointimeTextAttr($value, $data)
  146. {
  147. $value = $value ? $value : (isset($data['jointime']) ? $data['jointime'] : '');
  148. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  149. }
  150. public function getStatusTextAttr($value, $data)
  151. {
  152. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  153. $list = $this->getStatusList();
  154. return isset($list[$value]) ? $list[$value] : '';
  155. }
  156. public function getHideIsFinishinfoTextAttr($value, $data)
  157. {
  158. $value = $value ? $value : (isset($data['hide_is_finishinfo']) ? $data['hide_is_finishinfo'] : '');
  159. $list = $this->getHideIsFinishinfoList();
  160. return isset($list[$value]) ? $list[$value] : '';
  161. }
  162. public function getIsActiveTextAttr($value, $data)
  163. {
  164. $value = $value ? $value : (isset($data['is_active']) ? $data['is_active'] : '');
  165. $list = $this->getIsActiveList();
  166. return isset($list[$value]) ? $list[$value] : '';
  167. }
  168. public function getOpenMatchVideoTextAttr($value, $data)
  169. {
  170. $value = $value ? $value : (isset($data['open_match_video']) ? $data['open_match_video'] : '');
  171. $list = $this->getOpenMatchVideoList();
  172. return isset($list[$value]) ? $list[$value] : '';
  173. }
  174. public function getOpenMatchAudioTextAttr($value, $data)
  175. {
  176. $value = $value ? $value : (isset($data['open_match_audio']) ? $data['open_match_audio'] : '');
  177. $list = $this->getOpenMatchAudioList();
  178. return isset($list[$value]) ? $list[$value] : '';
  179. }
  180. public function getJinyantimeTextAttr($value, $data)
  181. {
  182. $value = $value ? $value : (isset($data['jinyantime']) ? $data['jinyantime'] : '');
  183. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  184. }
  185. public function getJinyantypeTextAttr($value, $data)
  186. {
  187. $value = $value ? $value : (isset($data['jinyantype']) ? $data['jinyantype'] : '');
  188. $list = $this->getJinyantypeList();
  189. return isset($list[$value]) ? $list[$value] : '';
  190. }
  191. public function getIsShouchongTextAttr($value, $data)
  192. {
  193. $value = $value ? $value : (isset($data['is_shouchong']) ? $data['is_shouchong'] : '');
  194. $list = $this->getIsShouchongList();
  195. return isset($list[$value]) ? $list[$value] : '';
  196. }
  197. protected function setYaoqingtimeAttr($value)
  198. {
  199. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  200. }
  201. protected function setLogintimeAttr($value)
  202. {
  203. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  204. }
  205. protected function setJointimeAttr($value)
  206. {
  207. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  208. }
  209. protected function setJinyantimeAttr($value)
  210. {
  211. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  212. }
  213. public function usergroup()
  214. {
  215. return $this->belongsTo('UserGroup', 'group_id', 'id', [], 'LEFT')->setEagerlyType(0);
  216. }
  217. public function userwallet()
  218. {
  219. return $this->belongsTo('Userwallet', 'id', 'user_id', [], 'LEFT')->setEagerlyType(0);
  220. }
  221. }