UserController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/2/24
  6. * Time: 下午12:48
  7. */
  8. namespace frontendApi\modules\v1\controllers;
  9. use common\helpers\Cache;
  10. use common\helpers\Form;
  11. use common\helpers\Tool;
  12. use common\helpers\user\Info;
  13. use common\models\BaUser;
  14. use common\models\Config;
  15. use common\models\DeclarationLevel;
  16. use common\models\DeclarationPackage;
  17. use common\models\DecOrder;
  18. use common\models\forms\ApproachDeclarationLoopForm;
  19. use common\models\forms\ApproachDeclarationUpgradeForm;
  20. use common\models\forms\BaUserForm;
  21. use common\models\forms\DeclarationForm;
  22. use common\models\forms\DeclarationLoopForm;
  23. use common\models\forms\UploadForm;
  24. use common\models\forms\UserBindForm;
  25. use common\models\forms\UserForm;
  26. use common\models\OpenBank;
  27. use common\models\ReceiveAddress;
  28. use common\models\Region;
  29. use common\models\ShopGoods;
  30. use common\models\UpgradeType;
  31. use common\models\User;
  32. use common\models\UserBind;
  33. use common\models\UserInfo;
  34. use common\models\UserNetwork;
  35. use common\models\forms\DeclarationUpgradeForm;
  36. use yii\db\Exception;
  37. use yii\web\UploadedFile;
  38. class UserController extends BaseController {
  39. public $modelClass = UserInfo::class;
  40. /**
  41. * 会员资料
  42. * @return mixed
  43. * @throws \yii\web\HttpException
  44. */
  45. public function actionIndex() {
  46. $allNation = \Yii::$app->params['nation'];
  47. $allOpenBank = OpenBank::findAllAsArray('STATUS=1');
  48. $data['allNation'] = $allNation;
  49. $data['allOpenBank'] = $allOpenBank;
  50. $data['userInfo'] = User::getEnCodeInfo(\Yii::$app->user->id);
  51. $data['userInfo']['NATION'] = $data['userInfo']['NATION_ID'];
  52. return static::notice($data);
  53. }
  54. /**
  55. * 编辑会员资料
  56. * @return mixed
  57. * @throws \yii\web\HttpException
  58. */
  59. public function actionEdit() {
  60. if(\Yii::$app->request->isPost){
  61. $form = new UserForm();
  62. $post = \Yii::$app->request->post();
  63. $form->scenario = 'modifyProfile';
  64. if($form->load($post, '') && $result = $form->modifyProfile()){
  65. return static::notice('Personal data modified successfully');//个人资料修改成功
  66. } else {
  67. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  68. }
  69. }
  70. return static::notice('Illegal request', 400); // 非法请求
  71. }
  72. /**
  73. * 修改登录密码
  74. */
  75. public function actionPassword(){
  76. if(\Yii::$app->request->isPost){
  77. $form = new UserForm();
  78. $form->scenario = 'modifyPassword';
  79. $post = \Yii::$app->request->post();
  80. if($form->load($post, '') && $result = $form->modifyPassword()){
  81. return static::notice('Password modified successfully');//密码修改成功
  82. } else {
  83. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  84. }
  85. }
  86. return static::notice('Illegal request', 400); // 非法请求
  87. }
  88. /**
  89. * 修改支付密码
  90. */
  91. public function actionPayPassword(){
  92. if(\Yii::$app->request->isPost){
  93. $form = new UserForm();
  94. $form->scenario = 'modifyPasswordPay';
  95. $post = \Yii::$app->request->post();
  96. $form->userId = \Yii::$app->user->id;
  97. if($form->load($post, '') && $result = $form->modifyPasswordPay()){
  98. return static::notice('支付密码修改成功');
  99. } else {
  100. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  101. }
  102. }
  103. return static::notice('Illegal request', 400); // 非法请求
  104. }
  105. /**
  106. * 直推会员列表
  107. * @return mixed
  108. * @throws \yii\web\HttpException
  109. */
  110. public function actionRecUser() {
  111. $allData = UserInfo::lists('AND REC_UID=:REC_UID', [':REC_UID' => \Yii::$app->user->id], ['useSlaves' => true, 'select'=>'USER_ID,CREATED_AT']);
  112. foreach ($allData['list'] as $key => $data) {
  113. $userBaseInfo = User::getEnCodeInfo($data['USER_ID']);
  114. $userBaseInfo['NATION'] = \Yii::$app->params['nation'][$userBaseInfo['NATION']]['name'] ?? '';
  115. $allData['list'][$key]['BASE_INFO'] = $userBaseInfo;
  116. }
  117. return static::notice($allData);
  118. }
  119. /**
  120. * 上传身份证
  121. * @return mixed
  122. * @throws \yii\base\Exception
  123. * @throws \yii\web\HttpException
  124. */
  125. public function actionIdCard() {
  126. if (\Yii::$app->request->isPost) {
  127. $formModel = new UploadForm();
  128. $formModel->scenario = 'idCardFront';
  129. $formModel->file = UploadedFile::getInstanceByName('file');
  130. //$formModel->token = \Yii::$app->request->post('uploadToken');
  131. $formModel->token = \Yii::$app->request->request('uploadToken');
  132. if ($formModel->file && $formModel->upload()) {
  133. return static::notice('Successful');
  134. } else {
  135. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  136. }
  137. }
  138. // 查看该用户是否已经上传过身份证
  139. $oneData = User::find()->select('ID_IMAGE')->where('ID=:ID', [':ID' => \Yii::$app->user->id])->asArray()->one();
  140. if ($oneData['ID_IMAGE']) {
  141. return static::notice($oneData);
  142. } else {
  143. $token = Cache::setUploadToken();
  144. return static::notice($token);
  145. }
  146. }
  147. /**
  148. * 点位绑定
  149. * @return mixed
  150. * @throws \yii\base\Exception
  151. * @throws \yii\web\HttpException
  152. */
  153. public function actionBind() {
  154. $userBind = UserBind::findOneAsArray('USER_ID=:USER_ID AND IS_DEL=0', [':USER_ID' => \Yii::$app->user->id]);
  155. $allData['list']=UserBind::findAllAsArray('MAIN_UID=:MAIN_UID AND IS_DEL=0', [':MAIN_UID' => $userBind['MAIN_UID']], 'ID,USER_ID,MAIN_UID,CREATED_AT,UPDATED_AT');
  156. foreach ($allData['list'] as $key => $value) {
  157. $baseInfo = Info::baseInfoZh($value['USER_ID']);
  158. if ($baseInfo['STATUS'] != 1) {
  159. unset($allData['list'][$key]);
  160. continue;
  161. }
  162. $allData['list'][$key]['USER_NAME'] = $baseInfo['USER_NAME'];
  163. $allData['list'][$key]['REAL_NAME'] = $baseInfo['REAL_NAME'];
  164. $allData['list'][$key]['BANK_PROVINCE_NAME'] = $baseInfo['BANK_PROVINCE_NAME'];
  165. $allData['list'][$key]['BANK_CITY_NAME'] = $baseInfo['BANK_CITY_NAME'];
  166. $allData['list'][$key]['BANK_COUNTY_NAME'] = $baseInfo['BANK_COUNTY_NAME'];
  167. $allData['list'][$key]['OPEN_BANK_NAME'] = $baseInfo['OPEN_BANK_NAME'];
  168. $allData['list'][$key]['BANK_NO'] = $baseInfo['BANK_NO'];
  169. $allData['list'][$key]['MAIN_USER_NAME'] =Info::getUserNameByUserId($value['MAIN_UID']);
  170. }
  171. $allData['list'] = array_values($allData['list']);
  172. return static::notice($allData);
  173. }
  174. /**
  175. * 编辑点位绑定
  176. * @return mixed
  177. * @throws \yii\web\HttpException
  178. */
  179. public function actionBindEdit(){
  180. $id = \Yii::$app->request->get('id');
  181. if(\Yii::$app->request->isPost) {
  182. return parent::edit(UserBindForm::class, '修改主点位成功', 'frontEdit', ['frontEdit'], null, function($form, $result){
  183. //log
  184. });
  185. }
  186. // 获得当前会员的用户名等信息
  187. $userBind = UserBind::findOneAsArray('ID=:ID AND IS_DEL=0', [':ID' => $id]);
  188. $userBinds = UserBind::findAllAsArray('MAIN_UID=:MAIN_UID AND IS_DEL=0',[':MAIN_UID'=>$userBind['MAIN_UID']], 'ID,USER_ID,MAIN_UID,CREATED_AT,UPDATED_AT');
  189. foreach($userBinds as $key=>$value){
  190. $status = Info::getStatusByUserId($value['USER_ID']);
  191. if ($status != 1) {
  192. unset($userBinds[$key]);
  193. continue;
  194. }
  195. $userBinds[$key]['USER_NAME'] = Info::getUserNameByUserId($value['USER_ID']);
  196. }
  197. $userBinds = array_values($userBinds);
  198. return static::notice(['userBinds' => $userBinds,'mainUid'=>$userBind['MAIN_UID']]);
  199. }
  200. // 会员升级,通过会员的编号,获取会员信息
  201. public function actionUpgradeInfo() {
  202. $isSwitchUpgrade = Config::find()
  203. ->where("CONFIG_NAME='isOpenUpgrade'")
  204. ->asArray()
  205. ->one();
  206. $isOpen = !empty($isSwitchUpgrade) && isset($isSwitchUpgrade['VALUE']) ? $isSwitchUpgrade['VALUE'] : 0;
  207. if ($isOpen < 1) {
  208. return static::notice('The function is not available',400); // 功能暂未开放
  209. }
  210. $userNumber = \Yii::$app->request->request('userName');
  211. $baseInfo = Info::baseInfoZhByUserName($userNumber);
  212. if ($baseInfo['STATUS'] != 1) {
  213. return static::notice('Inactive user. Please contact customer service.',400);// 非激活用户,请联系客服
  214. }
  215. // 1. 如果是最高级别,则只显示用户基本信息
  216. // 2. 如果不是最高级别,如果用户累计报单数据是0, 或者用户累计报单业绩不符合级别信息,则提示 请联系客服核对业绩
  217. $userId = $baseInfo['ID'];
  218. $userDecId = $baseInfo['DEC_LV'];// 用户当前的级别
  219. // 获取系统中的DEC 报单级别配置
  220. $decConfig = Cache::getDecLevelConfig();
  221. $userDecInfo = $decConfig[$userDecId]; // 会员的级别具体信息
  222. $maxPerfInfo = DeclarationLevel::getMaxDecPref();
  223. $maxDecId = $maxPerfInfo['ID']; // 级别配置中最高级别ID
  224. $observe = Config::getConfigByType('observe'); // 获取观察期配置信息
  225. $observeLimit = $observe['observePeriodLimit']['value']; // 月份限制
  226. $isObserve = User::checkIsObserve($baseInfo['CREATED_AT'], $observeLimit); // 判断用户是否再观察期中
  227. // 如果用户已经是最高级别,则只展示用户信息
  228. $isMax = false;
  229. if ($maxDecId == $userDecId) {
  230. $isMax = true;
  231. }
  232. // 如果用户已经是最高级别,则只展示用户信息
  233. $userInfo = [
  234. 'DEC_NAME' => $baseInfo['DEC_LV_NAME'], // 用户级别中文
  235. 'DEC_ID' => $userDecId, // 用户级别id
  236. 'REAL_NAME' => $baseInfo['REAL_NAME'], // 真实姓名
  237. 'ADD_AT' => date('Y-m-d', $baseInfo['CREATED_AT']), // 加入时间
  238. 'IS_OBSERVE' => $isObserve, // 是否是观察期 true为是观察期
  239. 'IS_MAX' => $isMax, // 是否已是最大级别 最大级别不需要判断报单总PV是多少 只展示基本信息
  240. ];
  241. // 如果是最高级别了,则无需升级
  242. if ($isMax) {
  243. return static::notice(['baseInfo' => $userInfo]);
  244. }
  245. $levelPerf = $userDecInfo['PERF'];// 用户当前级别对应的业绩值
  246. if (!$isMax) {
  247. $userDecPvSum = User::sumDevPvByUserId($userId); // 用户所有报单PV总和
  248. // // 如果总和小于级别业绩 去掉这校验直接补比如3000-980的差值
  249. // if ($userDecPvSum < $levelPerf) {
  250. // return static::notice('请联系客服人员核对业绩',400);
  251. // }
  252. // 下一级业绩
  253. $nextLevelPerf = DeclarationLevel::getNextDecPref($levelPerf)['PERF'];
  254. // 如果总和超过了下一级业绩
  255. if ($userDecPvSum >= $nextLevelPerf) {
  256. return static::notice('Please contact customer service to check performance.',400);// 请联系客服人员核对业绩
  257. }
  258. $type = $isObserve ? 1 : 2;
  259. $userInfo['UPGRADE_FUNC'] = $isObserve ? 'filling up of a deficit' : 'full payment';// 升级方式
  260. $upgradeType = UpgradeType::getOneByType($type);
  261. // 如果用户不是最大级别,则需要获取是否观察期,算出PV是否有问题,应该补多少,
  262. $userInfo['UPGRADE_TYPE'] = $upgradeType;
  263. $userInfo['NOW_PERF'] = $userDecPvSum;
  264. $userInfo['NEXT_PERF'] = $nextLevelPerf;
  265. // 用户可选择的级别列表
  266. $userInfo['LEVEL_LIST'] = DeclarationLevel::getNextAll($levelPerf);// 用户可选择的级别列表
  267. // 循环列表,补充升级所需要的补差
  268. foreach ($userInfo['LEVEL_LIST'] as &$v) {
  269. $v['REPAIR_PV'] = $isObserve ? $v['PERF'] - $userInfo['NOW_PERF'] : $v['PERF'];
  270. }
  271. }
  272. return static::notice(['baseInfo' => $userInfo]);
  273. }
  274. // 会员升级管理
  275. public function actionUpgrade() {
  276. $isSwitchUpgrade = Config::find()
  277. ->where("CONFIG_NAME='isOpenUpgrade'")
  278. ->asArray()
  279. ->one();
  280. $isOpen = !empty($isSwitchUpgrade) && isset($isSwitchUpgrade['VALUE']) ? $isSwitchUpgrade['VALUE'] : 0;
  281. if ($isOpen < 1) {
  282. return static::notice('功能暂未开放',400);
  283. }
  284. // 开始升级
  285. if (\Yii::$app->request->isPost) {
  286. $post = \Yii::$app->request->post();
  287. // 根据支付方式区分逻辑
  288. $payMethod = \Yii::$app->request->post('payType', '');
  289. if ($payMethod === 'pay_stack') {
  290. $formModel = new ApproachDeclarationUpgradeForm();
  291. } else {
  292. unset($post['payType']);
  293. $formModel = new DeclarationUpgradeForm();
  294. }
  295. $post['type'] = DeclarationForm::TYPE_ZC;
  296. if ($formModel->load($post, '') && $result = $formModel->add($post)) {
  297. return static::notice($result);// Upgrade declaration succeeded升级报单成功
  298. } else {
  299. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  300. }
  301. }
  302. //所有报单套餐
  303. $allDecPackage = DeclarationPackage::getAllData();
  304. $decLevels = Cache::getDecLevelConfig();
  305. foreach ($allDecPackage as $k=>$v){
  306. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  307. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  308. }
  309. //所有自选商品
  310. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  311. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  312. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  313. $decUserName = User::getEnCodeInfo(\Yii::$app->user->id)['USER_NAME'];
  314. $query_condition= " AND (1<>1";
  315. if(!$isDecReg || ($isDecReg && $isDec==1)){
  316. $query_condition = " AND (FIND_IN_SET(1,GIFT_TYPE)>0";
  317. }
  318. if($isStudio==1){
  319. $query_condition.= " OR FIND_IN_SET(3,GIFT_TYPE)>0";
  320. }
  321. $query_condition.= ")";
  322. $allGoods = ShopGoods::find()->where("STATUS=1 AND CATEGORY_TYPE=1 " . $query_condition)->orderBy('SORT ASC')->asArray()->all();
  323. foreach ($allGoods as &$goods) {
  324. $goods['TAX'] = Tool::calculateTax($goods['SELL_PRICE'], $goods['TAX_RATE']);
  325. }
  326. return static::notice([
  327. 'allDecPackage' => $allDecPackage,
  328. 'allGoods' => $allGoods,
  329. 'decUserName'=>$decUserName,
  330. 'payList' => ShopGoods::payTypes(),
  331. 'sellType' => ShopGoods::CATEGORY_TYPE,
  332. 'categoryType' => ShopGoods::CATEGORY_TYPE[0]['id'],
  333. ]);
  334. }
  335. /**
  336. * 报单管理
  337. */
  338. public function actionDec() {
  339. // 生成随机码 , 初始化redis
  340. $userName = Info::generateWebUserName('NG',9);
  341. $redis = \Yii::$app->redis;
  342. $post = \Yii::$app->request->post();
  343. if (\Yii::$app->request->isPost) {
  344. // 根据支付方式区分逻辑
  345. $payMethod = \Yii::$app->request->post('payType', '');
  346. if ($payMethod === 'pay_stack') {
  347. $formModel = new ApproachDeclarationLoopForm();
  348. } else {
  349. unset($post['payType']);
  350. $formModel = new DeclarationLoopForm();
  351. }
  352. $formModel->scenario = 'userDec';
  353. $post['province'] = $post['province'] ? :1;
  354. $post['city'] = $post['city'] ? :1;
  355. $post['county'] = $post['county'] ? :1;
  356. $post['conUserName'] = trim($post['conUserName']);
  357. $post['recUserName'] = trim($post['recUserName']);
  358. $post['cityName'] = trim($post['cityName']);
  359. $post['lgaName'] = trim($post['lgaName']);
  360. // 针对于会员编号的判断
  361. $insertUserName = strtoupper($post['insertUserName']);
  362. $getRedisUserName = $redis->get('key_' . $insertUserName);
  363. if (!$getRedisUserName){
  364. return static::notice('Membership number expired',400);//会员编号过期
  365. }
  366. if ($insertUserName != $getRedisUserName){
  367. return static::notice('Member number does not conform to',400);//会员编号不符合
  368. }
  369. $post['insertUserName'] = $insertUserName;
  370. $post['type'] = DeclarationForm::TYPE_ZC;
  371. $allData['data'][] = $post;
  372. if ($formModel->load($allData, '') && $result = $formModel->add()) {
  373. return static::notice($result);//报单成功
  374. } else {
  375. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  376. }
  377. }
  378. //所有报单套餐
  379. $allDecPackage = DeclarationPackage::getAllData();
  380. $decLevels = Cache::getDecLevelConfig();
  381. foreach ($allDecPackage as $k=>$v){
  382. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  383. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  384. }
  385. //所有自选商品
  386. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  387. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  388. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  389. $query_condition= " AND (1<>1";
  390. if(!$isDecReg || ($isDecReg && $isDec==1)){
  391. $query_condition = " AND (FIND_IN_SET(1,GIFT_TYPE)>0";
  392. }
  393. if($isStudio==1){
  394. $query_condition.= " OR FIND_IN_SET(3,GIFT_TYPE)>0";
  395. }
  396. $query_condition.= ")";
  397. // 只查询普通商品
  398. $allGoods = ShopGoods::find()->where("STATUS=1 AND CATEGORY_TYPE=1".$query_condition)->orderBy('SORT ASC')->asArray()->all();
  399. //$allGoods = ShopGoods::findAllAsArray('STATUS=1');
  400. // 所有开户行
  401. $allOpenBank = OpenBank::find()->where('STATUS=1')->orderBy('LIST_ORDER ASC')->asArray()->all();
  402. if (!$userName) {
  403. return static::notice('Failed to generate member number', 400);//会员编号生成失败
  404. }
  405. //随机码保存在redis中方便进行比对
  406. $redis->setex('key_'.$userName , 3600 , $userName);
  407. return static::notice([
  408. 'allDecPackage' => $allDecPackage,
  409. 'allGoods' => $allGoods,
  410. 'allOpenBank' => $allOpenBank,
  411. 'userName' => $userName,
  412. 'payList' => ShopGoods::payTypes(),
  413. 'sellType' => ShopGoods::CATEGORY_TYPE,
  414. 'categoryType' => ShopGoods::CATEGORY_TYPE[0]['id'],
  415. ]);
  416. }
  417. /**
  418. * 报单级别套餐
  419. */
  420. public function actionDecPackage() {
  421. $decLv = \Yii::$app->request->get('id');
  422. //所有报单级别套餐
  423. $allDecPackage = DeclarationPackage::getPackageFromLevelId($decLv);
  424. return static::notice(['allDecPackage' => $allDecPackage]);
  425. }
  426. /*
  427. * 从会员名和左右,获取底部安置人
  428. *
  429. */
  430. public function actionGetAutoPlace() {
  431. $userName = \Yii::$app->request->get('userName');
  432. $side = \Yii::$app->request->get('side');
  433. $userId = Info::getUserIdByUserName($userName);
  434. // print_r($userId);
  435. $bottomPlace = UserNetwork::getBottomPlace($userId,'', $side);
  436. $bottomUser = UserNetwork::find()->select('USER_ID')->where('LOCATION_TAG=:LOCATION_TAG', ['LOCATION_TAG' => $bottomPlace])->asArray()->one();
  437. $bottomUser = User::findOneAsArray('ID=:ID', [':ID' => $bottomUser['USER_ID']], 'USER_NAME');
  438. // print_r($bottomUser);
  439. return static::notice($bottomUser);
  440. }
  441. /**
  442. * 会员信息查询
  443. * @return mixed
  444. * @throws \yii\web\HttpException
  445. */
  446. public function actionFullInfo()
  447. {
  448. $userName = \Yii::$app->request->get('userName');
  449. $userId = Info::getUserIdByUserName($userName);
  450. $userInfo['REAL_NAME'] = '';
  451. $user = User::findOneAsArray('ID=:ID', [':ID' => $userId], 'REAL_NAME');
  452. if($user){
  453. $userInfo['REAL_NAME'] = $user['REAL_NAME'];
  454. $allChildUser = UserNetwork::getFirstFloorChildren($userId);
  455. $isLocation = [1 => 'Left-', 2 => 'Right-'];
  456. if($allChildUser) {
  457. foreach ($allChildUser as $child) {
  458. if ($child['RELATIVE_LOCATION']<'3'){
  459. $isLocation[$child['RELATIVE_LOCATION']].= 'Full';
  460. }
  461. }
  462. }
  463. $userInfo['isLocation'] = '('.implode(',',$isLocation).')';
  464. return static::notice($userInfo);
  465. }else{
  466. return static::notice('Member number does not exist', 400);//会员编号不存在
  467. }
  468. }
  469. /**
  470. * 复消会员信息查询
  471. * @return mixed
  472. * @throws \yii\web\HttpException
  473. */
  474. public function actionUserBaseInfo()
  475. {
  476. $userName = \Yii::$app->request->get('userName');
  477. $userId = Info::getUserIdByUserName($userName);
  478. if($userId){
  479. $allAddress = ReceiveAddress::findAllAsArray('USER_ID=:USER_ID', [':USER_ID'=>$userId]);
  480. if($allAddress) {
  481. foreach ($allAddress as $key => $row) {
  482. $allAddress[$key]['PROVINCE_NAME'] = Region::getCnName($row['PROVINCE']);
  483. $allAddress[$key]['CITY_NAME'] = Region::getCnName($row['CITY']);
  484. $allAddress[$key]['COUNTY_NAME'] = Region::getCnName($row['COUNTY']);
  485. }
  486. }
  487. $userInfo = Info::baseInfoWithNet($userId);
  488. // $decLevelConfig = Cache::getDecLevelConfig();
  489. // $empLevelConfig = Cache::getEmpLevelConfig();
  490. $arr = [
  491. 'REAL_NAME'=>$userInfo['REAL_NAME'],
  492. // 'DEC_LEVEL_NAME' => $decLevelConfig[$userInfo['DEC_LV']]['LEVEL_NAME'],
  493. // 'EMP_LEVEL_NAME'=>$empLevelConfig[$userInfo['EMP_LV']]['LEVEL_NAME'],
  494. // 'REC_UID'=>$userInfo['REC_USER_NAME'].'('.$userInfo['REC_REAL_NAME'].')',
  495. // 'CON_UID'=>$userInfo['CON_USER_NAME'].'('.$userInfo['CON_REAL_NAME'].')',
  496. 'allAddress'=>$allAddress
  497. ];
  498. return static::notice($arr);
  499. }else{
  500. return static::notice('Repeat sales Member No. does not exist', 400);//复消会员编号不存在
  501. }
  502. }
  503. /**
  504. * 会员资料
  505. * @return mixed
  506. * @throws \yii\web\HttpException
  507. */
  508. public function actionBaInfo()
  509. {
  510. $allNation = \Yii::$app->params['nation'];
  511. $allOpenBank = OpenBank::findAllAsArray('STATUS=1');
  512. $data['allNation'] = $allNation;
  513. $data['allOpenBank'] = $allOpenBank;
  514. $data['userInfo'] = BaUser::getEnCodeInfo(\Yii::$app->user->id);
  515. $data['userInfo']['NATION'] = $data['userInfo']['NATION_ID'];
  516. return static::notice($data);
  517. }
  518. /**
  519. * 编辑会员资料
  520. * @return mixed
  521. * @throws \yii\web\HttpException
  522. */
  523. public function actionBaEdit()
  524. {
  525. if(\Yii::$app->request->isPost)
  526. {
  527. $form = new BaUserForm();
  528. $post = \Yii::$app->request->post();
  529. $form->scenario = 'modifyProfile';
  530. if ($form->load($post, '') && $result = $form->modifyProfile()){
  531. return static::notice('Personal data modified successfully');//个人资料修改成功
  532. } else {
  533. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  534. }
  535. }
  536. return static::notice('Illegal request', 400); // 非法请求
  537. }
  538. /**
  539. * 修改登录密码
  540. */
  541. public function actionBaPassword(){
  542. if(\Yii::$app->request->isPost) {
  543. $form = new BaUserForm();
  544. $form->scenario = 'modifyPassword';
  545. $post = \Yii::$app->request->post();
  546. if($form->load($post, '') && $result = $form->modifyPassword()){
  547. return static::notice('Password modified successfully');//密码修改成功
  548. } else {
  549. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  550. }
  551. }
  552. return static::notice('Illegal request', 400); // 非法请求
  553. }
  554. /**
  555. * 修改支付密码
  556. */
  557. public function actionBaPayPassword(){
  558. if(\Yii::$app->request->isPost){
  559. $form = new BaUserForm();
  560. $form->scenario = 'modifyPasswordPay';
  561. $post = \Yii::$app->request->post();
  562. $form->userId = \Yii::$app->user->id;
  563. if($form->load($post, '') && $result = $form->modifyPasswordPay()){
  564. return static::notice('Payment password modified successfully'); // 支付密码修改成功
  565. } else {
  566. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  567. }
  568. }
  569. return static::notice('Illegal request', 400); // 非法请求
  570. }
  571. }