IndexList.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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\user\Info;
  6. use common\libs\dataList\DataListInterface;
  7. use common\models\Countries;
  8. use common\models\DecRole;
  9. use common\models\EmployLevel;
  10. use common\models\Language;
  11. use common\models\OpenBank;
  12. use common\models\Region;
  13. use common\models\StarCrownLevel;
  14. use common\models\User;
  15. use common\models\UserInfo;
  16. use common\libs\dataList\column\DateTime;
  17. use common\libs\dataList\column\YesNo;
  18. use common\models\UserNetwork;
  19. use common\models\UserSystem;
  20. use Yii;
  21. class IndexList extends \common\libs\dataList\DataList implements DataListInterface
  22. {
  23. /**
  24. * 列表名称
  25. * @return string
  26. */
  27. public function getListName(){
  28. return '会员列表';
  29. }
  30. /**
  31. * 列表筛选到的数据
  32. */
  33. public function dataHandle()
  34. {
  35. $this->condition .= ' AND UN.USER_ID=UI.USER_ID AND UN.PARENT_UID=UI.CON_UID';
  36. $this->listData = User::lists($this->condition, $this->params, [
  37. 'select' => 'U.*,
  38. UI.USER_ID, UI.ZC_PV, UI.CON_UID, UI.CON_UID_ACTUAL, UI.REC_UID, UI.CON_NUM, UI.REC_NUM, UI.NETWORK_DEEP,
  39. UI.RELATION_DEEP, UI.SYSTEM_ID, UI.IS_GROUP_LEADER, UI.IS_SYSTEM_LEADER, UI.IS_TEAM, UI.IS_BIND,
  40. UI.IS_TEAM_MAIN, UI.IS_BIND_MAIN, UI.IS_AUTO_WITHDRAW, UI.CLOSE_LOGIN, UI.REG_TYPE, UI.SHOULD_REG_TYPE,
  41. UI.REG_NAME, UI.CREDIT_CODE, UI.PREMISES, UI.LEGAL_PERSON, UI.REG_EXPIRES, UI.STORE_TYPE, UI.INVOICE_BALANCE,
  42. UI.HIGHEST_EMP_LV, UI.CLOSE_LOGIN_AT, UI.PULLED_AT,
  43. UI.GROUP_LEADER_AT, UI.ALLOW_TRANSFER, UI.ALLOW_RECONSUME_SMS, UI.ALLOW_RECONSUME_SMS_TO,
  44. UI.HIGHEST_EMP_LV_PERIOD, UI.TRANSFER_PROP, UI.LOGIN_NUMS, UI.FAIL_NUMS, UI.LAST_LOGIN_IP,
  45. UI.LAST_LOGIN_AT, UI.SHOW_EMP_LV,UN.RELATIVE_LOCATION,
  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. CS.NAME COUNTRY,
  50. LG.NAME LANGUAGE
  51. ',
  52. 'orderBy' => 'UI.CREATED_AT DESC, UI.ID DESC',
  53. 'from' => User::tableName() . ' AS U',
  54. 'join' => [
  55. ['LEFT JOIN', UserInfo::tableName() . ' AS UI', 'UI.USER_ID=U.ID'],
  56. ['LEFT JOIN', UserNetwork::tableName() . ' AS UN', 'UI.USER_ID=UN.USER_ID'],
  57. ['LEFT JOIN', User::tableName() . ' AS CU', 'UI.CON_UID=CU.ID'],
  58. ['LEFT JOIN', User::tableName() . ' AS RU', 'UI.REC_UID=RU.ID'],
  59. ['LEFT JOIN', User::tableName() . ' AS DU', 'U.DEC_ID=DU.ID'],
  60. ['LEFT JOIN', Countries::tableName() . ' AS CS', 'U.COUNTRY_ID=CS.ID'],
  61. ['LEFT JOIN', Language::tableName() . ' AS LG', 'U.LANGUAGE_ID=LG.ID'],
  62. ],
  63. 'page' => $this->page,
  64. 'pageSize' => $this->pageSize,
  65. ]);
  66. foreach ($this->listData['list'] as $key => $value) {
  67. // 后台访问前台的请求参数
  68. if (!$this->isExport && Yii::$app->user->validateAdminAction('user', 'login-to-frontend')) {
  69. $urlParams = BackendToFrontendApi::paramsFormat(['id' => $value['USER_ID']]);
  70. $urlParamStr = '';
  71. foreach ($urlParams as $pKey => $pValue) {
  72. $urlParamStr .= $pKey . '=' . $pValue . '&';
  73. }
  74. $urlParamStr = substr($urlParamStr, 0, -1);
  75. $this->listData['list'][$key]['BTF_URL'] = $urlParamStr;
  76. } else {
  77. $this->listData['list'][$key]['BTF_URL'] = null;
  78. }
  79. $conActual = User::getBaseInfo($value['CON_UID_ACTUAL']);
  80. $this->listData['list'][$key]['CON_USER_NAME_ACTUAL'] = $conActual['USER_NAME'] ?? '';
  81. $this->listData['list'][$key]['CON_REAL_NAME_ACTUAL'] = $conActual['REAL_NAME'] ?? '';
  82. }
  83. }
  84. /**
  85. * 要展示和导出的所有字段
  86. * @return array
  87. */
  88. public function getColumn(){
  89. $decLevelConfig = Cache::getDecLevelConfig();
  90. $empLevelConfig = Cache::getEmpLevelConfig();
  91. $crownLevelConfig = Cache::getStarCrownLevelConfig();
  92. $decRoleConfig = DecRole::getAllData();
  93. $systemConfig = UserSystem::getAllSystems();
  94. $openBankConfig = OpenBank::getAllOpenBank();
  95. $regionConfig = Cache::getRegionConfig();
  96. if(!$this->columns){
  97. $this->columns = [
  98. 'USER_ID' => null, // 这种传输方式主要是用于索引,因为过滤后的字段可能没有这种ID,但是一些功能的操作还需要用这种ID去关联,例如前台会员列表中的勾选批量状态管理,这里需要的就是USER_ID
  99. 'BTF_URL' => null,
  100. 'USER_NAME' => [
  101. 'header' => Yii::t('ctx', 'memberCode'),
  102. 'headerOther' => ['width' => '150'],
  103. ],
  104. 'REAL_NAME' => [
  105. 'header' => Yii::t('ctx', 'memberName'),
  106. 'headerOther' => [
  107. 'width' => '120',
  108. ],
  109. 'valueOther' => [
  110. 'tag'=>['type'=>'success', 'size' => 'small', 'class'=>'no-border']
  111. ],
  112. ],
  113. 'LOGIN_STATUS_NAME' => [
  114. 'header' => Yii::t('ctx', 'loginStatus'),
  115. 'value' => function($row) {
  116. return $row['ALLOW_LOGIN'] == 1 ? Yii::t('ctx', 'allowLogin') : Yii::t('ctx', 'prohibitLogin');
  117. },
  118. 'headerOther' => ['width' => '110'],
  119. ],
  120. 'STATUS' => [
  121. 'header' => Yii::t('ctx', 'status'),
  122. 'value' => function($row) {
  123. return $row['STATUS'] == 1 ? Yii::t('ctx', 'activate') : Yii::t('ctx', 'lock');
  124. },
  125. 'headerOther' => ['width' => '110'],
  126. ],
  127. 'COUNTRY' => [
  128. 'header' => Yii::t('ctx', 'country'),
  129. 'headerOther' => ['width' => '110'],
  130. ],
  131. // 'ALLOW_LOGIN' => [
  132. // 'header' => Yii::t('ctx', 'filterAllowLogin'),
  133. // 'value' => function($row) {
  134. // return $row['ALLOW_LOGIN'] == 1 ? Yii::t('ctx', 'allowLogin') : Yii::t('ctx', 'prohibitLogin');
  135. // },
  136. // ],
  137. 'CREATED_AT' => [
  138. 'header' => Yii::t('ctx', 'joiningDate'),
  139. 'value' => function($row) {
  140. return (new DateTime([
  141. 'value' => $row['CREATED_AT'],
  142. ]))->result();
  143. },
  144. 'headerOther' => ['width' => '170'],
  145. ],
  146. 'PERIOD_AT' => [
  147. 'header' => Yii::t('ctx', 'joiningPeriod'),
  148. 'headerOther' => ['width' => '180'],
  149. ],
  150. 'DEC_LV_NAME' => [
  151. 'header' => Yii::t('ctx', 'currentMemberLevel'),
  152. 'headerOther' => ['width' => '160'],
  153. 'value' => function($row) use($decLevelConfig) {
  154. return $decLevelConfig[$row['DEC_LV']]['LEVEL_NAME'];
  155. },
  156. 'valueOther' => [
  157. 'tag'=>['type'=>'warning', 'size' => 'small', 'class'=>'no-border']
  158. ],
  159. ],
  160. 'DEC_LV_UPDATED_AT' => [
  161. 'header' => Yii::t('ctx', 'currentAdjustmentDate'),
  162. 'value' => function($row) {
  163. return (new DateTime([
  164. 'value' => $row['DEC_LV_UPDATED_AT'],
  165. ]))->result();
  166. },
  167. 'headerOther' => ['width' => '180'],
  168. ],
  169. 'LAST_DEC_LV_NAME' => [
  170. 'header' => Yii::t('ctx', 'PCMemberLevel'),
  171. 'headerOther' => [
  172. 'width' => '140',
  173. ],
  174. 'value' => function($row) use($decLevelConfig) {
  175. if (!$row['LAST_DEC_LV']) {
  176. return $decLevelConfig[$row['DEC_LV']]['LEVEL_NAME'];
  177. } else {
  178. return $decLevelConfig[$row['LAST_DEC_LV']]['LEVEL_NAME'];
  179. }
  180. },
  181. 'valueOther' => [
  182. 'tag'=>['type'=>'warning', 'size' => 'small', 'class'=>'no-border']
  183. ],
  184. ],
  185. 'EMP_LV_NAME' => [
  186. 'header' => Yii::t('ctx', 'highestDirector'),
  187. 'headerOther' => [
  188. 'width' => '190',
  189. ],
  190. 'value' => function($row) use($empLevelConfig) {
  191. return isset($empLevelConfig[$row['EMP_LV']]) ? $empLevelConfig[$row['EMP_LV']]['LEVEL_NAME'] : $empLevelConfig[EmployLevel::getDefaultLevelId()]['LEVEL_NAME'];
  192. },
  193. 'valueOther' => [
  194. 'tag'=>['type'=>'warning', 'size' => 'small', 'class'=>'no-border']
  195. ],
  196. ],
  197. 'LAST_EMP_LV_NAME' => [
  198. 'header' => Yii::t('ctx', 'latestDirector'),
  199. 'headerOther' => [
  200. 'width' => '190',
  201. ],
  202. 'value' => function($row) use($empLevelConfig) {
  203. return isset($empLevelConfig[$row['LAST_EMP_LV']]) ? $empLevelConfig[$row['LAST_EMP_LV']]['LEVEL_NAME'] : $empLevelConfig[EmployLevel::getDefaultLevelId()]['LEVEL_NAME'];
  204. },
  205. 'valueOther' => [
  206. 'tag'=>['type'=>'warning', 'size' => 'small', 'class'=>'no-border']
  207. ],
  208. ],
  209. 'CROWN_LV_NAME' => [
  210. 'header' => Yii::t('ctx', 'highestCrown'),
  211. 'headerOther' => [
  212. 'width' => '180',
  213. ],
  214. 'value' => function($row) use($crownLevelConfig) {
  215. return isset($crownLevelConfig[$row['CROWN_LV']]) ? $crownLevelConfig[$row['CROWN_LV']]['LEVEL_NAME'] : $crownLevelConfig[StarCrownLevel::getDefaultLevelId()]['LEVEL_NAME'];
  216. },
  217. 'valueOther' => [
  218. 'tag'=>['type'=>'warning', 'size' => 'small', 'class'=>'no-border']
  219. ],
  220. ],
  221. 'LAST_CROWN_LV_NAME' => [
  222. 'header' => Yii::t('ctx', 'latestCrown'),
  223. 'headerOther' => [
  224. 'width' => '180',
  225. ],
  226. 'value' => function($row) use($crownLevelConfig) {
  227. return isset($crownLevelConfig[$row['LAST_CROWN_LV']]) ? $crownLevelConfig[$row['LAST_CROWN_LV']]['LEVEL_NAME'] : $crownLevelConfig[StarCrownLevel::getDefaultLevelId()]['LEVEL_NAME'];
  228. },
  229. 'valueOther' => [
  230. 'tag'=>['type'=>'warning', 'size' => 'small', 'class'=>'no-border']
  231. ],
  232. ],
  233. // 'REC_USER_NAME' => [
  234. // 'header' => Yii::t('ctx', 'recommendationNo'),
  235. // 'headerOther' => ['width' => '160'],
  236. // ],
  237. // 'REC_REAL_NAME' => [
  238. // 'header' => Yii::t('ctx', 'recommendedName'),
  239. // 'headerOther' => ['width' => '160'],
  240. // ],
  241. 'CON_USER_NAME_ACTUAL' => [
  242. 'header' => Yii::t('ctx', 'recommendationNo'),
  243. 'headerOther' => ['width' => '140'],
  244. ],
  245. 'CON_REAL_NAME_ACTUAL' => [
  246. 'header' => Yii::t('ctx', 'recommendedName'),
  247. 'headerOther' => ['width' => '140'],
  248. ],
  249. 'CON_USER_NAME' => [
  250. 'header' => Yii::t('ctx', 'placementNo'),
  251. 'headerOther' => ['width' => '140'],
  252. ],
  253. 'CON_REAL_NAME' => [
  254. 'header' => Yii::t('ctx', 'placementName'),
  255. 'headerOther' => ['width' => '140'],
  256. ],
  257. // 'RELATIVE_LOCATION' => [
  258. // 'header' => Yii::t('ctx', 'resettlementArea'),
  259. // 'headerOther' => ['width' => '140'],
  260. // ],
  261. 'MOBILE' => [
  262. 'header' => Yii::t('ctx', 'phoneNumber'),
  263. 'value' => function($row) {
  264. return "\t".$row['MOBILE'];
  265. },
  266. 'headerOther' => ['width' => '120'],
  267. ],
  268. 'TEL' => [
  269. 'header' => Yii::t('ctx', 'alternatePhoneNumber'),
  270. 'value' => function($row) {
  271. return "\t".$row['TEL'];
  272. },
  273. 'headerOther' => ['width' => '180'],
  274. ],
  275. 'DEC_USER_NAME' => [
  276. 'header' => Yii::t('ctx', 'stockistCode'),
  277. 'headerOther' => ['width' => '150'],
  278. ],
  279. 'IS_DEC' => [
  280. 'header' => Yii::t('ctx', 'whetherStockist'),
  281. 'value' => function($row) {
  282. return (new YesNo([
  283. 'value' => $row['IS_DEC'],
  284. ]))->result();
  285. },
  286. 'headerOther' => function($row) {
  287. return ['width' => '200'];
  288. },
  289. 'valueOther' => function($row) {
  290. return [
  291. 'tag'=>['type'=>(isset($row['IS_DEC']) && $row['IS_DEC'] )? 'success' : 'info', 'size' => 'small']
  292. ];
  293. },
  294. ],
  295. 'IS_ATLAS' => [
  296. 'header' => Yii::t('ctx', 'whetherChartDisplay'),
  297. 'value' => function($row) {
  298. return (new YesNo([
  299. 'value' => $row['IS_ATLAS'],
  300. ]))->result();
  301. },
  302. 'headerOther' => function($row) {
  303. return [
  304. 'width' => '160',
  305. ];
  306. },
  307. 'valueOther' => function($row) {
  308. return [
  309. 'tag'=>['type'=>(isset($row['IS_ATLAS']) && $row['IS_ATLAS'] )? 'success' : 'info', 'size' => 'small']
  310. ];
  311. },
  312. ],
  313. 'IS_RECHARGE' => [
  314. 'header' => Yii::t('ctx', 'whetherRechargeDisplay'),
  315. 'value' => function($row) {
  316. return (new YesNo([
  317. 'value' => $row['IS_RECHARGE'],
  318. ]))->result();
  319. },
  320. 'headerOther' => function($row) {
  321. return [
  322. 'width' => '180',
  323. ];
  324. },
  325. 'valueOther' => function($row) {
  326. return [
  327. 'tag'=>['type'=>(isset($row['IS_RECHARGE']) && $row['IS_RECHARGE'] )? 'success' : 'info', 'size' => 'small']
  328. ];
  329. },
  330. ],
  331. 'DEC_ROLE_NAME' => [
  332. 'header' => Yii::t('ctx', 'stockistLevel'),
  333. 'headerOther' => ['width' => '110'],
  334. 'value' => function($row) use($decRoleConfig) {
  335. return $decRoleConfig[$row['DEC_ROLE_ID']]['ROLE_NAME'] ?? '';
  336. },
  337. ],
  338. 'OPEN_BANK_NAME' => [
  339. 'header' => Yii::t('ctx', 'bankName'),
  340. 'headerOther' => ['width' => '110'],
  341. 'value' => function($row) use($openBankConfig) {
  342. return $openBankConfig[$row['OPEN_BANK']]['BANK_NAME'] ?? '';
  343. },
  344. ],
  345. 'BANK_NO' => [
  346. 'header' => Yii::t('ctx', 'bankAccountNumber'),
  347. 'headerOther' => ['width' => '220'],
  348. 'value' => function($row) {
  349. return "\t".$row['BANK_NO'];
  350. },
  351. ],
  352. 'AREA' => [
  353. 'header' => Yii::t('ctx', 'commonAddress'),
  354. 'value' => function($row) use($regionConfig) {
  355. $province = $regionConfig[$row['PROVINCE']]['REGION_NAME'] ?? '';
  356. $city = $regionConfig[$row['CITY']]['REGION_NAME'] ?? '';
  357. $county = $regionConfig[$row['COUNTY']]['REGION_NAME'] ?? '';
  358. return $province.$city.$county;
  359. },
  360. 'showValue' => function($row) {
  361. $province = $regionConfig[$row['PROVINCE']]['REGION_NAME'] ?? '';
  362. $city = $regionConfig[$row['CITY']]['REGION_NAME'] ?? '';
  363. $county = $regionConfig[$row['COUNTY']]['REGION_NAME'] ?? '';
  364. return '<div class="addr" title='.$province.$city.$county.'>'.$province.$city.$county.'</div>';
  365. },
  366. 'headerOther' => [
  367. 'width' => '200'
  368. ],
  369. ],
  370. 'ALLOW_TRANSFER' => [
  371. 'header' => Yii::t('ctx', 'enableTransfer'),
  372. 'value' => function($row) {
  373. return $row['ALLOW_TRANSFER'] == 1 ? Yii::t('ctx', 'on') : Yii::t('ctx', 'off');
  374. },
  375. 'headerOther' => function($row) {
  376. return [
  377. 'width' => '130',
  378. ];
  379. },
  380. 'valueOther' => function($row) {
  381. return [
  382. 'tag'=>['type'=>(isset($row['ALLOW_TRANSFER']) && $row['ALLOW_TRANSFER']) ? 'Success' : 'Info', 'size' => 'small']
  383. ];
  384. },
  385. ],
  386. ];
  387. }
  388. return $this->columns;
  389. }
  390. /**
  391. * 前台用于筛选的类型集合
  392. * @return mixed
  393. */
  394. public function getFilterTypes()
  395. {
  396. if(!$this->filterTypes){
  397. $this->filterTypes = [
  398. 'USER_NAME'=> ['name'=> Yii::t('ctx', 'memberCode')],
  399. 'REAL_NAME'=> ['name'=> Yii::t('ctx', 'memberName')],
  400. 'CREATED_AT'=> ['name'=> Yii::t('ctx', 'joiningDate'), 'other'=> 'date'],
  401. 'PERIOD_AT'=> ['name'=> Yii::t('ctx', 'joiningPeriod')],
  402. 'DEC_LV_NAME'=> ['name'=> Yii::t('ctx', 'currentMemberLevel'), 'other'=> 'decLevel'],
  403. 'EMP_LV_NAME'=> ['name'=> Yii::t('ctx', 'highestDirector'), 'other'=> 'empLevel'],
  404. 'LAST_EMP_LV_NAME'=> ['name'=> Yii::t('ctx', 'latestDirector'), 'other'=> 'empLevel'],
  405. 'CROWN_LV_NAME'=> ['name'=> Yii::t('ctx', 'highestCrown'), 'other'=> 'crownLevel'],
  406. 'LAST_CROWN_LV_NAME'=> ['name'=> Yii::t('ctx', 'latestCrown'), 'other'=> 'crownLevel'],
  407. // 'REC_USER_NAME'=> ['name'=> Yii::t('ctx', 'recommendationNo')],
  408. // 'CON_USER_NAME'=> ['name'=> Yii::t('ctx', 'placementNo')],
  409. 'MOBILE'=> ['name'=> Yii::t('ctx', 'phoneNumber')],
  410. 'DEC_USER_NAME'=> ['name'=> Yii::t('ctx', 'stockistCode')],
  411. 'IS_DEC'=> ['name'=> Yii::t('ctx', 'stockistOrNot'), 'other'=> 'yesOrNo'],
  412. 'DEC_ROLE_NAME'=> ['name'=> Yii::t('ctx', 'stockistLevel'), 'other'=> 'decRole'],
  413. 'COUNTRY'=> [
  414. 'name'=> \Yii::t('ctx', 'country'),
  415. 'other'=> 'select',
  416. 'selectData'=> self::getCountry()
  417. ],
  418. 'AREA'=> ['name'=> Yii::t('ctx', 'commonAddress'), 'other'=> 'area'],
  419. 'STATUS'=> ['name'=> Yii::t('ctx', 'activeStatus'), 'other'=> 'select', 'selectData'=> [['id'=> 0, 'name'=> Yii::t('ctx', 'locking')],['id'=> 1, 'name'=> Yii::t('ctx', 'activation')]]],
  420. ];
  421. }
  422. return $this->filterTypes;
  423. }
  424. public function getCountry()
  425. {
  426. $countries = Countries::getFromCache();
  427. $data = [];
  428. foreach ($countries as $country) {
  429. $data[] = [
  430. 'id' => $country['ID'],
  431. 'name' => $country['NAME'],
  432. ];
  433. }
  434. return $data;
  435. }
  436. }