UserController.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  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\bonus\CalcCache;
  10. use common\helpers\Cache;
  11. use common\helpers\Form;
  12. use common\helpers\LoggerTool;
  13. use common\helpers\Tool;
  14. use common\helpers\user\Info;
  15. use common\models\BaUser;
  16. use common\models\Config;
  17. use common\models\Countries;
  18. use common\models\Currency;
  19. use common\models\CurrencyConversions;
  20. use common\models\DeclarationLevel;
  21. use common\models\DeclarationPackage;
  22. use common\models\DecOrder;
  23. use common\models\forms\ApproachDeclarationLoopForm;
  24. use common\models\forms\BaApproachDeclarationLoopForm;
  25. use common\models\forms\ApproachDeclarationUpgradeForm;
  26. use common\models\forms\BaUserForm;
  27. use common\models\forms\DeclarationForm;
  28. use common\models\forms\BaDeclarationForm;
  29. use common\models\forms\DeclarationLoopForm;
  30. use common\models\forms\BaDeclarationLoopForm;
  31. use common\models\forms\UploadForm;
  32. use common\models\forms\UserBindForm;
  33. use common\models\forms\UserForm;
  34. use common\models\Instalment;
  35. use common\models\OpenBank;
  36. use common\models\Period;
  37. use common\models\ReceiveAddress;
  38. use common\models\Region;
  39. use common\models\ShopGoods;
  40. use common\models\ShopGoodsNature;
  41. use common\models\UpgradeType;
  42. use common\models\User;
  43. use common\models\UserBind;
  44. use common\models\UserBonus;
  45. use common\models\UserInfo;
  46. use common\models\BaUserInfo;
  47. use common\models\UserNetwork;
  48. use common\models\forms\DeclarationUpgradeForm;
  49. use common\models\UserPerformance;
  50. use common\models\UserWallet;
  51. use frontendApi\modules\v1\models\Relation;
  52. use Yii;
  53. use yii\db\Exception;
  54. use yii\web\UploadedFile;
  55. class UserController extends BaseController {
  56. public $modelClass = UserInfo::class;
  57. const LOOP_FINISH = 1;
  58. /**
  59. * 会员资料
  60. * @return mixed
  61. * @throws \yii\web\HttpException
  62. */
  63. public function actionIndex() {
  64. $allNation = \Yii::$app->params['nation'];
  65. $allOpenBank = OpenBank::findAllAsArray('STATUS=1');
  66. $data['allNation'] = $allNation;
  67. $data['allOpenBank'] = $allOpenBank;
  68. $data['userInfo'] = User::getEnCodeInfo(\Yii::$app->user->id);
  69. $data['userInfo']['NATION'] = $data['userInfo']['NATION_ID'];
  70. return static::notice($data);
  71. }
  72. /**
  73. * 编辑会员资料
  74. * @return mixed
  75. * @throws \yii\web\HttpException
  76. */
  77. public function actionEdit() {
  78. if(\Yii::$app->request->isPost){
  79. $form = new UserForm();
  80. $post = \Yii::$app->request->post();
  81. $form->scenario = 'modifyProfile';
  82. if($form->load($post, '') && $result = $form->modifyProfile()){
  83. return static::notice(Yii::t('app', 'personalDataModifiedSuccessfully'), 400);
  84. } else {
  85. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  86. }
  87. }
  88. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  89. }
  90. /**
  91. * 修改登录密码
  92. */
  93. public function actionPassword(){
  94. if(\Yii::$app->request->isPost){
  95. $form = new UserForm();
  96. $form->scenario = 'modifyPassword';
  97. $post = \Yii::$app->request->post();
  98. if($form->load($post, '') && $result = $form->modifyPassword()){
  99. return static::notice(Yii::t('app', 'passwordModifiedSuccessfully'), 400);
  100. } else {
  101. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  102. }
  103. }
  104. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  105. }
  106. /**
  107. * 修改支付密码
  108. */
  109. public function actionPayPassword(){
  110. if(\Yii::$app->request->isPost){
  111. $form = new UserForm();
  112. $form->scenario = 'modifyPasswordPay';
  113. $post = \Yii::$app->request->post();
  114. $form->userId = \Yii::$app->user->id;
  115. if($form->load($post, '') && $result = $form->modifyPasswordPay()){
  116. return static::notice(Yii::t('app', 'passwordModifiedSuccessfully'));
  117. } else {
  118. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  119. }
  120. }
  121. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  122. }
  123. /**
  124. * 直推会员列表
  125. * @return mixed
  126. * @throws \yii\web\HttpException
  127. */
  128. public function actionRecUser() {
  129. $allData = UserInfo::lists('AND REC_UID=:REC_UID', [':REC_UID' => \Yii::$app->user->id], ['useSlaves' => true, 'select'=>'USER_ID,CREATED_AT']);
  130. foreach ($allData['list'] as $key => $data) {
  131. $userBaseInfo = User::getEnCodeInfo($data['USER_ID']);
  132. $userBaseInfo['NATION'] = \Yii::$app->params['nation'][$userBaseInfo['NATION']]['name'] ?? '';
  133. $allData['list'][$key]['BASE_INFO'] = $userBaseInfo;
  134. }
  135. return static::notice($allData);
  136. }
  137. /**
  138. * 上传身份证
  139. * @return mixed
  140. * @throws \yii\base\Exception
  141. * @throws \yii\web\HttpException
  142. */
  143. public function actionIdCard() {
  144. if (\Yii::$app->request->isPost) {
  145. $formModel = new UploadForm();
  146. $formModel->scenario = 'idCardFront';
  147. $formModel->file = UploadedFile::getInstanceByName('file');
  148. //$formModel->token = \Yii::$app->request->post('uploadToken');
  149. $formModel->token = \Yii::$app->request->request('uploadToken');
  150. if ($formModel->file && $formModel->upload()) {
  151. return static::notice(Yii::t('app', 'successfully'));
  152. } else {
  153. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  154. }
  155. }
  156. // 查看该用户是否已经上传过身份证
  157. $oneData = User::find()->select('ID_IMAGE')->where('ID=:ID', [':ID' => \Yii::$app->user->id])->asArray()->one();
  158. if ($oneData['ID_IMAGE']) {
  159. return static::notice($oneData);
  160. } else {
  161. $token = Cache::setUploadToken();
  162. return static::notice($token);
  163. }
  164. }
  165. /**
  166. * 点位绑定
  167. * @return mixed
  168. * @throws \yii\base\Exception
  169. * @throws \yii\web\HttpException
  170. */
  171. public function actionBind() {
  172. $userBind = UserBind::findOneAsArray('USER_ID=:USER_ID AND IS_DEL=0', [':USER_ID' => \Yii::$app->user->id]);
  173. $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');
  174. foreach ($allData['list'] as $key => $value) {
  175. $baseInfo = Info::baseInfoZh($value['USER_ID']);
  176. if ($baseInfo['STATUS'] != 1) {
  177. unset($allData['list'][$key]);
  178. continue;
  179. }
  180. $allData['list'][$key]['USER_NAME'] = $baseInfo['USER_NAME'];
  181. $allData['list'][$key]['REAL_NAME'] = $baseInfo['REAL_NAME'];
  182. $allData['list'][$key]['BANK_PROVINCE_NAME'] = $baseInfo['BANK_PROVINCE_NAME'];
  183. $allData['list'][$key]['BANK_CITY_NAME'] = $baseInfo['BANK_CITY_NAME'];
  184. $allData['list'][$key]['BANK_COUNTY_NAME'] = $baseInfo['BANK_COUNTY_NAME'];
  185. $allData['list'][$key]['OPEN_BANK_NAME'] = $baseInfo['OPEN_BANK_NAME'];
  186. $allData['list'][$key]['BANK_NO'] = $baseInfo['BANK_NO'];
  187. $allData['list'][$key]['MAIN_USER_NAME'] =Info::getUserNameByUserId($value['MAIN_UID']);
  188. }
  189. $allData['list'] = array_values($allData['list']);
  190. return static::notice($allData);
  191. }
  192. /**
  193. * 编辑点位绑定
  194. * @return mixed
  195. * @throws \yii\web\HttpException
  196. */
  197. public function actionBindEdit(){
  198. $id = \Yii::$app->request->get('id');
  199. if(\Yii::$app->request->isPost) {
  200. return parent::edit(UserBindForm::class, Yii::t('app', 'successfully'), 'frontEdit', ['frontEdit'], null, function($form, $result){
  201. //log
  202. });
  203. }
  204. // 获得当前会员的用户名等信息
  205. $userBind = UserBind::findOneAsArray('ID=:ID AND IS_DEL=0', [':ID' => $id]);
  206. $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');
  207. foreach($userBinds as $key=>$value){
  208. $status = Info::getStatusByUserId($value['USER_ID']);
  209. if ($status != 1) {
  210. unset($userBinds[$key]);
  211. continue;
  212. }
  213. $userBinds[$key]['USER_NAME'] = Info::getUserNameByUserId($value['USER_ID']);
  214. }
  215. $userBinds = array_values($userBinds);
  216. return static::notice(['userBinds' => $userBinds,'mainUid'=>$userBind['MAIN_UID']]);
  217. }
  218. // 会员升级,通过会员的编号,获取会员信息
  219. public function actionUpgradeInfo() {
  220. $isSwitchUpgrade = Config::find()
  221. ->where("CONFIG_NAME='isOpenUpgrade'")
  222. ->asArray()
  223. ->one();
  224. $isOpen = !empty($isSwitchUpgrade) && isset($isSwitchUpgrade['VALUE']) ? $isSwitchUpgrade['VALUE'] : 0;
  225. if ($isOpen < 1) {
  226. return static::notice(Yii::t('app', 'theFunctionIsNotAvailable'), 400);
  227. }
  228. $userNumber = \Yii::$app->request->request('userName');
  229. $baseInfo = Info::baseInfoZhByUserName($userNumber);
  230. if ($baseInfo['STATUS'] != 1) {
  231. return static::notice(Yii::t('app', 'inactiveUser'), 400);
  232. }
  233. // 1. 如果是最高级别,则只显示用户基本信息
  234. // 2. 如果不是最高级别,如果用户累计报单数据是0, 或者用户累计报单业绩不符合级别信息,则提示 请联系客服核对业绩
  235. $userId = $baseInfo['ID'];
  236. $userDecId = $baseInfo['DEC_LV'];// 用户当前的级别
  237. // 获取系统中的DEC 报单级别配置
  238. $decConfig = DeclarationLevel::getAllData();
  239. $userDecInfo = $decConfig[$userDecId]; // 会员的级别具体信息
  240. $maxPerfInfo = DeclarationLevel::getMaxDecPref();
  241. $maxDecId = $maxPerfInfo['ID']; // 级别配置中最高级别ID
  242. $observe = Config::getConfigByType('observe'); // 获取观察期配置信息
  243. $observeLimit = $observe['observePeriodLimit']['value']; // 月份限制
  244. $isObserve = User::checkIsObserve($baseInfo['CREATED_AT'], $observeLimit); // 判断用户是否再观察期中
  245. // 如果用户已经是最高级别,则只展示用户信息
  246. $isMax = false;
  247. if ($maxDecId == $userDecId) {
  248. $isMax = true;
  249. }
  250. // NA级别暂时不提供升级
  251. if ($userDecInfo['ID'] == '67ABC6AO8YTK2LN0E055736AECE8644D') {
  252. return static::notice(Yii::t('app', 'upgradeNotSupport'), 400);
  253. }
  254. // 分期的总期数
  255. $instalmentConfig = intval(Cache::getSystemConfig()['instalment']['VALUE'] ?? 3);
  256. // 查询是否有FX的分期订单
  257. $stageFX = Instalment::getOneStage($baseInfo['ID'], 'FX');
  258. if ($stageFX && $stageFX < $instalmentConfig) {
  259. $instalment = false;
  260. } else {
  261. // 是否有未完成的BD类型的分期订单
  262. $stage = Instalment::getOneStage($userId, 'BD');
  263. if ($stage && $stage < $instalmentConfig) {
  264. $instalment = true;
  265. } else if ($isMax && $stage == $instalmentConfig) {
  266. $instalment = false;
  267. } else {
  268. $instalment = false;
  269. }
  270. }
  271. // 如果用户已经是最高级别,则只展示用户信息
  272. $userInfo = [
  273. 'DEC_NAME' => $baseInfo['DEC_LV_NAME'], // 用户级别中文
  274. 'DEC_ID' => $userDecId, // 用户级别id
  275. 'REAL_NAME' => $baseInfo['REAL_NAME'], // 真实姓名
  276. 'ADD_AT' => date('Y-m-d', $baseInfo['CREATED_AT']), // 加入时间
  277. 'COUNTRY_NAME' => $baseInfo['COUNTRY_NAME'], // 国家
  278. 'IS_OBSERVE' => $isObserve, // 是否是观察期 true为是观察期
  279. 'IS_MAX' => $isMax, // 是否已是最大级别 最大级别不需要判断报单总PV是多少 只展示基本信息
  280. 'INSTALMENT' => $instalment,
  281. 'NOW_PERF' => User::sumDevPvByUserId($userId), // 用户所有报单PV总和
  282. ];
  283. // 如果是最高级别了,则无需升级
  284. if ($isMax) {
  285. return static::notice(['baseInfo' => $userInfo]);
  286. }
  287. $levelPerf = $userDecInfo['PERF'];// 用户当前级别对应的业绩值
  288. if (!$isMax) {
  289. $userDecPvSum = User::sumDevPvByUserId($userId); // 用户所有报单PV总和
  290. // // 如果总和小于级别业绩 去掉这校验直接补比如3000-980的差值
  291. // if ($userDecPvSum < $levelPerf) {
  292. // return static::notice('请联系客服人员核对业绩',400);
  293. // }
  294. // 下一级业绩
  295. $nextLevelPerf = DeclarationLevel::getNextDecPref($levelPerf)['PERF'];
  296. // 如果总和超过了下一级业绩
  297. if ($userDecPvSum >= $nextLevelPerf) {
  298. return static::notice(Yii::t('app', 'checkPerformance'), 400);
  299. }
  300. $type = $isObserve ? 1 : 2;
  301. $userInfo['UPGRADE_FUNC'] = $isObserve ? Yii::t('app', 'fillingUpOfADeficit') : Yii::t('app', 'fullPayment');
  302. $upgradeType = UpgradeType::getOneByType($type);
  303. // 如果用户不是最大级别,则需要获取是否观察期,算出PV是否有问题,应该补多少,
  304. $userInfo['UPGRADE_TYPE'] = $upgradeType;
  305. $userInfo['NOW_PERF'] = $userDecPvSum;
  306. $userInfo['NEXT_PERF'] = $nextLevelPerf;
  307. // 用户可选择的级别列表
  308. $userInfo['LEVEL_LIST'] = DeclarationLevel::getNextAll($levelPerf);// 用户可选择的级别列表
  309. // 如果用户正处于报单分期中,则可以升级到Elite
  310. $userInstalmentInfo = Instalment::getInfo($userId);
  311. if($userInstalmentInfo){
  312. if ($userInstalmentInfo['ORDER_TYPE']=='BD' && $userInstalmentInfo['STAGE'] < 3){
  313. $userInfo['LEVEL_LIST'] = DeclarationLevel::getNextAll(12);// 用户可选择的级别列表
  314. unset($userInfo['LEVEL_LIST'][$userDecId]);
  315. }
  316. }
  317. // 循环列表,补充升级所需要的补差
  318. foreach ($userInfo['LEVEL_LIST'] as &$v) {
  319. $v['REPAIR_PV'] = $isObserve ? $v['PERF'] - $userInfo['NOW_PERF'] : $v['PERF'];
  320. }
  321. }
  322. return static::notice(['baseInfo' => $userInfo]);
  323. }
  324. // 会员升级管理
  325. public function actionUpgrade() {
  326. $isMax = \Yii::$app->request->get('isMax');
  327. $userNumber = \Yii::$app->request->get('userName');
  328. $isSwitchUpgrade = Config::find()
  329. ->where("CONFIG_NAME='isOpenUpgrade'")
  330. ->asArray()
  331. ->one();
  332. $isOpen = !empty($isSwitchUpgrade) && isset($isSwitchUpgrade['VALUE']) ? $isSwitchUpgrade['VALUE'] : 0;
  333. if ($isOpen < 1) {
  334. return static::notice(Yii::t('app', 'theFunctionIsNotAvailable'), 400);
  335. }
  336. // 开始升级
  337. if (\Yii::$app->request->isPost) {
  338. $post = \Yii::$app->request->post();
  339. // 根据支付方式区分逻辑
  340. $payMethod = \Yii::$app->request->post('payType', '');
  341. if ($payMethod === 'pay_stack') {
  342. $formModel = new ApproachDeclarationUpgradeForm();
  343. } else {
  344. unset($post['payType']);
  345. $formModel = new DeclarationUpgradeForm();
  346. }
  347. $post['type'] = DeclarationForm::TYPE_ZC;
  348. if ($formModel->load($post, '') && $result = $formModel->add($post)) {
  349. return static::notice($result);// Upgrade declaration succeeded升级报单成功
  350. } else {
  351. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  352. }
  353. }
  354. // 升级的会员
  355. $userName = \Yii::$app->request->get('userName');
  356. // 会员信息
  357. $user = User::findOneAsArray('USER_NAME=:USER_NAME', [':USER_NAME' => trim($userName)]);
  358. if (!$user) {
  359. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  360. }
  361. //所有报单套餐
  362. $allDecPackage = DeclarationPackage::getAllData();
  363. $decLevels = Cache::getDecLevelConfig();
  364. foreach ($allDecPackage as $k=>$v){
  365. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  366. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  367. }
  368. $baseInfo = Info::baseInfoZhByUserName($userNumber);
  369. // 分期的总期数
  370. $instalmentConfig = intval(Cache::getSystemConfig()['instalment']['VALUE'] ?? 3);
  371. // 查询是否有FX的分期订单
  372. $stageFX = Instalment::getOneStage($baseInfo['ID'], 'FX');
  373. if ($stageFX && $stageFX < $instalmentConfig) {
  374. if ($isMax === "true") {
  375. $condition = ") AND S.INSTALMENT = 1000";
  376. } else {
  377. $condition = ") AND (S.INSTALMENT = 0 OR S.INSTALMENT = 1000)";
  378. }
  379. } else {
  380. // 是否有未完成的BD类型的分期订单
  381. $stageBD = Instalment::getOneStage($baseInfo['ID'], 'BD');
  382. if ($isMax === "true") {
  383. if ($stageBD > 0 && $stageBD < $instalmentConfig) {
  384. $condition = ") AND (S.INSTALMENT = " . ($stageBD + 1) . ")";
  385. } else {
  386. $condition = ") AND S.INSTALMENT = 0";
  387. }
  388. } else {
  389. if ($stageBD > 0 && $stageBD < $instalmentConfig) {
  390. $condition = ") AND (S.INSTALMENT = 0 OR S.INSTALMENT = " . ($stageBD + 1) . ")";
  391. } else {
  392. $condition = ") AND (S.INSTALMENT = 0 OR S.INSTALMENT = 1)";
  393. }
  394. }
  395. }
  396. //所有自选商品
  397. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  398. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  399. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  400. $decUserName = User::getEnCodeInfo(\Yii::$app->user->id)['USER_NAME'];
  401. $query_condition= " AND (1<>1";
  402. if(!$isDecReg || ($isDecReg && $isDec==1)){
  403. $query_condition = " AND (FIND_IN_SET(1, S.GIFT_TYPE)>0";
  404. }
  405. if($isStudio==1){
  406. $query_condition .= " OR FIND_IN_SET(3, S.GIFT_TYPE)>0";
  407. }
  408. $query_condition .= $condition . ' AND N.COUNTRY_ID=:COUNTRY_ID ';
  409. $allGoods = ShopGoods::find()
  410. ->alias('S')
  411. ->select('S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID,C.CODE')
  412. ->join('INNER JOIN', ShopGoodsNature::tableName() . ' AS N', 'N.GOODS_ID=S.ID')
  413. ->join('INNER JOIN', Currency::tableName() . ' AS C', 'C.ID=N.LOCAL_CURRENCY_ID')
  414. ->where("STATUS=1 AND CATEGORY_TYPE=1 " . $query_condition, [':COUNTRY_ID' => $user['COUNTRY_ID']])
  415. ->orderBy('SORT ASC')
  416. ->asArray()
  417. ->all();
  418. foreach ($allGoods as &$goods) {
  419. $goods['TAX'] = Tool::calculateTax($goods['SELL_PRICE'], $goods['TAX_RATE']);
  420. }
  421. // 报单中心汇率
  422. $decCountryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
  423. $decCountry = Countries::getById($decCountryId);
  424. $decUserCurrencyRate = CurrencyConversions::getToUSDRate($decCountry['LOCAL_CURRENCY_ID']);
  425. // 升级会员汇率
  426. $country = Countries::getById($user['COUNTRY_ID']);
  427. $currencyRate = CurrencyConversions::getToUSDRate($country['LOCAL_CURRENCY_ID']);
  428. // 升级会员币种
  429. $currency = Currency::getById($country['LOCAL_CURRENCY_ID']);
  430. $userBalance = [
  431. 'cash' => 0,
  432. 'localCash' => 0,
  433. 'coin' => '',
  434. ];
  435. // 会员余额
  436. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  437. if ($userCash) {
  438. $userBalance['cash'] = $userCash['CASH'];
  439. $userBalance['coin'] = $currency['CODE'] ?? '';
  440. $userBalance['localCash'] = Tool::convertAmount($userCash['CASH'], $decUserCurrencyRate, $currencyRate);
  441. }
  442. // 会员绩效奖金
  443. $userPerformanceAmount = UserPerformance::getAmounts(\Yii::$app->user->id);
  444. $userBalance['prp'] = $userPerformanceAmount ?? 0;
  445. $userBalance['localPrp'] = Tool::convertAmount($userPerformanceAmount, $decUserCurrencyRate, $currencyRate);
  446. // 行政区划
  447. $region = Region::getByCountryId($user['COUNTRY_ID']);
  448. // 支付方式
  449. $payList = ShopGoods::payTypes();
  450. unset($payList['prp']);
  451. // 售卖方式
  452. $sellType = ShopGoods::getCategoryType();
  453. unset($sellType[0]['sell_type'][1]);
  454. return static::notice([
  455. 'allDecPackage' => $allDecPackage,
  456. 'allGoods' => $allGoods,
  457. 'decUserName'=>$decUserName,
  458. 'payList' => $payList,
  459. 'sellType' => $sellType,
  460. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  461. 'userBalance' => $userBalance,
  462. 'decUserCurrencyRate' => $decUserCurrencyRate,
  463. 'userCurrencyRate' => $currencyRate,
  464. 'region' => $region,
  465. ]);
  466. }
  467. /**
  468. * 报单管理
  469. */
  470. public function actionDec() {
  471. $redis = \Yii::$app->redis;
  472. $post = \Yii::$app->request->post();
  473. if (\Yii::$app->request->isPost) {
  474. $userInfo = User::getEnCodeInfo(\Yii::$app->user->id);
  475. if($userInfo['IS_DEC'] == 1 && !empty($post['decUserName']) && $post['decUserName'] != $userInfo['USER_NAME']){
  476. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  477. }
  478. if($userInfo['IS_DEC'] == 0 && $post['decUserName']){
  479. //查询报单编号是否存在
  480. $userId = Info::getUserIdByUserName($post['decUserName']);
  481. if(!$userId){
  482. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  483. }
  484. $isDec = User::getEnCodeInfo($userId)['IS_DEC'];
  485. if(!$isDec){
  486. return static::notice(Yii::t('app', 'decUserNameIsWrong'), 400);
  487. }
  488. }
  489. $conUserName = trim($post['conUserName']); // 实际推荐人
  490. $recUserName = trim($post['recUserName']);
  491. // 如果推荐人和实际推荐人是同一人,则跳过检查
  492. if ($recUserName != $conUserName) {
  493. // 实际推荐人必须是推荐人的推荐网上级
  494. $sqlUp = <<<SQL
  495. WITH recursive t_rec AS
  496. (
  497. SELECT
  498. m.USER_ID,
  499. U.USER_NAME,
  500. m.PARENT_UID,
  501. U2.USER_NAME AS PARENT_NAME,
  502. 1 AS node_level
  503. FROM
  504. AR_USER_RELATION_NEW m
  505. LEFT JOIN AR_USER U ON U.ID = m.USER_ID
  506. LEFT JOIN AR_USER U2 ON U2.ID = m.PARENT_UID
  507. WHERE
  508. U.USER_NAME = :USER_NAME
  509. UNION ALL
  510. SELECT
  511. t1.USER_ID,
  512. U.USER_NAME,
  513. t1.PARENT_UID,
  514. U2.USER_NAME AS PARENT_NAME,
  515. t2.node_level + 1 -- 结点层级
  516. FROM
  517. AR_USER_RELATION_NEW t1
  518. JOIN t_rec t2 ON t2.PARENT_UID = t1.USER_ID
  519. LEFT JOIN AR_USER U ON U.ID = t1.USER_ID
  520. LEFT JOIN AR_USER U2 ON U2.ID = t1.PARENT_UID
  521. )
  522. SELECT
  523. *
  524. FROM
  525. t_rec
  526. SQL;
  527. // 查询推荐人的所有上级
  528. $relationNodeUp = \Yii::$app->db->createCommand($sqlUp)
  529. ->bindValue(':USER_NAME', $post['recUserName'])
  530. ->queryAll();
  531. $relationNodeUp = array_column($relationNodeUp, 'USER_NAME');
  532. unset($relationNodeUp[$post['recUserName']]);
  533. if (!in_array($post['conUserName'], $relationNodeUp)) {
  534. return static::notice(Yii::t('app', 'fillSponsorUpline'), 400);
  535. }
  536. }
  537. // 根据支付方式区分逻辑
  538. $payMethod = \Yii::$app->request->post('payType', '');
  539. if ($payMethod === 'pay_stack') {
  540. $formModel = new ApproachDeclarationLoopForm();
  541. } else {
  542. unset($post['payType']);
  543. $formModel = new DeclarationLoopForm();
  544. }
  545. $formModel->scenario = 'userDec';
  546. $post['province'] = $post['province'] ? :1;
  547. $post['city'] = $post['city'] ? :1;
  548. $post['county'] = $post['county'] ? :1;
  549. $post['cityName'] = trim($post['cityName']);
  550. $post['lgaName'] = trim($post['lgaName']);
  551. // 针对那群沙雕移除安置网络的行为,强制增加自动安置左侧
  552. $recUserId = Info::getUserIdByUserName($conUserName);
  553. $bottomPlace = UserNetwork::getBottomPlace($recUserId,'', 'left');
  554. $bottomUser = UserNetwork::find()->select('USER_ID')->where('LOCATION_TAG=:LOCATION_TAG', ['LOCATION_TAG' => $bottomPlace])->asArray()->one();
  555. $bottomUser = User::findOneAsArray('ID=:ID', [':ID' => $bottomUser['USER_ID']], 'USER_NAME');
  556. $bottomUser = $bottomUser['USER_NAME']; // 推算出的安置人
  557. $post['conUserName'] = $bottomUser; // 安置人
  558. $post['recUserName'] = $conUserName; // 实际推荐人
  559. $post['bottomUserName'] = $recUserName; // 推荐人
  560. $post['location'] = 1;
  561. // 针对于会员编号的判断
  562. $insertUserName = strtoupper($post['insertUserName']);
  563. $getRedisUserName = $redis->get('key_' . $insertUserName);
  564. if (!$getRedisUserName){
  565. return static::notice(Yii::t('app', 'memberNumberExpired'), 400);
  566. }
  567. if ($insertUserName != $getRedisUserName){
  568. return static::notice(Yii::t('app', 'memberNumberDoesNotConformTo'), 400);
  569. }
  570. $post['insertUserName'] = $insertUserName;
  571. $post['type'] = DeclarationForm::TYPE_ZC;
  572. $allData['data'][] = $post;
  573. if ($formModel->load($allData, '') && $result = $formModel->add()) {
  574. return static::notice($result);//报单成功
  575. } else {
  576. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  577. }
  578. }
  579. // 默认国家
  580. $countryId = \Yii::$app->request->get('countryId');
  581. if (!$countryId) {
  582. return static::notice(Yii::t('app', 'countryDoesNotSelect'), 400);
  583. }
  584. // 生成随机码 , 初始化redis
  585. $userName = Info::generateWebName($countryId);
  586. //所有报单套餐
  587. $allDecPackage = DeclarationPackage::getAllData();
  588. $decLevels = Cache::getDecLevelConfig();
  589. foreach ($allDecPackage as $k=>$v){
  590. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  591. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  592. }
  593. //所有自选商品
  594. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  595. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  596. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  597. $query_condition = " AND (1<>1";
  598. if(!$isDecReg || ($isDecReg && $isDec==1)){
  599. $query_condition = " AND (FIND_IN_SET(1, S.GIFT_TYPE)>0";
  600. }
  601. if($isStudio==1){
  602. $query_condition .= " OR FIND_IN_SET(3, S.GIFT_TYPE)>0";
  603. }
  604. $query_condition .= ") AND (S.INSTALMENT=0 OR S.INSTALMENT=1) AND N.COUNTRY_ID=:COUNTRY_ID";
  605. // 只查询普通商品
  606. $allGoods = ShopGoods::find()
  607. ->alias('S')
  608. ->select('S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID,C.CODE')
  609. ->join('INNER JOIN', ShopGoodsNature::tableName() . ' AS N', 'N.GOODS_ID=S.ID')
  610. ->join('INNER JOIN', Currency::tableName() . ' AS C', 'C.ID=N.LOCAL_CURRENCY_ID')
  611. ->where("STATUS=1 AND CATEGORY_TYPE=1 " . $query_condition, [':COUNTRY_ID' => $countryId])
  612. ->orderBy('SORT ASC')
  613. ->asArray()
  614. ->all();
  615. // 银行开户行
  616. $allOpenBank = OpenBank::find()
  617. ->where('STATUS=:STATUS AND COUNTRY_ID=:COUNTRY_ID', [':STATUS' => 1, ':COUNTRY_ID' => $countryId])
  618. ->orderBy('BANK_NAME ASC')
  619. ->asArray()
  620. ->all();
  621. if (!$userName) {
  622. return static::notice(Yii::t('app', 'failedToGenerateMemberNumber'), 400);
  623. }
  624. //随机码保存在redis中方便进行比对
  625. $redis->setex('key_'.$userName , 3600 , $userName);
  626. // 报单中心会员的本地汇率
  627. $decCountryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
  628. $decCountry = Countries::getById($decCountryId);
  629. $decUserCurrencyRate = CurrencyConversions::getToUSDRate($decCountry['LOCAL_CURRENCY_ID']);
  630. // 新会员的本地汇率
  631. $country = Countries::getById($countryId);
  632. $currencyRate = CurrencyConversions::getToUSDRate($country['LOCAL_CURRENCY_ID']);
  633. // 新会员币种
  634. $currency = Currency::getById($country['LOCAL_CURRENCY_ID']);
  635. // 会员账户
  636. $userBalance = [
  637. 'cash' => 0,
  638. 'localCash' => 0,
  639. 'coin' => '',
  640. ];
  641. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  642. if ($userCash) {
  643. $userBalance['cash'] = $userCash['CASH'];
  644. $userBalance['localCash'] = Tool::convertAmount($userCash['CASH'], $decUserCurrencyRate, $currencyRate);
  645. $userBalance['coin'] = $currency['CODE'] ?? '';
  646. }
  647. // 行政区划
  648. $region = Region::getByCountryId($countryId);
  649. // 支付方式
  650. $payList = ShopGoods::payTypes();
  651. unset($payList['prp']);
  652. // 售卖方式
  653. $sellType = ShopGoods::getCategoryType();
  654. unset($sellType[0]['sell_type'][1]);
  655. return static::notice([
  656. 'allDecPackage' => $allDecPackage,
  657. 'allGoods' => $allGoods,
  658. 'allOpenBank' => $allOpenBank,
  659. 'userName' => $userName,
  660. 'payList' => $payList,
  661. 'sellType' => $sellType,
  662. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  663. 'userBalance' => $userBalance,
  664. 'isDec' => $isDec,
  665. 'decUserCurrencyRate' => $decUserCurrencyRate,
  666. 'userCurrencyRate' => $currencyRate,
  667. 'region' => $region,
  668. 'decLevel' => DeclarationLevel::getData(),
  669. ]);
  670. }
  671. /**
  672. * 报单级别套餐
  673. */
  674. public function actionDecPackage() {
  675. $decLv = \Yii::$app->request->get('id');
  676. //所有报单级别套餐
  677. $allDecPackage = DeclarationPackage::getPackageFromLevelId($decLv);
  678. return static::notice(['allDecPackage' => $allDecPackage]);
  679. }
  680. /*
  681. * 从会员名和左右,获取底部安置人
  682. *
  683. */
  684. public function actionGetAutoPlace() {
  685. $userName = \Yii::$app->request->get('userName');
  686. $side = \Yii::$app->request->get('side');
  687. $userId = Info::getUserIdByUserName($userName);
  688. $bottomPlace = UserNetwork::getBottomPlace($userId,'', $side);
  689. $bottomUser = UserNetwork::find()->select('USER_ID')->where('LOCATION_TAG=:LOCATION_TAG', ['LOCATION_TAG' => $bottomPlace])->asArray()->one();
  690. $bottomUser = User::findOneAsArray('ID=:ID', [':ID' => $bottomUser['USER_ID']], 'USER_NAME');
  691. return static::notice($bottomUser);
  692. }
  693. /**
  694. * 会员信息查询
  695. * @return mixed
  696. * @throws \yii\web\HttpException
  697. */
  698. public function actionFullInfo()
  699. {
  700. $userName = \Yii::$app->request->get('userName');
  701. $userId = Info::getUserIdByUserName($userName);
  702. $userInfo['REAL_NAME'] = '';
  703. $user = User::findOneAsArray('ID=:ID', [':ID' => $userId]);
  704. if($user){
  705. $userInfo['REAL_NAME'] = $user['REAL_NAME'];
  706. $allChildUser = UserNetwork::getFirstFloorChildren($userId);
  707. $isLocation = [1 => 'Left-Null', 2 => 'Right-Null'];
  708. if($allChildUser) {
  709. foreach ($allChildUser as $child) {
  710. if ($child['RELATIVE_LOCATION']<'3'){
  711. // $isLocation[$child['RELATIVE_LOCATION']].= 'Full';
  712. $isLocation[$child['RELATIVE_LOCATION']] = str_replace('Null', 'Full', $isLocation[$child['RELATIVE_LOCATION']]);
  713. }
  714. }
  715. }
  716. $userInfo['countryId'] = $user['COUNTRY_ID'];
  717. $userInfo['userId'] = $userId;
  718. $userInfo['isLocation'] = '('.implode(',',$isLocation).')';
  719. return static::notice($userInfo);
  720. }else{
  721. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  722. }
  723. }
  724. public function actionInspectNetwork()
  725. {
  726. // 推荐人信息
  727. $recommenderName= \Yii::$app->request->get('recommenderName');
  728. $userId = Info::getUserIdByUserName($recommenderName);
  729. $recommender = User::findOneAsArray('ID=:ID', [':ID' => $userId]);
  730. if (!$recommender) {
  731. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  732. }
  733. // 实际推荐人信息
  734. $recommenderActualName= \Yii::$app->request->get('recommenderActualName');
  735. $actualId = Info::getUserIdByUserName($recommenderActualName);
  736. $recommenderActual = User::findOneAsArray('ID=:ID', [':ID' => $actualId]);
  737. if (!$recommenderActual) {
  738. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  739. }
  740. // 实际推荐人是否是推荐人本人
  741. if ($actualId == $userId) {
  742. return static::notice([
  743. 'REAL_NAME' => $recommenderActual['REAL_NAME'],
  744. 'userId' => $recommenderActual['ID'],
  745. ]);
  746. }
  747. // 实际推荐人必须是推荐人的推荐网上级
  748. $sqlUp =<<<SQL
  749. WITH recursive t_rec AS
  750. (
  751. SELECT
  752. m.USER_ID,
  753. U.USER_NAME,
  754. m.PARENT_UID,
  755. U2.USER_NAME AS PARENT_NAME,
  756. 1 AS node_level
  757. FROM
  758. AR_USER_RELATION_NEW m
  759. LEFT JOIN AR_USER U ON U.ID = m.USER_ID
  760. LEFT JOIN AR_USER U2 ON U2.ID = m.PARENT_UID
  761. WHERE
  762. U.USER_NAME = :USER_NAME
  763. UNION ALL
  764. SELECT
  765. t1.USER_ID,
  766. U.USER_NAME,
  767. t1.PARENT_UID,
  768. U2.USER_NAME AS PARENT_NAME,
  769. t2.node_level + 1 -- 结点层级
  770. FROM
  771. AR_USER_RELATION_NEW t1
  772. JOIN t_rec t2 ON t2.PARENT_UID = t1.USER_ID
  773. LEFT JOIN AR_USER U ON U.ID = t1.USER_ID
  774. LEFT JOIN AR_USER U2 ON U2.ID = t1.PARENT_UID
  775. )
  776. SELECT
  777. *
  778. FROM
  779. t_rec
  780. SQL;
  781. // 查询推荐人的所有上级
  782. $relationNodeUp = \Yii::$app->db->createCommand($sqlUp)
  783. ->bindValue(':USER_NAME' , $recommenderName)
  784. ->queryAll();
  785. $relationNodeUp = array_column($relationNodeUp, 'USER_NAME');
  786. unset($relationNodeUp[$recommenderName]);
  787. if (in_array($recommenderActualName, $relationNodeUp)) {
  788. return static::notice([
  789. 'REAL_NAME' => $recommenderActual['REAL_NAME'],
  790. 'userId' => $recommenderActual['ID'],
  791. ]);
  792. }
  793. return static::notice(Yii::t('ctx', 'fillSponsorUpline'), 400);
  794. }
  795. /**
  796. * 复消会员信息查询
  797. * @return mixed
  798. * @throws \yii\web\HttpException
  799. */
  800. public function actionUserBaseInfo()
  801. {
  802. $userName = \Yii::$app->request->get('userName');
  803. $userId = Info::getUserIdByUserName($userName);
  804. if($userId){
  805. $allAddress = ReceiveAddress::findAllAsArray('USER_ID=:USER_ID', [':USER_ID'=>$userId]);
  806. if($allAddress) {
  807. foreach ($allAddress as $key => $row) {
  808. $allAddress[$key]['PROVINCE_NAME'] = Region::getCnName($row['PROVINCE']);
  809. $allAddress[$key]['CITY_NAME'] = Region::getCnName($row['CITY']);
  810. $allAddress[$key]['COUNTY_NAME'] = Region::getCnName($row['COUNTY']);
  811. }
  812. }
  813. $userInfo = Info::baseInfoWithNet($userId);
  814. // $decLevelConfig = Cache::getDecLevelConfig();
  815. // $empLevelConfig = Cache::getEmpLevelConfig();
  816. $arr = [
  817. 'REAL_NAME'=>$userInfo['REAL_NAME'],
  818. // 'DEC_LEVEL_NAME' => $decLevelConfig[$userInfo['DEC_LV']]['LEVEL_NAME'],
  819. // 'EMP_LEVEL_NAME'=>$empLevelConfig[$userInfo['EMP_LV']]['LEVEL_NAME'],
  820. // 'REC_UID'=>$userInfo['REC_USER_NAME'].'('.$userInfo['REC_REAL_NAME'].')',
  821. // 'CON_UID'=>$userInfo['CON_USER_NAME'].'('.$userInfo['CON_REAL_NAME'].')',
  822. 'allAddress'=>$allAddress
  823. ];
  824. return static::notice($arr);
  825. }else{
  826. return static::notice(Yii::t('app', 'repeatSalesMemberNoDoesNotExist'), 400);
  827. }
  828. }
  829. /**
  830. * 会员资料
  831. * @return mixed
  832. * @throws \yii\web\HttpException
  833. */
  834. public function actionBaInfo()
  835. {
  836. $data['userInfo'] = BaUser::getEnCodeInfo(\Yii::$app->user->id);
  837. $data['userInfo']['NATION'] = $data['userInfo']['NATION_ID'];
  838. // 推荐人
  839. $baUserInfo = BaUserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => \Yii::$app->user->id]);
  840. $sponsor = User::findOneAsArray('ID=:USER_ID', [':USER_ID' => $baUserInfo['REC_UID']]);
  841. $data['userInfo']['SponsorCode'] = $sponsor['USER_NAME'];
  842. $data['userInfo']['SponsorName'] = $sponsor['REAL_NAME'];
  843. return static::notice($data);
  844. }
  845. /**
  846. * 编辑会员资料
  847. * @return mixed
  848. * @throws \yii\web\HttpException
  849. */
  850. public function actionBaEdit()
  851. {
  852. if(\Yii::$app->request->isPost)
  853. {
  854. $form = new BaUserForm();
  855. $post = \Yii::$app->request->post();
  856. $form->scenario = 'modifyProfile';
  857. if ($form->load($post, '') && $result = $form->modifyProfile()){
  858. return static::notice(Yii::t('app', 'personalDataModifiedSuccessfully'), 400);
  859. } else {
  860. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  861. }
  862. }
  863. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  864. }
  865. /**
  866. * 修改登录密码
  867. */
  868. public function actionBaPassword(){
  869. if(\Yii::$app->request->isPost) {
  870. $form = new BaUserForm();
  871. $form->scenario = 'modifyPassword';
  872. $post = \Yii::$app->request->post();
  873. if($form->load($post, '') && $result = $form->modifyPassword()){
  874. return static::notice(Yii::t('app', 'passwordModifiedSuccessfully'), 400);
  875. } else {
  876. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  877. }
  878. }
  879. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  880. }
  881. /**
  882. * 修改支付密码
  883. */
  884. public function actionBaPayPassword(){
  885. if(\Yii::$app->request->isPost){
  886. $form = new BaUserForm();
  887. $form->scenario = 'modifyPasswordPay';
  888. $post = \Yii::$app->request->post();
  889. $form->userId = \Yii::$app->user->id;
  890. if($form->load($post, '') && $result = $form->modifyPasswordPay()){
  891. return static::notice(Yii::t('app', 'passwordModifiedSuccessfully'), 400);
  892. } else {
  893. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  894. }
  895. }
  896. return static::notice(Yii::t('app', 'illegalRequest'), 400);
  897. }
  898. /**
  899. * BA报单管理
  900. */
  901. public function actionBaDec() {
  902. // 生成随机码 , 初始化redis
  903. $userName = Info::generateWebUserName('NG',9);
  904. $redis = \Yii::$app->redis;
  905. $post = \Yii::$app->request->post();
  906. if (\Yii::$app->request->isPost) {
  907. // 根据支付方式区分逻辑
  908. $payMethod = \Yii::$app->request->post('payType', '');
  909. if ($payMethod === 'pay_stack') {
  910. $formModel = new BaApproachDeclarationLoopForm();
  911. } else {
  912. unset($post['payType']);
  913. $formModel = new BaDeclarationLoopForm();
  914. }
  915. $formModel->scenario = 'userDec';
  916. $post['province'] = $post['province'] ? :1;
  917. $post['city'] = $post['city'] ? :1;
  918. $post['county'] = $post['county'] ? :1;
  919. // $post['conUserName'] = trim($post['conUserName']);
  920. $post['recUserName'] = trim($post['recUserName']);
  921. $post['cityName'] = trim($post['cityName']);
  922. $post['lgaName'] = trim($post['lgaName']);
  923. // 针对于会员编号的判断
  924. $insertUserName = strtoupper($post['insertUserName']);
  925. $getRedisUserName = $redis->get('key_' . $insertUserName);
  926. if (!$getRedisUserName){
  927. return static::notice(Yii::t('app', 'memberNumberExpired'), 400);
  928. }
  929. if ($insertUserName != $getRedisUserName){
  930. return static::notice(Yii::t('app', 'memberNumberDoesNotConformTo'), 400);
  931. }
  932. $post['insertUserName'] = $insertUserName;
  933. $post['type'] = BaDeclarationForm::TYPE_ZC;
  934. $allData['data'][] = $post;
  935. if ($formModel->load($allData, '') && $result = $formModel->add()) {
  936. return static::notice($result); // 报单成功
  937. } else {
  938. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  939. }
  940. }
  941. // 只查询普通商品
  942. $allGoods = ShopGoods::find()->where("ID='375895243322691584'")->orderBy('SORT ASC')->asArray()->all();
  943. if (!$userName) {
  944. return static::notice(Yii::t('app', 'failedToGenerateMemberNumber'), 400);
  945. }
  946. //随机码保存在redis中方便进行比对
  947. $redis->setex('key_'.$userName , 3600 , $userName);
  948. // 会员账户
  949. $userBalance = [
  950. 'cash' => 0,
  951. // 'tourism_points' => 0,
  952. // 'garage_points' => 0,
  953. // 'villa_points' => 0,
  954. ];
  955. $userCash = UserWallet::findOneAsArray(['USER_ID' => \Yii::$app->user->id]);
  956. if ($userCash) {
  957. $userBalance['cash'] = $userCash['CASH'];
  958. }
  959. return static::notice([
  960. 'allGoods' => $allGoods,
  961. 'userName' => $userName,
  962. 'payList' => ShopGoods::payTypes(),
  963. 'sellType' => ShopGoods::getCategoryType(),
  964. 'categoryType' => ShopGoods::getCategoryType()[0]['id'],
  965. 'userBalance' => $userBalance,
  966. ]);
  967. }
  968. /**
  969. * BA会员信息
  970. * @return mixed
  971. * @throws \yii\web\HttpException
  972. */
  973. public function actionBaUserInfo()
  974. {
  975. $userName = \Yii::$app->request->get('userName');
  976. $userId = Info::getBaUserIdByUserName($userName);
  977. $userInfo['REAL_NAME'] = '';
  978. $user = BaUser::findOneAsArray('ID=:ID', [':ID' => $userId], 'REAL_NAME');
  979. $uInfo = BaUserInfo::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId], 'REC_UID');
  980. if($user){
  981. $rec_user = UserInfo::findOneAsArray('USER_ID=:USER_ID',[':USER_ID' => $uInfo['REC_UID']], 'USER_ID, USER_NAME');
  982. $userInfo['REAL_NAME'] = $user['REAL_NAME'];
  983. $userInfo['REC_USER_ID'] = $rec_user['USER_ID'];
  984. $userInfo['REC_USER_NAME'] = $rec_user['USER_NAME'];
  985. return static::notice($userInfo);
  986. }else{
  987. return static::notice(Yii::t('app', 'memberNumberDoesNotExist'), 400);
  988. }
  989. }
  990. }