UserController.php 30 KB

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