UserController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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\user\Info;
  12. use common\models\DeclarationPackage;
  13. use common\models\forms\DeclarationForm;
  14. use common\models\forms\DeclarationLoopForm;
  15. use common\models\forms\UploadForm;
  16. use common\models\forms\UserBindForm;
  17. use common\models\forms\UserForm;
  18. use common\models\OpenBank;
  19. use common\models\ReceiveAddress;
  20. use common\models\Region;
  21. use common\models\ShopGoods;
  22. use common\models\User;
  23. use common\models\UserBind;
  24. use common\models\UserInfo;
  25. use common\models\UserNetwork;
  26. use yii\web\UploadedFile;
  27. class UserController extends BaseController {
  28. public $modelClass = UserInfo::class;
  29. /**
  30. * 会员资料
  31. * @return mixed
  32. * @throws \yii\web\HttpException
  33. */
  34. public function actionIndex() {
  35. $allNation = \Yii::$app->params['nation'];
  36. $allOpenBank = OpenBank::findAllAsArray('STATUS=1');
  37. $data['allNation'] = $allNation;
  38. $data['allOpenBank'] = $allOpenBank;
  39. $data['userInfo'] = User::getEnCodeInfo(\Yii::$app->user->id);
  40. $data['userInfo']['NATION'] = $data['userInfo']['NATION_ID'];
  41. return static::notice($data);
  42. }
  43. /**
  44. * 编辑会员资料
  45. * @return mixed
  46. * @throws \yii\web\HttpException
  47. */
  48. public function actionEdit() {
  49. if(\Yii::$app->request->isPost){
  50. $form = new UserForm();
  51. $post = \Yii::$app->request->post();
  52. $form->scenario = 'modifyProfile';
  53. if($form->load($post, '') && $result = $form->modifyProfile()){
  54. return static::notice('个人资料修改成功');
  55. } else {
  56. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  57. }
  58. }
  59. return static::notice('非法访问', 400);
  60. }
  61. /**
  62. * 修改登录密码
  63. */
  64. public function actionPassword(){
  65. if(\Yii::$app->request->isPost){
  66. $form = new UserForm();
  67. $form->scenario = 'modifyPassword';
  68. $post = \Yii::$app->request->post();
  69. if($form->load($post, '') && $result = $form->modifyPassword()){
  70. return static::notice('密码修改成功');
  71. } else {
  72. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  73. }
  74. }
  75. return static::notice('非法访问', 400);
  76. }
  77. /**
  78. * 修改支付密码
  79. */
  80. public function actionPayPassword(){
  81. if(\Yii::$app->request->isPost){
  82. $form = new UserForm();
  83. $form->scenario = 'modifyPasswordPay';
  84. $post = \Yii::$app->request->post();
  85. $form->userId = \Yii::$app->user->id;
  86. if($form->load($post, '') && $result = $form->modifyPasswordPay()){
  87. return static::notice('支付密码修改成功');
  88. } else {
  89. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  90. }
  91. }
  92. return static::notice('非法访问', 400);
  93. }
  94. /**
  95. * 直推会员列表
  96. * @return mixed
  97. * @throws \yii\web\HttpException
  98. */
  99. public function actionRecUser() {
  100. $allData = UserInfo::lists('AND REC_UID=:REC_UID', [':REC_UID' => \Yii::$app->user->id], ['useSlaves' => true, 'select'=>'USER_ID,CREATED_AT']);
  101. foreach ($allData['list'] as $key => $data) {
  102. $userBaseInfo = User::getEnCodeInfo($data['USER_ID']);
  103. $userBaseInfo['NATION'] = \Yii::$app->params['nation'][$userBaseInfo['NATION']]['name'] ?? '';
  104. $allData['list'][$key]['BASE_INFO'] = $userBaseInfo;
  105. }
  106. return static::notice($allData);
  107. }
  108. /**
  109. * 上传身份证
  110. * @return mixed
  111. * @throws \yii\base\Exception
  112. * @throws \yii\web\HttpException
  113. */
  114. public function actionIdCard() {
  115. if (\Yii::$app->request->isPost) {
  116. $formModel = new UploadForm();
  117. $formModel->scenario = 'idCardFront';
  118. $formModel->file = UploadedFile::getInstanceByName('file');
  119. //$formModel->token = \Yii::$app->request->post('uploadToken');
  120. $formModel->token = \Yii::$app->request->request('uploadToken');;
  121. if ($formModel->file && $formModel->upload()) {
  122. return static::notice('上传成功');
  123. } else {
  124. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  125. }
  126. }
  127. // 查看该用户是否已经上传过身份证
  128. $oneData = User::find()->select('ID_IMAGE')->where('ID=:ID', [':ID' => \Yii::$app->user->id])->asArray()->one();
  129. if ($oneData['ID_IMAGE']) {
  130. return static::notice($oneData);
  131. } else {
  132. $token = Cache::setUploadToken();
  133. return static::notice($token);
  134. }
  135. }
  136. /**
  137. * 点位绑定
  138. * @return mixed
  139. * @throws \yii\base\Exception
  140. * @throws \yii\web\HttpException
  141. */
  142. public function actionBind() {
  143. $userBind = UserBind::findOneAsArray('USER_ID=:USER_ID AND IS_DEL=0', [':USER_ID' => \Yii::$app->user->id]);
  144. $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');
  145. foreach ($allData['list'] as $key => $value) {
  146. $baseInfo = Info::baseInfoZh($value['USER_ID']);
  147. if ($baseInfo['STATUS'] != 1) {
  148. unset($allData['list'][$key]);
  149. continue;
  150. }
  151. $allData['list'][$key]['USER_NAME'] = $baseInfo['USER_NAME'];
  152. $allData['list'][$key]['REAL_NAME'] = $baseInfo['REAL_NAME'];
  153. $allData['list'][$key]['BANK_PROVINCE_NAME'] = $baseInfo['BANK_PROVINCE_NAME'];
  154. $allData['list'][$key]['BANK_CITY_NAME'] = $baseInfo['BANK_CITY_NAME'];
  155. $allData['list'][$key]['BANK_COUNTY_NAME'] = $baseInfo['BANK_COUNTY_NAME'];
  156. $allData['list'][$key]['OPEN_BANK_NAME'] = $baseInfo['OPEN_BANK_NAME'];
  157. $allData['list'][$key]['BANK_NO'] = $baseInfo['BANK_NO'];
  158. $allData['list'][$key]['MAIN_USER_NAME'] =Info::getUserNameByUserId($value['MAIN_UID']);
  159. }
  160. $allData['list'] = array_values($allData['list']);
  161. return static::notice($allData);
  162. }
  163. /**
  164. * 编辑点位绑定
  165. * @return mixed
  166. * @throws \yii\web\HttpException
  167. */
  168. public function actionBindEdit(){
  169. $id = \Yii::$app->request->get('id');
  170. if(\Yii::$app->request->isPost) {
  171. return parent::edit(UserBindForm::class, '修改主点位成功', 'frontEdit', ['frontEdit'], null, function($form, $result){
  172. //log
  173. });
  174. }
  175. // 获得当前会员的用户名等信息
  176. $userBind = UserBind::findOneAsArray('ID=:ID AND IS_DEL=0', [':ID' => $id]);
  177. $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');
  178. foreach($userBinds as $key=>$value){
  179. $status = Info::getStatusByUserId($value['USER_ID']);
  180. if ($status != 1) {
  181. unset($userBinds[$key]);
  182. continue;
  183. }
  184. $userBinds[$key]['USER_NAME'] = Info::getUserNameByUserId($value['USER_ID']);
  185. }
  186. $userBinds = array_values($userBinds);
  187. return static::notice(['userBinds' => $userBinds,'mainUid'=>$userBind['MAIN_UID']]);
  188. }
  189. /**
  190. * 报单管理
  191. */
  192. public function actionDec() {
  193. // 生成随机码 , 初始化redis
  194. $userName = Info::generateWebUserName('CQ',9);
  195. $redis = \Yii::$app->redis;
  196. if (\Yii::$app->request->isPost) {
  197. $formModel = new DeclarationLoopForm();
  198. $formModel->scenario = 'userDec';
  199. $post = \Yii::$app->request->post();
  200. // 针对于会员编号的判断
  201. $insertUserName = strtoupper($post['insertUserName']);
  202. $getRedisUserName = $redis->get('key_'.$insertUserName);
  203. if (!$getRedisUserName){
  204. return static::notice('会员编号过期',400);
  205. }
  206. if ($insertUserName != $getRedisUserName){
  207. return static::notice('会员编号不符合',400);
  208. }
  209. $post['insertUserName'] = $insertUserName;
  210. $post['type'] = DeclarationForm::TYPE_ZC;
  211. $allData['data'][] = $post;
  212. if ($formModel->load($allData, '') && $formModel->add()) {
  213. return static::notice('报单成功');
  214. } else {
  215. return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
  216. }
  217. }
  218. //所有报单套餐
  219. $allDecPackage = DeclarationPackage::getAllData();
  220. $decLevels = Cache::getDecLevelConfig();
  221. foreach ($allDecPackage as $k=>$v){
  222. $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
  223. $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
  224. }
  225. //所有自选商品
  226. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  227. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  228. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  229. $query_condition= " AND (1<>1";
  230. if(!$isDecReg || ($isDecReg && $isDec==1)){
  231. $query_condition = " AND (FIND_IN_SET(1,GIFT_TYPE)>0";
  232. }
  233. if($isStudio==1){
  234. $query_condition.= " OR FIND_IN_SET(3,GIFT_TYPE)>0";
  235. }
  236. $query_condition.= ")";
  237. $allGoods = ShopGoods::find()->where("STATUS=1 ".$query_condition)->orderBy('SORT ASC')->asArray()->all();
  238. //$allGoods = ShopGoods::findAllAsArray('STATUS=1');
  239. // 所有开户行
  240. $allOpenBank = OpenBank::find()->where('STATUS=1')->orderBy('LIST_ORDER ASC')->asArray()->all();
  241. if (!$userName) {
  242. return static::notice('会员编号生成失败', 400);
  243. }
  244. //随机码保存在redis中方便进行比对
  245. $msg = $redis->setex('key_'.$userName , 1800 , $userName);
  246. return static::notice(['allDecPackage' => $allDecPackage,'allGoods' => $allGoods,'allOpenBank' => $allOpenBank, 'userName' => $userName]);
  247. }
  248. /**
  249. * 报单级别套餐
  250. */
  251. public function actionDecPackage() {
  252. $decLv = \Yii::$app->request->get('id');
  253. //所有报单级别套餐
  254. $allDecPackage = DeclarationPackage::getPackageFromLevelId($decLv);
  255. return static::notice(['allDecPackage' => $allDecPackage]);
  256. }
  257. /**
  258. * 会员信息查询
  259. * @return mixed
  260. * @throws \yii\web\HttpException
  261. */
  262. public function actionFullInfo()
  263. {
  264. $userName = \Yii::$app->request->get('userName');
  265. $userId = Info::getUserIdByUserName($userName);
  266. $userInfo['REAL_NAME'] = '';
  267. $user = User::findOneAsArray('ID=:ID', [':ID' => $userId], 'REAL_NAME');
  268. if($user){
  269. $userInfo['REAL_NAME'] = $user['REAL_NAME'];
  270. $allChildUser = UserNetwork::getFirstFloorChildren($userId);
  271. $isLocation = [1 => '左-', 2 => '中-', 3 => '右-'];
  272. if($allChildUser) {
  273. foreach ($allChildUser as $child) {
  274. $isLocation[$child['RELATIVE_LOCATION']].= '满';
  275. }
  276. }
  277. $userInfo['isLocation'] = '('.implode(',',$isLocation).')';
  278. return static::notice($userInfo);
  279. }else{
  280. return static::notice('会员编号不存在', 400);
  281. }
  282. }
  283. /**
  284. * 复消会员信息查询
  285. * @return mixed
  286. * @throws \yii\web\HttpException
  287. */
  288. public function actionUserBaseInfo()
  289. {
  290. $userName = \Yii::$app->request->get('userName');
  291. $userId = Info::getUserIdByUserName($userName);
  292. if($userId){
  293. $allAddress = ReceiveAddress::findAllAsArray('USER_ID=:USER_ID', [':USER_ID'=>$userId]);
  294. if($allAddress) {
  295. foreach ($allAddress as $key => $row) {
  296. $allAddress[$key]['PROVINCE_NAME'] = Region::getCnName($row['PROVINCE']);
  297. $allAddress[$key]['CITY_NAME'] = Region::getCnName($row['CITY']);
  298. $allAddress[$key]['COUNTY_NAME'] = Region::getCnName($row['COUNTY']);
  299. }
  300. }
  301. $userInfo = Info::baseInfoWithNet($userId);
  302. // $decLevelConfig = Cache::getDecLevelConfig();
  303. // $empLevelConfig = Cache::getEmpLevelConfig();
  304. $arr = [
  305. 'REAL_NAME'=>$userInfo['REAL_NAME'],
  306. // 'DEC_LEVEL_NAME' => $decLevelConfig[$userInfo['DEC_LV']]['LEVEL_NAME'],
  307. // 'EMP_LEVEL_NAME'=>$empLevelConfig[$userInfo['EMP_LV']]['LEVEL_NAME'],
  308. // 'REC_UID'=>$userInfo['REC_USER_NAME'].'('.$userInfo['REC_REAL_NAME'].')',
  309. // 'CON_UID'=>$userInfo['CON_USER_NAME'].'('.$userInfo['CON_REAL_NAME'].')',
  310. 'allAddress'=>$allAddress
  311. ];
  312. return static::notice($arr);
  313. }else{
  314. return static::notice('复消会员编号不存在', 400);
  315. }
  316. }
  317. }