IndexList.php 17 KB

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