UserController.php 34 KB

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