UserController.php 30 KB

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