UserController.php 30 KB

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