ActivityController.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: PHP
  5. * Date: 2016/10/9
  6. * Time: 14:44
  7. */
  8. class ActivityController extends O2oBaseController
  9. {
  10. /**
  11. * 双十一给所有用户发券
  12. * 57fe0aaa9f5160b1048b456c
  13. */
  14. public function actionDoubleEleven()
  15. {
  16. $coupon_id = "5816a413a84ea0023f8b46ba";
  17. $coupon_id = new MongoId($coupon_id);
  18. $start_time = date_create("2016-11-01")->format('U'); //发放优惠券可用开始时间 2016.11.11
  19. $end_time = $start_time + 86400 * 30; //发放优惠券过期时间 一个月
  20. $cursor = RUser::model()->findAll();
  21. $rows = CommonFn::getRowsFromCursor($cursor);
  22. $flag = 0;
  23. foreach ($rows as $value) {
  24. if (CommonFn::isMongoId($value['_id'])) {
  25. $userId = $value['_id'];
  26. Service::factory('CouponService')->giveCoupon($userId, $coupon_id, $start_time, $end_time);//发放代金券
  27. $flag += 1;
  28. }
  29. }
  30. echo "总共发送" . $flag . "个用户";
  31. }
  32. //扫码跳转11元订单页面,回掉微信接口,注册用户信息,然后生成订单
  33. public function actionScanCoupon()
  34. {
  35. $this->redirect('http://common.yiguanjia.me/index.php?r=o2o/web/index');
  36. }
  37. //名宿保洁
  38. public function actionSinglesDay(){
  39. $this->render('SinglesDay');
  40. }
  41. //企业服务
  42. public function actionEnterprise(){
  43. if (Yii::app()->request->getParam('success') == 1) {
  44. CommonFn::requestAjax(true, '您的咨询已发送成功,请等待我们的企业管家与您联系,温馨提示,一般是一个工作日内,日间致电给您,请留意。');
  45. }
  46. $this->render('Enterprise');
  47. }
  48. public function actionSaveAdvisory(){
  49. $name = Yii::app()->request->getParam('user_name','');
  50. $area = Yii::app()->request->getParam('area','');
  51. $homeType = Yii::app()->request->getParam('homeType','');
  52. $num = Yii::app()->request->getParam('num','');
  53. $area = intval(Yii::app()->request->getParam('mobile'));
  54. $tech_content = Yii::app()->request->getParam('tech_content','');
  55. $advisory = new Advisory();
  56. $advisory->user_name = $name;
  57. $advisory->area = $area;
  58. $advisory->homeType = $homeType;
  59. $advisory->num = $num;
  60. $advisory->area =$area;
  61. $advisory->tech_content = $tech_content;
  62. if ($advisory->save()){
  63. $this->redirect('http://commontest.yiguanjia.me/index.php?r=common/Activity/SinglesDay&success=1');
  64. }
  65. }
  66. //扫码获取代金券
  67. public function actionGetCoupon()
  68. {
  69. $signPackage = CommonWeixin::get_sign();
  70. $coupon_id = Yii::app()->request->getParam('coupon_id', '');//获取代金券id
  71. $code = Yii::app()->getRequest()->getParam("code");
  72. $state = Yii::app()->getRequest()->getParam("state");
  73. $userId = Yii::app()->getRequest()->getParam("userId", '');
  74. $appToken = '';
  75. if ($code && $state) {
  76. $accessInfo = CommonWeixin::getAccessInfo($code);
  77. if (!isset($accessInfo['errcode']) && $state == 'yiguanjia') {
  78. $appToken = md5(substr($accessInfo['openid'], 2));
  79. //微信校验通过,登录(注册),分发token
  80. $userInfo = CommonWeixin::getUserInfo($accessInfo['access_token'], $accessInfo['openid']);
  81. if (!isset($accessInfo['errcode'])) {
  82. //检查是否有注册,没有就注册
  83. $criteria = new EMongoCriteria();
  84. $criteria->unionid('==', $accessInfo['unionid']);
  85. $user = RUser::model()->find($criteria);
  86. if ($user) {
  87. $userId = $user->_id;
  88. if (!isset($user->wx_pub_openid) || empty($user->wx_pub_openid)) {
  89. $user->wx_pub_openid = $accessInfo['openid'];
  90. $user->wx_have_follow = 1;
  91. $user->update(array('wx_pub_openid', 'wx_have_follow'), true);
  92. }
  93. } else {
  94. $userAr = new RUser();
  95. $userAr->user_name = $userInfo['nickname'];
  96. $userAr->avatar = $userInfo['headimgurl'];
  97. $userAr->wx_pub_openid = $userInfo['openid'];
  98. $userAr->unionid = $userInfo['unionid'];
  99. $userAr->sex = $userInfo['sex'];
  100. $userAr->register_time = time();
  101. $userAr->channel = 'wxpub';
  102. $userAr->wx_have_follow = 1;
  103. $u_criteria = new EMongoCriteria();
  104. $u_criteria->user_name('==', $userInfo['nickname']);
  105. $olduser = RUser::model()->find($u_criteria);
  106. if ($olduser) {
  107. $user_new_neme = $userAr->user_name . '_' . substr(time(), -7);
  108. $userAr->user_name = $user_new_neme;
  109. }
  110. $result = $userAr->save();
  111. if ($result) {
  112. //异步同步微信头像到七牛
  113. if (!empty($userAr->unionid) && (strpos($userAr->avatar, 'qiniu') === false)) {
  114. $list = new ARedisList('after_user_reg');
  115. $user_id = (string)$userAr->_id;
  116. $list->push($user_id);
  117. }
  118. $userId = (string)$userAr->_id;
  119. } else {
  120. var_dump($userAr);
  121. exit;
  122. }
  123. }
  124. } else {
  125. echo $accessInfo['errcode'];
  126. die();
  127. }
  128. }
  129. }
  130. $coupon_id = new MongoId($coupon_id);
  131. $start_time = time(); //发放优惠券可用开始时间
  132. $end_time = $start_time + 86400 * 30; //发放优惠券过期时间
  133. $flag = 0;
  134. if ($userId != '') {
  135. $userId = new MongoId($userId);
  136. $criteria = new EMongoCriteria();
  137. //$criteria->coupon('==',$coupon_id);
  138. $criteria->user('==', $userId);
  139. $user_coupon = UserCoupon::model()->find($criteria);
  140. if (!$user_coupon) {
  141. Service::factory('CouponService')->giveCoupon($userId, $coupon_id, $start_time, $end_time);//发放代金券
  142. }
  143. $flag = 1;
  144. }
  145. if ($flag) {
  146. $this->renderpartial('index');
  147. } else {
  148. $this->renderpartial('getCoupon', array(
  149. 'version' => '2015111601',
  150. 'signPackage' => $signPackage,
  151. 'userId' => $userId,
  152. 'appToken' => $appToken,
  153. 'coupon_id' => $coupon_id,
  154. ));
  155. }
  156. }
  157. //检查微信登录页
  158. public function actionWxIndex()
  159. {
  160. $wxConfig = Yii::app()->params['wxConfig'];
  161. $coupon_id = Yii::app()->request->getParam('coupon_id', '');
  162. $redirectURI = 'http://' . $_SERVER['HTTP_HOST'] . Yii::app()->request->baseUrl . '/index.php?r=/common/activity/getCoupon&coupon_id=' . $coupon_id;
  163. $appURI = Yii::app()->request->baseUrl . '/index.php?r=common/activity/getCoupon&coupon_id=' . $coupon_id;
  164. $scope = 'snsapi_userinfo';
  165. $state = 'yiguanjia';
  166. $codeURI = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . $wxConfig['appId'] . '&redirect_uri=' . urlencode($redirectURI) . '&response_type=code&scope=' . $scope . '&state=' . $state . '#wechat_redirect';
  167. $this->renderpartial('wxIndex', array(
  168. 'codeURI' => $codeURI,
  169. 'appURI' => $appURI
  170. ));
  171. }
  172. }