User.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * Created by JetBrains PhpStorm.
  4. * User: charlie
  5. * Date: 13-11-29
  6. * Time: 下午4:47
  7. * To change this template use File | Settings | File Templates.
  8. */
  9. class User extends MongoAr
  10. {
  11. public $_id;
  12. public $email = ''; //邮箱
  13. public $name = ''; //姓名or用户名
  14. public $id_num = '' ;
  15. public $pass = ''; //密码
  16. public $status = 0; //状态
  17. public $reg_time = 0; //注册时间
  18. public $last_login = 0; //上次登陆时间
  19. public $login_times = 0; //登陆次数
  20. public $type = 1; //类型
  21. public $fake_users = array();
  22. public $scheme; // 提成方案
  23. public $service_type;//array(1, 2, 3);
  24. public $coverage;//array() 服务范围 array(array('provice'=>'上海市', 'city'=> '上海市', 'area'=>'静安区', points=>array()));
  25. public $is_member; // 是否为企业微信成员,默认为否
  26. public $userid; // 企业微信号内部ID
  27. public $wx_info; // 微信信息
  28. /*
  29. $wx_info = array(
  30. 'name' => '张三', // 企业内部姓名
  31. 'department' => [1, 2], // 所属部门
  32. 'position' => '技术', // 职位
  33. 'mobile' => '13012345678', // 用户手机,唯一
  34. 'weixinid' => 'zhangsandeweixin', // 成员微信号
  35. 'gender' => 1, // 性别
  36. );
  37. */
  38. public static $status_option = array(
  39. 1 => array('name' => '正常', 'color' => 'green', 'wx' => 1),
  40. 0 => array('name' => '待审核', 'color' => 'blue', 'wx' => -1),
  41. -1 => array('name' => '已删除', 'color' => 'red', 'wx' => 0)
  42. );
  43. public static $is_member_option = array(
  44. 0 => array('name' => '否'),
  45. 1 => array('name' => '是'),
  46. );
  47. public static $gender_option = array(
  48. 0 => array('name' => '未填写'),
  49. 1 => array('name' => '男'),
  50. 2 => array('name' => '女'),
  51. );
  52. public static function model($className=__CLASS__)
  53. {
  54. return parent::model($className);
  55. }
  56. public function getCollectionName()
  57. {
  58. return 'users';
  59. }
  60. public static function get($_id) {
  61. $criteria = new EMongoCriteria();
  62. $criteria->_id('==', $_id);
  63. $model = self::model()->find($criteria);
  64. if ($model) {
  65. return $model;
  66. } else {
  67. return false;
  68. }
  69. }
  70. public static function getAdminByFakeUserId($fake_user_id){
  71. $criteria = new EMongoCriteria();
  72. $criteria->fake_users('==', $fake_user_id);
  73. $model = self::model()->find($criteria);
  74. if ($model) {
  75. return $model;
  76. } else {
  77. return false;
  78. }
  79. }
  80. /**
  81. * UserModel整理函数
  82. * @author 2015-11-31
  83. */
  84. public function parseRow($row, $output=array()) {
  85. $newRow = array();
  86. // 基本信息
  87. $newRow['_id'] = (string)$row['_id'];
  88. $newRow['email'] = CommonFn::get_val_if_isset($row, 'email', '');
  89. $newRow['name'] = CommonFn::get_val_if_isset($row, 'name', '');
  90. $newRow['id_num'] = CommonFn::get_val_if_isset($row, 'id_num', '');
  91. $newRow['pass'] = CommonFn::get_val_if_isset($row, 'pass', '');
  92. $newRow['status'] = CommonFn::get_val_if_isset($row, 'status', 1);
  93. $reg_time = CommonFn::get_val_if_isset($row, 'reg_time', 0);
  94. $newRow['reg_time'] = $reg_time != 0 ? date('Y-m-d H:i', $reg_time) : '';
  95. $last_login = CommonFn::get_val_if_isset($row, 'last_login', 0);
  96. $newRow['last_login'] = $last_login != 0 ? date('Y-m-d H:i', $newRow['last_login']) : '';
  97. $newRow['login_times'] = CommonFn::get_val_if_isset($row, 'login_times', 0);
  98. $newRow['type'] = CommonFn::get_val_if_isset($row, 'type', 1);
  99. $newRow['fake_users'] = CommonFn::get_val_if_isset($row, 'fake_users', array());
  100. $newRow['member_enable'] = CommonFn::get_val_if_isset($row, 'member_enable', -1);
  101. $newRow['userid'] = CommonFn::get_val_if_isset($row, 'userid', '');
  102. $newRow['wx_info'] = CommonFn::get_val_if_isset($row, 'wx_info', array());
  103. // 提成方案
  104. $newRow['scheme_str'] = CommonFn::get_val_if_isset($row, 'scheme', '');
  105. $scheme_option = Commision::$scheme_option;
  106. $newRow['scheme'] = -1;
  107. foreach ($scheme_option as $key => $value) {
  108. if ($value['alias'] == $newRow['scheme_str']) {
  109. $newRow['scheme'] = $key;
  110. }
  111. }
  112. // 微信信息
  113. $newRow['is_member'] = CommonFn::get_val_if_isset($row, 'is_member', 0);
  114. $wx_info = $newRow['wx_info'];
  115. $newRow['wx_name'] = CommonFn::get_val_if_isset($wx_info, 'name', '');
  116. $newRow['department'] = CommonFn::get_val_if_isset($wx_info, 'department', array());
  117. $newRow['position'] = CommonFn::get_val_if_isset($wx_info, 'position', array());
  118. $newRow['mobile'] = CommonFn::get_val_if_isset($wx_info, 'mobile', '');
  119. $newRow['weixinid'] = CommonFn::get_val_if_isset($wx_info, 'weixinid', '');
  120. $newRow['gender'] = CommonFn::get_val_if_isset($wx_info, 'gender', 0);
  121. // 编辑信息
  122. $newRow['action_user'] = CommonFn::get_val_if_isset($row,'action_user',"");
  123. $newRow['action_time'] = CommonFn::get_val_if_isset($row,'action_time',"");
  124. $newRow['action_log'] = CommonFn::get_val_if_isset($row,'action_log',"");
  125. // 后台角色
  126. $auth = Yii::app()->authManager;
  127. $roles = array_keys($auth->getAuthAssignments($newRow['_id']));
  128. $newRow['role'] = implode(',', $roles);
  129. // 服务类型
  130. $newRow['service_type'] = CommonFn::get_val_if_isset($row, 'service_type', array());
  131. // 服务范围
  132. $newRow['coverage'] = CommonFn::get_val_if_isset($row, 'coverage', array());
  133. return $this->output($newRow, $output);
  134. }
  135. }