CenterController.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. <?php
  2. namespace mobile\controllers;
  3. use biz\goods\services\CategoryRelateService;
  4. use biz\goods\services\CategoryService;
  5. use biz\goods\services\UsageRelationService;
  6. use biz\tool\services\CouponModelService;
  7. use biz\tool\services\CouponRewardService;
  8. use biz\tool\services\CouponRightService;
  9. use biz\tool\services\CouponService;
  10. use biz\user\services\UserAssetService;
  11. use biz\user\services\UserOldDataService;
  12. use biz\user\services\UserService;
  13. use Yii;
  14. use yii\helpers\Json;
  15. use common\models\xhOrderGoods;
  16. use common\models\xhUserCapital;
  17. use common\models\xhUserIntegral;
  18. use common\components\qrCodeUtil;
  19. use common\components\stringUtil;
  20. use common\components\weixinUtil;
  21. use common\components\configDict;
  22. use common\components\util;
  23. use common\services\xhCommonService;
  24. use common\services\xhUserService;
  25. use common\services\xhGoodsService;
  26. use common\services\xhTrainStudentService;
  27. use common\services\xhMerchantExtendService;
  28. use common\services\xhUnionUserService;
  29. use common\services\xhOrderService;
  30. use common\services\xhUserAssetService;
  31. use common\services\xhCouponService;
  32. use common\services\xhTrainUserCourseService;
  33. use common\services\xhUserIntegralService;
  34. class CenterController extends MobileendController
  35. {
  36. public $layout = 'centerMain';
  37. public function actionIndex()
  38. {
  39. $id = $this->userId;
  40. CouponService::paySuccessGetCoupon();
  41. $userAsset = xhUserAssetService::getByUserId($id);
  42. return $this->render('index', ['user' => $this->user, 'userAsset' => $userAsset]);
  43. }
  44. public function actionOrder()
  45. {
  46. $order = xhOrderService::getAllByCondition(['userId' => $this->userId]);
  47. $payStatusName = configDict::getConfig('payStatusName');
  48. return $this->render('order', ['order' => $order, 'payStatusName' => $payStatusName]);
  49. }
  50. public function actionOrderDetail()
  51. {
  52. $get = Yii::$app->request->get();
  53. $id = isset($get['id']) ? $get['id'] : 0;
  54. $order = xhOrderService::getById($id);
  55. if ($order['userId'] != $this->userId) {
  56. util::stop('非法访问');
  57. }
  58. if ($order['sourceType'] == 0) {//0商城订单
  59. $goodsList = xhOrderGoods::getAllByCondition(['orderId' => $id]);
  60. foreach ($goodsList as $key => $good) {
  61. $goodsId = $good['goodsId'];
  62. $goodsData = xhGoodsService::getById($goodsId);
  63. if ($goodsData['goodsName'] != $good['title']) {
  64. $subTitle = $good['title'];
  65. $goodsList[$key]['title'] = $goodsData['goodsName'];
  66. $goodsList[$key]['subTitle'] = $subTitle;
  67. }
  68. }
  69. } else if ($order['sourceType'] == 1) {//1付款订单
  70. $goodsList = [];
  71. } else {
  72. util::stop('未知订单类型');
  73. }
  74. $payWayNameList = configDict::getConfig('payWayName');
  75. $payStatusName = configDict::getConfig('payStatusName');
  76. $sendStatus = configDict::getConfig('sendStatus');
  77. $sendStatusName = configDict::getConfig('sendStatusName');
  78. return $this->render('orderDetail', ['sendStatusName' => $sendStatusName, 'sendStatus' => $sendStatus, 'payStatusName' => $payStatusName, 'payWayNameList' => $payWayNameList, 'order' => $order, 'goodsList' => $goodsList]);
  79. }
  80. /**
  81. * 我的二维码
  82. */
  83. public function actionQrCode()
  84. {
  85. $get = Yii::$app->request->get();
  86. $userAsset = xhUserAssetService::getByUserId($this->userId);
  87. $uniqueQrCode = $userAsset['uniqueQrCode'];
  88. $userId = $this->userId;
  89. $string = configDict::getQrKey('user') . $userId;
  90. $webRoot = Yii::getAlias('@webroot') . '/../../../../resource/images/';
  91. if (empty($uniqueQrCode) || file_exists($webRoot . $uniqueQrCode) == false) {
  92. $logo = !empty($this->merchant['logo']) ? $webRoot . $this->merchant['logo'] : '';
  93. $uniqueQrCode = qrCodeUtil::card($string, '', $logo);
  94. xhUserAssetService::updateByUserId($this->userId, ['uniqueQrCode' => $uniqueQrCode]);
  95. }
  96. //正在呼叫
  97. $discount = '';
  98. if (!empty($userAsset) && $userAsset['isMember'] == 1) {
  99. $gradeList = xhMerchantExtendService::getGradeList($this->merchantExtend, 'desc');
  100. $level = $userAsset['memberLevel'];
  101. $discount = $gradeList[$level]['discount'];
  102. }
  103. return $this->render('qrCode', ['uniqueQrCode' => $uniqueQrCode, 'userAsset' => $userAsset, 'user' => $this->user, 'discount' => $discount]);
  104. }
  105. public function actionStudentCard()
  106. {
  107. $student = xhTrainStudentService::getByUserId($this->userId);
  108. $uniqueQrCode = $userAsset['uniqueQrCode'];
  109. $string = configDict::getQrKey('xhStudent') . $this->userId;
  110. $unique = $string;
  111. if (empty($uniqueQrCode)) {
  112. $webRoot = Yii::getAlias('@webroot') . '/../../../resource/images/';
  113. $logo = !empty($this->merchant['logo']) ? $webRoot . $this->merchant['logo'] : '';
  114. $uniqueQrCode = qrCodeUtil::generate($string, $unique, $logo);
  115. xhTrainStudentService::updateByUserId($this->userId, ['uniqueQrCode' => $uniqueQrCode]);
  116. }
  117. return $this->render('studentCard', ['uniqueQrCode' => $uniqueQrCode, 'student' => $student, 'user' => $this->user]);
  118. }
  119. /**
  120. * 获取集赞排行榜
  121. */
  122. public function actionGetPraiseRank()
  123. {
  124. $weekReturn = Yii::$app->redis->executeCommand('ZREVRANGE', ["merchant{$this->merchantId}UserWeek" . date("Y-W") . "PraiseNum", 0, 10, 'WITHSCORES']);
  125. $weekRank = [];
  126. if (!empty($weekReturn)) {
  127. $i = 0;
  128. $x = 0;
  129. foreach ($weekReturn as $key => $val) {
  130. $i++;
  131. if ($i % 2 == 0) {
  132. $weekRank[$x]['praiseNum'] = $val;
  133. $x++;
  134. } else {
  135. $userInfo = xhUserService::getById($val);
  136. unset($userInfo['payPassword']);
  137. unset($userInfo['password']);
  138. $weekRank[$x]['userInfo'] = $userInfo;
  139. }
  140. }
  141. }
  142. $monthReturn = Yii::$app->redis->executeCommand('ZREVRANGE', ["merchant{$this->merchantId}UserMonth" . date("Y-m") . "PraiseNum", 0, 10, 'WITHSCORES']);
  143. $monthRank = [];
  144. if (!empty($monthReturn)) {
  145. $i = 0;
  146. $x = 0;
  147. foreach ($monthReturn as $key => $val) {
  148. $i++;
  149. if ($i % 2 == 0) {
  150. $monthRank[$x]['praiseNum'] = $val;
  151. $x++;
  152. } else {
  153. $userInfo = xhUserService::getById($val);
  154. unset($userInfo['payPassword']);
  155. unset($userInfo['password']);
  156. $monthRank[$x]['userInfo'] = $userInfo;
  157. }
  158. }
  159. }
  160. return $this->renderPartial('getPraiseRank', ['weekRank' => $weekRank, 'monthRank' => $monthRank]);
  161. }
  162. /**
  163. * 支付密码设置
  164. * @return string
  165. */
  166. public function actionPassword()
  167. {
  168. return $this->render('password', ['user' => $this->user]);
  169. }
  170. /**
  171. * 修改支付密码
  172. */
  173. public function actionModifyPayPassword()
  174. {
  175. $post = Yii::$app->request->post();
  176. $prePassword = isset($post['prePassword']) ? $post['prePassword'] : '';
  177. $sqlpwd = $this->user['payPassword'];
  178. if (empty($sqlpwd) || md5($prePassword) == $sqlpwd) {
  179. xhUserService::updateById($this->userId, ['payPassword' => md5($post['password'])]);
  180. util::successInfo();
  181. }
  182. util::failInfo('没有修改成功');
  183. }
  184. /**
  185. * 我的资料
  186. */
  187. public function actionInfo()
  188. {
  189. $merchantAccount = $this->merchant['id'];
  190. return $this->render('info', ['user' => $this->user, 'merchantAccount' => $merchantAccount]);
  191. }
  192. /**
  193. * 用户修改个人信息,验证手机号
  194. */
  195. public function actionMobileNotUsed()
  196. {
  197. $get = Yii::$app->request->get();
  198. $mobile = isset($get['mobile']) ? $get['mobile'] : '';
  199. $status = xhUserService::mobileNotUsed($mobile, $this->merchantId);
  200. if ($status) {
  201. util::successInfo('');
  202. }
  203. util::failInfo('');
  204. }
  205. /**
  206. * 修改用户信息,生成验证码
  207. */
  208. public function actionGenerateAuthCode()
  209. {
  210. $get = Yii::$app->request->get();
  211. if (isset($get['mobile'])) {
  212. $mobile = $_GET['mobile'];
  213. if (stringUtil::isMobieNumber($mobile) == false) {
  214. echo Json::encode(['code' => 'A0002', 'msg' => '手机号填写有误']);
  215. Yii::$app->end();
  216. }
  217. $status = xhUserService::mobileNotUsed($mobile, $this->merchantId);
  218. if ($status == false) {
  219. echo Json::encode(['code' => 'A0002', 'msg' => '手机号已经被使用']);
  220. Yii::$app->end();
  221. }
  222. $now = time();
  223. if (isset(Yii::$app->session['modifyUserMobileAuthCode']) == false || ($now - Yii::$app->session['modifyUserMobileAuthCodeTime']) > 120) {
  224. $num = stringUtil::getRandNum(5);
  225. Yii::$app->session['modifyUserMobileAuthCode'] = $num;
  226. Yii::$app->session['modifyUserMobileAuthCodeTime'] = time();
  227. $msg = "您的验证码:" . $num;
  228. echo Json::encode(['code' => 'A0001', 'msg' => '', 'data' => '']);
  229. xhCommonService::sendMobileMsg($mobile, $msg, $this->merchant);
  230. }
  231. }
  232. }
  233. /**
  234. * 修改用户信息,检测验证码
  235. */
  236. public function actionCheckAuthCode()
  237. {
  238. $get = Yii::$app->request->get();
  239. if (isset($get['authCode']) && isset(Yii::$app->session['modifyUserMobileAuthCode'])) {
  240. if ($get['authCode'] == Yii::$app->session['modifyUserMobileAuthCode']) {
  241. echo Json::encode(['code' => 'A0001', 'msg' => '', 'data' => []]);
  242. Yii::$app->end();
  243. }
  244. echo Json::encode(['code' => 'A0002', 'msg' => '验证码不正确', 'data' => []]);
  245. }
  246. }
  247. /**
  248. * 更新用户信息
  249. */
  250. public function actionUpdateUserInfo()
  251. {
  252. $post = Yii::$app->request->post();
  253. $session = Yii::$app->session;
  254. if (isset($post['authCode']) == false || empty($post['authCode']) || isset($session['modifyUserMobileAuthCode']) == false) {
  255. echo Json::encode(['code' => 'A0002', 'msg' => '没有验证码参数或未生成验证码', 'data' => '']);
  256. Yii::$app->end();
  257. }
  258. if ($post['authCode'] != $session['modifyUserMobileAuthCode']) {
  259. echo Json::encode(['code' => 'A0002', 'msg' => '验证码不正确', 'data' => '']);
  260. Yii::$app->end();
  261. }
  262. if (isset($post['mobile']) == false || stringUtil::isMobieNumber($post['mobile'] == false)) {
  263. echo Json::encode(['code' => 'A0002', 'msg' => '没有手机号或不符合要求', 'data' => '']);
  264. Yii::$app->end();
  265. }
  266. $mobile = $post['mobile'];
  267. $status = xhUserService::mobileNotUsed($mobile, $this->merchantId);
  268. if ($status == false) {
  269. util::failInfo('手机号已经被使用');
  270. }
  271. unset($post['_csrf']);
  272. unset($post['authCode']);
  273. unset($post['nickName']);
  274. $post['isMember'] = 1;
  275. $userId = $this->userId;
  276. /**升级成为会员**/
  277. UserService::upgradeToMember($userId,$this->merchantId, $post);
  278. util::successInfo('操作成功');
  279. }
  280. /**
  281. * 我的余额记录
  282. */
  283. public function actionMyBalance()
  284. {
  285. $capital = xhUserCapital::find()->where(['merchantId' => $this->merchantId, 'userId' => $this->userId])->orderBy('addTime desc')->all();
  286. return $this->render('myBalance', ['capital' => $capital]);
  287. }
  288. /**
  289. * 我的积分记录
  290. */
  291. public function actionMyIntegral()
  292. {
  293. $integral = xhUserIntegral::find()->where(['merchantId' => $this->merchantId, 'userId' => $this->userId])->orderBy('id desc')->all();
  294. $userAsset = xhUserAssetService::getByUserId($this->merchantId);
  295. $myIntegral = !empty($userAsset) ? $userAsset['integral'] : 0;
  296. return $this->render('myIntegral', ['integral' => $integral, 'myIntegral' => $myIntegral]);
  297. }
  298. public function actionMyIntegralDetail()
  299. {
  300. $get = Yii::$app->request->get();
  301. $id = isset($get['id']) ? $get['id'] : 0;
  302. $integral = xhUserIntegralService::getById($id);
  303. $order = [];
  304. $capitalList = configDict::getConfig('capitalType');
  305. $orderCapital = $capitalList['xhOrder']['id'];
  306. if ($integral['capitalType'] == $orderCapital) {
  307. $orderId = $integral['relateId'];
  308. if (!empty($orderId)) {
  309. $order = xhOrderService::getById($orderId);
  310. }
  311. }
  312. return $this->render('myIntegralDetail', ['integral' => $integral, 'order' => $order]);
  313. }
  314. /**
  315. * 用户聊天获取消息
  316. */
  317. public function actionGetMsg()
  318. {
  319. $merchantId = $this->merchantId;
  320. $userId = $this->userId;
  321. $get = Yii::$app->request->get();
  322. $content = Yii::$app->redis->executeCommand('RPOP', ["chat_user_get_{$merchantId}_{$userId}"]);
  323. echo Json::encode(['code' => 'A0001', 'msg' => 'success', 'data' => ['content' => $content]]);
  324. }
  325. /**
  326. * 用户聊天送消息
  327. */
  328. public function actionSendMsg()
  329. {
  330. $merchantId = $this->merchantId;
  331. $userId = $this->userId;
  332. $get = Yii::$app->request->get();
  333. if (isset($get['content']) && !empty($get['content'])) {
  334. $content = $get['content'];
  335. $now = time();
  336. Yii::$app->redis->executeCommand('LPUSH', ["chat_merchant_get_{$merchantId}_{$userId}", $now . '|' . $content]);
  337. //独立认证公众号,用户不需要使用网页接收消息,直接使用公众号聊天
  338. if (xhMerchantService::isAuth($merchantId) == false) {
  339. Yii::$app->redis->executeCommand('LPUSH', ["chat_user_get_{$merchantId}_{$userId}", $now . '|' . $content]);
  340. }
  341. }
  342. }
  343. public function actionRight()
  344. {
  345. $memberLevel = xhMerchantExtendService::getGradeList($this->merchantExtend);
  346. return $this->render('right', ['memberLevel' => $memberLevel]);
  347. }
  348. public function actionStudentRight()
  349. {
  350. $memberIntegral = configDict::getConfig('memberIntegral');
  351. return $this->render('studentRight', ['memberIntegral' => $memberIntegral]);
  352. }
  353. public function actionMyCourse()
  354. {
  355. $course = xhTrainUserCourseService::getAllByCondition(['userId' => $this->userId]);
  356. $numList = [];
  357. $time = time();
  358. foreach ($course as $key => $val) {
  359. $courseId = $val->id;
  360. $praiseNum = Yii::$app->redis->executeCommand('ZCOUNT', ["userCourse{$courseId}PraiseUser", 0, $time]);
  361. $numList[$courseId] = $praiseNum;
  362. }
  363. return $this->render('myCourse', ['course' => $course, 'numList' => $numList]);
  364. }
  365. public function actionMyCourseDetail()
  366. {
  367. $get = Yii::$app->request->get();
  368. $id = isset($get['id']) ? $get['id'] : 0;
  369. $course = xhTrainUserCourseService::getById($id);
  370. if (empty($course) || $course['userId'] != $this->userId) {
  371. echo '课程不存在或不是你的课程哦~';
  372. util::end();
  373. }
  374. return $this->render('myCourseDetail', ['course' => $course]);
  375. }
  376. public function actionUploadCourse()
  377. {
  378. $post = Yii::$app->request->post();
  379. $courseId = $post['courseId'];
  380. $mediaId = $post['mediaId'];
  381. $course = xhTrainUserCourseService::getById($courseId);
  382. if (empty($course) || $course['userId'] != $this->userId) {
  383. util::failInfo('非法课程');
  384. }
  385. $img = weixinUtil::downloadStudentWorksImg($this->merchant, $mediaId);//用mediaId从微信下载图片保存到服务器
  386. $now = time();
  387. $data = ['worksImg' => $img, 'status' => 1, 'attendTime' => $now, 'modTime' => $now, 'addTime' => $now];
  388. xhTrainUserCourseService::updateById($courseId, $data);
  389. util::successInfo('上传成功');
  390. }
  391. public function actionMyCourseShow()
  392. {
  393. $get = Yii::$app->request->get();
  394. $id = isset($get['id']) ? $get['id'] : 0;
  395. $course = xhTrainUserCourseService::getById($id);
  396. $largeImg = $course['worksImg'];
  397. $worksImgList = xhTrainUserCourseService::getWorksImgList($largeImg);
  398. $time = time();
  399. $praiseNum = Yii::$app->redis->executeCommand('ZCOUNT', ["userCourse{$id}PraiseUser", 0, $time]);//值在min和max之间的成员的数量
  400. return $this->render('myCourseShow', ['praiseNum' => $praiseNum, 'user' => $this->user, 'course' => $course, 'worksImgList' => $worksImgList]);
  401. }
  402. public function actionPraiseWorks()
  403. {
  404. $get = Yii::$app->request->get();
  405. $courseId = isset($get['courseId']) ? $get['courseId'] : 0;
  406. $course = xhTrainUserCourseService::getById($courseId);
  407. $courseUserId = $course['userId'];
  408. $userId = $this->userId;
  409. $time = time();
  410. $return = Yii::$app->redis->executeCommand('ZRANK', ["userCourse{$userCourseId}PraiseUser", "{$userId}"]);
  411. if (empty($courseUserId)) {
  412. util::failInfo('这个作品没有主人哦~');
  413. }
  414. if (isset($return)) {
  415. util::failInfo('您已经赞过了哦~');
  416. }
  417. //这个作品增加点赞用户,点赞时间
  418. Yii::$app->redis->executeCommand('ZADD', ["userCourse{$userCourseId}PraiseUser", $time, "{$userId}"]);
  419. //每个星期,用户的点赞数量+1
  420. Yii::$app->redis->executeCommand('ZINCRBY', ["merchant{$this->merchantId}UserWeek" . date("Y-W") . "PraiseNum", 1, "{$courseUserId}"]);
  421. //每个月,用户的点赞数量+1
  422. Yii::$app->redis->executeCommand('ZINCRBY', ["merchant{$this->merchantId}UserMonth" . date("Y-m") . "PraiseNum", 1, "{$courseUserId}"]);
  423. $student = xhTrainStudentService::getByUserId($courseUserId);
  424. $updatePraiseNum = $student['praiseNum'] + 1;
  425. xhTrainStudentService::updateByUserId($courseUserId, ['praiseNum' => $updatePraiseNum]);
  426. util::successInfo('+1');
  427. }
  428. /**
  429. * 获取所有点赞的人
  430. */
  431. public function actionGetPraiseUser()
  432. {
  433. $get = Yii::$app->request->get();
  434. $userCourseId = $get['userCourseId'];
  435. $userId = $this->userId;
  436. $time = time();
  437. $return = Yii::$app->redis->executeCommand('ZRANGE', ["userCourse{$userCourseId}PraiseUser", 0, 100, 'WITHSCORES']);
  438. $arr = [];
  439. $userList = [];
  440. if (!empty($return)) {
  441. $i = 0;
  442. $x = 0;
  443. foreach ($return as $key => $val) {
  444. $i++;
  445. if ($i % 2 == 0) {
  446. $arr[$x]['time'] = $val;
  447. $x++;
  448. } else {
  449. $arr[$x]['userId'] = $val;
  450. $userInfo = xhUserService::getById($val);
  451. unset($userInfo['payPassword']);
  452. unset($userInfo['password']);
  453. $userList[] = $userInfo;
  454. }
  455. }
  456. }
  457. $weekReturn = Yii::$app->redis->executeCommand('ZREVRANGE', ["merchant{$this->merchantId}UserWeek" . date("Y-W") . "PraiseNum", 0, 10, 'WITHSCORES']);
  458. $weekRank = [];
  459. if (!empty($weekReturn)) {
  460. $i = 0;
  461. $x = 0;
  462. foreach ($weekReturn as $key => $val) {
  463. $i++;
  464. if ($i % 2 == 0) {
  465. $weekRank[$x]['praiseNum'] = $val;
  466. $x++;
  467. } else {
  468. $userInfo = xhUserService::getById($val);
  469. unset($userInfo['payPassword']);
  470. unset($userInfo['password']);
  471. $weekRank[$x]['userInfo'] = $userInfo;
  472. }
  473. }
  474. }
  475. return $this->renderPartial('getPraiseUser', ['weekRank' => $weekRank, 'user' => $userList]);
  476. }
  477. /**
  478. * 代金劵
  479. */
  480. public function actionCoupon()
  481. {
  482. $coupon = xhCouponService::getUserCoupon($this->userId);
  483. return $this->render('coupon', ['coupon' => $coupon]);
  484. }
  485. /**
  486. * 生成代金劵的二维码地址
  487. */
  488. public function actionShowCouponQrcode()
  489. {
  490. $get = Yii::$app->request->get();
  491. $id = isset($get['id']) ? $get['id'] : 0;
  492. $number = isset($get['number']) ? $get['number'] : 0;
  493. $string = configDict::getQrKey('coupon') . $id;
  494. $logo = Yii::getAlias("@app") . '/../images' . $this->merchant['logo'];//取商家的logo
  495. $imgUrl = qrCodeUtil::generate($string, 'frontend_coupon_' . $this->merchantId . '_' . $id, $logo);
  496. $coupon = xhCouponService::getById($id);
  497. if (!empty($coupon)) {
  498. $id = $coupon['id'];
  499. $userId = $coupon['userId'];
  500. xhCouponService::updateById($id, $userId, ['urlQrCode' => $imgUrl]);
  501. }
  502. util::successInfo('success', 'A0001', ['url' => $imgUrl]);
  503. }
  504. //老带新优惠卷 shish 2019.8.21
  505. public function actionMyRight()
  506. {
  507. $userId = $this->userId;
  508. $respond = CouponRightService::getListData('*', ['userId' => $userId], 1, 100, 'addTime desc');
  509. $list = isset($respond['list']) ? $respond['list'] : [];
  510. $modelInfoList = [];
  511. if (!empty($list)) {
  512. $modelIds = array_column($list, 'modelId');
  513. $modelInfoList = CouponModelService::getByIds($modelIds, null, 'id');
  514. }
  515. $usageList = UsageRelationService::getMyUsage();
  516. $categoryList = CategoryRelateService::getCategoryData();
  517. return $this->renderPartial('myRight', ['list' => $list, 'usageList' => $usageList, 'categoryList' => $categoryList, 'modelInfoList' => $modelInfoList]);
  518. }
  519. //朋友已经领取,但没有使用的卷 shish 2019.9.1
  520. public function actionGetCoupon()
  521. {
  522. $userId = $this->userId;
  523. $respond = CouponService::getListData('*', ['introUserId' => $userId], 1, 100, 'addTime desc');
  524. $list = isset($respond['list']) ? $respond['list'] : [];
  525. $userInfoList = [];
  526. if (!empty($list)) {
  527. $time = time();
  528. $userIdList = array_column($list, 'userId');
  529. $userInfoList = UserService::getByIds($userIdList, null, 'id');
  530. foreach ($list as $key => $val) {
  531. if ($val['deadline'] < $time) {
  532. unset($list[$key]);
  533. }
  534. }
  535. }
  536. $usageList = UsageRelationService::getMyUsage();
  537. $categoryList = CategoryRelateService::getCategoryData();
  538. return $this->renderPartial('getCoupon', ['list' => $list, 'usageList' => $usageList, 'categoryList' => $categoryList, 'userInfoList' => $userInfoList]);
  539. }
  540. //朋友已使用的卷和奖励 shish 2019.9.1
  541. public function actionGetReward()
  542. {
  543. $userId = $this->userId;
  544. $respond = CouponRewardService::getListData('*', ['userId' => $userId], 1, 100, 'addTime desc');
  545. $list = isset($respond['list']) ? $respond['list'] : [];
  546. $userInfoList = [];
  547. if (!empty($list)) {
  548. $userIdList = array_column($list, 'invitedUserId');
  549. $userInfoList = UserService::getByIds($userIdList, null, 'id');
  550. }
  551. return $this->renderPartial('getReward', ['list' => $list, 'userInfoList' => $userInfoList]);
  552. }
  553. //我的优惠卷 shish 2019.8.27
  554. public function actionMyCoupon()
  555. {
  556. $status = Yii::$app->request->get('status', 0);
  557. $list = CouponService::getMyCoupon($status);
  558. $categoryList = CategoryRelateService::getCategoryData();
  559. $usageList = UsageRelationService::getMyUsage();
  560. return $this->renderPartial('myCoupon', ['list' => $list, 'usageList' => $usageList, 'categoryList' => $categoryList, 'status' => $status]);
  561. }
  562. //老带新优惠卷明细 shish 2019.8.25
  563. public function actionMyRightDetail()
  564. {
  565. $get = Yii::$app->request->get();
  566. $id = isset($get['id']) ? $get['id'] : 0;
  567. $info = CouponRightService::getRightDetail($id);
  568. $categoryList = CategoryRelateService::getCategoryData();
  569. $usageList = UsageRelationService::getMyUsage();
  570. return $this->renderPartial('myRightDetail', ['info' => $info, 'usageList' => $usageList, 'categoryList' => $categoryList]);
  571. }
  572. //老带新优惠卷情况 shish 2019.8.25
  573. public function actionCouponDetail()
  574. {
  575. $rightId = Yii::$app->request->get('rightId');
  576. $info = CouponRightService::getRightDetail($rightId);
  577. if ($info['merchantId'] != $this->merchantId) {
  578. util::fail('无效请求');
  579. }
  580. $userId = $info['userId'];
  581. $userInfo = UserService::getById($userId);
  582. $categoryList = CategoryRelateService::getCategoryData();
  583. $usageList = UsageRelationService::getMyUsage();
  584. return $this->renderPartial('couponDetail', ['info' => $info, 'usageList' => $usageList, 'categoryList' => $categoryList, 'userInfo' => $userInfo]);
  585. }
  586. //领取优惠卷 shish 2019.8.25
  587. public function actionGainCoupon()
  588. {
  589. $get = Yii::$app->request->get();
  590. CouponRightService::gainCoupon($get);
  591. util::success([], '成功领取');
  592. }
  593. }