IndexList.php 19 KB

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