UserController.php 35 KB

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