UserController.php 12 KB

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