BaUserList.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. namespace backendApi\modules\v1\models\lists\user;
  3. use common\helpers\Cache;
  4. use common\helpers\http\BackendToFrontendApi;
  5. use common\helpers\LoggerTool;
  6. use common\helpers\user\Info;
  7. use common\libs\dataList\DataListInterface;
  8. use common\models\BaUser;
  9. use common\models\BaUserInfo;
  10. use common\models\DecRole;
  11. use common\models\OpenBank;
  12. use common\models\Region;
  13. use common\models\User;
  14. use common\models\UserInfo;
  15. use common\libs\dataList\column\DateTime;
  16. use common\libs\dataList\column\YesNo;
  17. use common\models\UserNetwork;
  18. use common\models\UserSystem;
  19. use Yii;
  20. class BaUserList extends \common\libs\dataList\DataList implements DataListInterface
  21. {
  22. /**
  23. * 列表名称
  24. * @return string
  25. */
  26. public function getListName(){
  27. return 'Brand Ambassador List';
  28. }
  29. /**
  30. * 列表筛选到的数据
  31. */
  32. public function dataHandle()
  33. {
  34. $this->condition .= ' AND UN.USER_ID=UI.USER_ID AND UN.PARENT_UID=UI.CON_UID';
  35. $this->listData = BaUser::lists($this->condition, $this->params, [
  36. 'select' => 'U.*,
  37. UI.USER_ID, UI.ZC_PV, UI.CON_UID, UI.REC_UID, UI.CON_NUM, UI.REC_NUM, UI.NETWORK_DEEP,
  38. UI.RELATION_DEEP, UI.SYSTEM_ID, UI.IS_GROUP_LEADER, UI.IS_SYSTEM_LEADER, UI.IS_TEAM, UI.IS_BIND,
  39. UI.IS_TEAM_MAIN, UI.IS_BIND_MAIN, UI.IS_AUTO_WITHDRAW, UI.CLOSE_LOGIN, UI.REG_TYPE, UI.SHOULD_REG_TYPE,
  40. UI.REG_NAME, UI.CREDIT_CODE, UI.PREMISES, UI.LEGAL_PERSON, UI.REG_EXPIRES, UI.STORE_TYPE, UI.INVOICE_BALANCE,
  41. UI.HIGHEST_EMP_LV, UI.CLOSE_LOGIN_AT, UI.PULLED_AT,
  42. UI.GROUP_LEADER_AT, UI.ALLOW_TRANSFER, UI.ALLOW_RECONSUME_SMS, UI.ALLOW_RECONSUME_SMS_TO,
  43. UI.HIGHEST_EMP_LV_PERIOD, UI.TRANSFER_PROP, UI.LOGIN_NUMS, UI.FAIL_NUMS, UI.LAST_LOGIN_IP,
  44. UI.LAST_LOGIN_AT, UI.SHOW_EMP_LV,UN.RELATIVE_LOCATION
  45. ',
  46. // CU.USER_NAME CON_USER_NAME,CU.REAL_NAME CON_REAL_NAME,
  47. // RU.USER_NAME REC_USER_NAME,RU.REAL_NAME REC_REAL_NAME,
  48. // DU.USER_NAME DEC_USER_NAME
  49. 'orderBy' => 'UI.CREATED_AT DESC, UI.ID DESC',
  50. 'from' => BaUser::tableName() . ' AS U',
  51. 'join' => [
  52. ['LEFT JOIN', BaUserInfo::tableName() . ' AS UI', 'UI.USER_ID=U.ID'],
  53. ['LEFT JOIN', UserNetwork::tableName() . ' AS UN', 'UI.USER_ID=UN.USER_ID'],
  54. ['LEFT JOIN', User::tableName() . ' AS CU', 'UI.CON_UID=CU.ID'],
  55. ['LEFT JOIN', User::tableName() . ' AS RU', 'UI.REC_UID=RU.ID'],
  56. ['LEFT JOIN', User::tableName() . ' AS DU', 'U.DEC_ID=DU.ID'],
  57. ],
  58. 'page' => $this->page,
  59. 'pageSize' => $this->pageSize,
  60. ]);
  61. foreach ($this->listData['list'] as $key => $value) {
  62. // 后台访问前台的请求参数
  63. if (!$this->isExport && Yii::$app->user->validateAdminAction('user', 'login-to-frontend')) {
  64. $urlParams = BackendToFrontendApi::paramsFormat(['id' => $value['USER_ID']]);
  65. $urlParamStr = '';
  66. foreach ($urlParams as $pKey => $pValue) {
  67. $urlParamStr .= $pKey . '=' . $pValue . '&';
  68. }
  69. $urlParamStr = substr($urlParamStr, 0, -1);
  70. $this->listData['list'][$key]['BTF_URL'] = $urlParamStr;
  71. } else {
  72. $this->listData['list'][$key]['BTF_URL'] = null;
  73. }
  74. }
  75. }
  76. /**
  77. * 要展示和导出的所有字段
  78. * @return array
  79. */
  80. public function getColumn()
  81. {
  82. $regionConfig = Cache::getRegionConfig();
  83. if(!$this->columns){
  84. $this->columns = [
  85. 'USER_ID' => null, // 这种传输方式主要是用于索引,因为过滤后的字段可能没有这种ID,但是一些功能的操作还需要用这种ID去关联,例如前台会员列表中的勾选批量状态管理,这里需要的就是USER_ID
  86. 'BTF_URL' => null,
  87. 'USER_NAME' => [
  88. 'header' => 'Member Code', // 会员编号
  89. 'headerOther' => ['width' => '150'],
  90. ],
  91. 'REAL_NAME' => [
  92. 'header' => 'Member Name', // 会员姓名
  93. 'headerOther' => [
  94. 'width' => '120',
  95. ],
  96. 'valueOther' => [
  97. 'tag'=>['type'=>'success', 'size' => 'small', 'class'=>'no-border']
  98. ],
  99. ],
  100. 'LOGIN_STATUS_NAME' => [
  101. 'header' => 'Login Status', // 登录状态
  102. 'value' => function($row) {
  103. return $row['ALLOW_LOGIN'] == 1 ? 'Allow Login': 'Prohibit Login'; // '允许登录' : '禁止登录'
  104. },
  105. 'headerOther' => ['width' => '110'],
  106. ],
  107. 'STATUS' => [
  108. 'header' => 'Status', // 状态
  109. 'value' => function($row) {
  110. return $row['STATUS'] == 1 ? 'Activate': 'Lock'; // '激活' : '锁定'
  111. },
  112. 'headerOther' => ['width' => '110'],
  113. ],
  114. 'ALLOW_LOGIN' => ['header' => 'Filter Allow Login','hidden'=>true], // 筛选允许登录
  115. 'CREATED_AT' => [
  116. 'header' => 'Joining Date', // 加入日期
  117. 'value' => function($row) {
  118. return (new DateTime([
  119. 'value' => $row['CREATED_AT'],
  120. ]))->result();
  121. },
  122. 'headerOther' => ['width' => '170'],
  123. ],
  124. 'PERIOD_AT' => [
  125. 'header' => 'Joining Period', // 加入期数
  126. 'headerOther' => ['width' => '180'],
  127. ],
  128. 'REC_USER_NAME' => [
  129. 'header' => 'Recommendation No', // 推荐编号
  130. 'headerOther' => ['width' => '160'],
  131. ],
  132. 'REC_REAL_NAME' => [
  133. 'header' => 'Recommended Name', // 推荐姓名
  134. 'headerOther' => ['width' => '160'],
  135. ],
  136. 'MOBILE' => [
  137. 'header' => 'Phone Number', // 手机号码
  138. 'value' => function($row) {
  139. return "\t".$row['MOBILE'];
  140. },
  141. 'headerOther' => ['width' => '120'],
  142. ],
  143. 'TEL' => [
  144. 'header' => 'Alternate Phone Number', // 备用手机号码
  145. 'value' => function($row) {
  146. return "\t".$row['TEL'];
  147. },
  148. 'headerOther' => ['width' => '180'],
  149. ],
  150. 'AREA' => [
  151. 'header' => 'Common Address', // 常用地址
  152. 'value' => function($row) use($regionConfig) {
  153. $province = $regionConfig[$row['PROVINCE']]['REGION_NAME'] ?? '';
  154. $city = $regionConfig[$row['CITY']]['REGION_NAME'] ?? '';
  155. $county = $regionConfig[$row['COUNTY']]['REGION_NAME'] ?? '';
  156. return $province.$city.$county;
  157. },
  158. 'showValue' => function($row) {
  159. $province = $regionConfig[$row['PROVINCE']]['REGION_NAME'] ?? '';
  160. $city = $regionConfig[$row['CITY']]['REGION_NAME'] ?? '';
  161. $county = $regionConfig[$row['COUNTY']]['REGION_NAME'] ?? '';
  162. return '<div class="addr" title='.$province.$city.$county.'>'.$province.$city.$county.'</div>';
  163. },
  164. 'headerOther' => [
  165. 'width' => '200'
  166. ],
  167. ],
  168. ];
  169. }
  170. return $this->columns;
  171. }
  172. /**
  173. * 前台用于筛选的类型集合
  174. * @return mixed
  175. */
  176. public function getFilterTypes()
  177. {
  178. if(!$this->filterTypes){
  179. $this->filterTypes = [
  180. 'USER_NAME'=> ['name'=> 'Member code'], // 会员编号
  181. 'REAL_NAME'=> ['name'=> 'Member name'], // 会员姓名
  182. 'CREATED_AT'=> ['name'=> 'Joining Date', 'other'=> 'date'], // 加入日期
  183. 'PERIOD_AT'=> ['name'=> 'Joining Period'], // 加入期数
  184. 'REC_USER_NAME'=> ['name'=> 'Recommendation No'],//推荐编号
  185. 'MOBILE'=> ['name'=> 'Phone Number'],//手机号码
  186. 'AREA'=> ['name'=> 'Common address', 'other'=> 'area'],//常用地址
  187. 'STATUS'=> ['name'=> 'Active status', 'other'=> 'select', 'selectData'=> [['id'=> 0, 'name'=> 'locking'],['id'=> 1, 'name'=> 'activation']]],
  188. ];
  189. }
  190. return $this->filterTypes;
  191. }
  192. }