UserController.php 32 KB

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