IndexList.php 19 KB

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