UserController.php 34 KB

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