ProductController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. /**
  3. * ProductController o2o商品相关接口
  4. *
  5. *
  6. *
  7. */
  8. class ProductController extends O2oBaseController{
  9. public function actionList(){
  10. $page = intval(Yii::app()->getRequest()->getParam("page",1));
  11. $user_id = Yii::app()->getRequest()->getParam("user_id");
  12. $holiday = explode(',',Service::factory('VariableService')->getVariable('forbidden_order_date'));
  13. //新手礼包判断
  14. if($user_id){
  15. $cache = new ARedisCache();
  16. $key = 'new_user_coupons_check'.$user_id;
  17. $new_user_coupons_check = $cache->get($key);
  18. if(!$new_user_coupons_check){
  19. if(CommonFn::isMongoId($user_id)){
  20. $user_id = new MongoId($user_id);
  21. $criteria = new EMongoCriteria();
  22. $criteria->user('==',$user_id);
  23. $coupons = UserCoupon::model()->count($criteria);
  24. //if($coupons<3){
  25. //新手礼包
  26. $coupon_ids = Yii::app()->params['new_user_coupon_ids'];
  27. $start_time = time();
  28. $end_time = $start_time + 2592000;
  29. foreach ($coupon_ids as $coupon_id) {
  30. $coupon_id = new MongoId($coupon_id);
  31. @Service::factory('CouponService')->giveCoupon($user_id,$coupon_id,$start_time,$end_time);
  32. }
  33. //}else{
  34. $key = 'new_user_coupons_check'.$user_id;
  35. $cache->set($key,1,604800);
  36. //}
  37. }else{
  38. $key = 'new_user_coupons_check'.$user_id;
  39. $cache->set($key,1,604800);
  40. }
  41. }
  42. }
  43. $type = Yii::app()->getRequest()->getParam("type");
  44. $pagesize = Yii::app()->params['O2oProductListPageSize'];
  45. if($type){
  46. $conditions = array(
  47. 'status'=>array('==',1),
  48. 'type'=>array('==',$type),
  49. //'is_extra'=>array('==',0),
  50. );
  51. }else{
  52. $conditions = array(
  53. 'status'=>array('==',1),
  54. //'is_extra'=>array('==',0),
  55. );
  56. }
  57. $order = array(
  58. 'order'=>'desc',
  59. );
  60. $model = new Product();
  61. $pagedata = CommonFn::getPagedata($model,$page,$pagesize,$conditions,$order);
  62. $data['products'] = $pagedata['res'];
  63. $criteria = new EMongoCriteria();
  64. $criteria->status('==',1);
  65. if($type){
  66. $criteria->type('==',$type);
  67. }
  68. //$criteria->is_extra('==',1);
  69. //$extra_products = $model->findAll($criteria);
  70. //$extra_products = CommonFn::getRows($extra_products);
  71. //$extra_products = $model->parse($extra_products);
  72. //$data['extra_products'] = $extra_products;
  73. CommonFn::requestAjax(true,'true',$data,200,array('sum_count' => $pagedata['sum_count'],'sum_page'=>$pagedata['sum_page'],'page_size'=>$pagedata['page_size'],'current_page'=>$pagedata['current_page'],'holiday' => $holiday));
  74. }
  75. public function actionCommentList(){
  76. $page = intval(Yii::app()->getRequest()->getParam("page",1));
  77. $user_id = Yii::app()->getRequest()->getParam("user_id");
  78. $type = Yii::app()->getRequest()->getParam("type");
  79. $pagesize = Yii::app()->params['O2oCommentListPageSize'];
  80. if($type){
  81. $conditions = array(
  82. 'status'=>array('==',1),
  83. 'type'=>array('==',intval($type)),
  84. );
  85. }else{
  86. $conditions = array(
  87. 'status'=>array('==',1),
  88. );
  89. }
  90. $order = array(
  91. 'weight'=>'desc',
  92. 'time' => 'desc'
  93. );
  94. $model = new Comment();
  95. $pagedata = CommonFn::getPagedata($model,$page,$pagesize,$conditions,$order);
  96. $data['comments'] = $pagedata['res'];
  97. CommonFn::requestAjax(true,CommonFn::getMessage('message','operation_success'),$data,200,array('sum_count' => $pagedata['sum_count'],'sum_page'=>$pagedata['sum_page'],'page_size'=>$pagedata['page_size'],'current_page'=>$pagedata['current_page']));
  98. }
  99. public function actionComment(){
  100. $user_id = Yii::app()->getRequest()->getParam("user_id");
  101. $order_id = Yii::app()->getRequest()->getParam("order_id");
  102. $content = Yii::app()->getRequest()->getParam("content");
  103. $pics = json_decode(Yii::app()->request->getParam('pics'),true);
  104. $score = intval(Yii::app()->getRequest()->getParam("score"));
  105. if(!$score || !$order_id || !$content || !$user_id || !CommonFn::isMongoId($user_id) || !CommonFn::isMongoId($order_id)){
  106. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  107. }
  108. if(mb_strlen(trim($content),'utf-8')<10){
  109. CommonFn::requestAjax(false,'评价最少十个字哦~~');
  110. }
  111. if($score>5 || $score<0){
  112. $score = 5;
  113. }
  114. $user = RUser::get(new MongoId($user_id));
  115. $order = ROrder::get(new MongoId($order_id));
  116. if(!$user || !$order || $order->user != $user->_id){
  117. CommonFn::requestAjax(false,CommonFn::getMessage('message','operation_not_permission'));
  118. }
  119. if(isset($order->have_comment) && $order->have_comment == 1){
  120. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','haved_comment'));
  121. }
  122. $type = 0;
  123. if(!isset($order->type) || $order->type == 0){
  124. foreach ($order->products as $product) {
  125. $product_obj = Product::get($product['product']);
  126. $type = $product_obj->type;
  127. break;
  128. }
  129. } else {
  130. $type = $order->type;
  131. }
  132. $comment = new Comment();
  133. $comment->content = $content;
  134. $comment->user = $user->_id;
  135. $comment->type = intval($type);
  136. $comment->order = $order->_id;
  137. $comment->pics = $pics;
  138. $comment->score = $score;
  139. $comment->time = time();
  140. // 保洁师信息处理
  141. // 2015-12-11
  142. $technicians = empty($order->technicians) ? null : $order->technicians;
  143. $comment->technicians = $technicians;
  144. if($comment->save()) {
  145. $order->have_comment = 1;
  146. $order->update(array('have_comment'), true);
  147. $data = $comment->parseRow($comment);
  148. $start_time = time();
  149. $end_time = strtotime(date('Y-m-d', $start_time + 1209600));
  150. $coupon_ids[] = '56c5914fa84ea0874f8d3820';
  151. $coupon_ids[] = '56c591b1a84ea0dd4e8d411e';
  152. $coupon_ids[] = '56c591e5a84ea04d238cc67b';
  153. $coupon_ids[] = '56c5921ca84ea0b3268bd949';
  154. Service::factory('CouponService')->giveCoupon($order->user, new MongoId($coupon_ids[mt_rand(0, 3)]), $start_time, $end_time);
  155. // 保洁师操作
  156. foreach ($technicians as $technician) {
  157. if ($technician) {
  158. $technicianObj = TechInfo::get($technician['technician_id']);
  159. if ($technicianObj && $technicianObj->weixin_userid) {
  160. $url_prefix = ENVIRONMENT == 'product' ? 'http://api.yiguanjia.club' : 'http://apitest.yiguanjia.club';
  161. $wechat = O2oApp::getWechatObj();
  162. $wechat_data = array(
  163. 'touser' => $technicianObj->weixin_userid,
  164. 'msgtype' => 'news',
  165. 'agentid' => '1',
  166. 'news' => array(
  167. 'articles' => array(
  168. array(
  169. 'title' => '壹管家提示-新评价',
  170. 'description' => $technicianObj->name . '你好!你刚刚在壹管家O2O服务上收到了一条评分为' . $score . '分的订单评价,请点击查看。',
  171. 'url' => $url_prefix . '/index.php?r=o2o/myComment/index',
  172. ),
  173. ),
  174. ),
  175. );
  176. $wechat->sendMessage($wechat_data);
  177. }
  178. // 好评数统计
  179. if ($score == 5) {
  180. $favourable_count = $technicianObj->favourable_count + 1;
  181. $technicianObj->favourable_count = $favourable_count;
  182. $technicianObj->save();
  183. }
  184. }
  185. CommonFn::requestAjax(true, CommonFn::getMessage('o2o', 'comment_success'), $data);
  186. }
  187. }else{
  188. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','comment_failt'));
  189. }
  190. }
  191. public function actionQuestion(){
  192. $user_id = Yii::app()->getRequest()->getParam("user_id");
  193. $content = Yii::app()->getRequest()->getParam("content");
  194. $type = Yii::app()->getRequest()->getParam("type");
  195. if(!$type || !$content || !$user_id || !CommonFn::isMongoId($user_id)){
  196. CommonFn::requestAjax(false,CommonFn::getMessage('message','params_illegal'));
  197. }
  198. $user = RUser::get(new MongoId($user_id));
  199. if(!$user){
  200. CommonFn::requestAjax(false,CommonFn::getMessage('message','operation_not_permission'));
  201. }
  202. $question = new Question();
  203. $question->content = $content;
  204. $question->user = $user->_id;
  205. $question->type = isset($type)?intval($type):0;
  206. $question->time = time();
  207. if($question->save()){
  208. $data = $question->parseRow($question);
  209. CommonFn::requestAjax(true,CommonFn::getMessage('o2o','comment_success'),$data);
  210. }else{
  211. CommonFn::requestAjax(false,CommonFn::getMessage('o2o','comment_failt'));
  212. }
  213. }
  214. }