GoodscommentController.class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <?php
  2. /**
  3. * 播播资源
  4. *
  5. * ==========================================================================
  6. * @link https://www.ttbobo.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license https://www.ttbobo.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Seller\Controller;
  15. use Seller\Model\GoodscommentModel;
  16. class GoodscommentController extends CommonController{
  17. protected function _initialize(){
  18. parent::_initialize();
  19. $this->breadcrumb1='商品管理';
  20. $this->breadcrumb2='商品评价管理';
  21. }
  22. function index(){
  23. $name = I('get.name','');
  24. $order_num_alias = I('get.order_num_alias','1');
  25. $search = array();
  26. if( !empty($name) )
  27. {
  28. $search['goods_name'] = $name;
  29. }
  30. if( !empty($order_num_alias) )
  31. {
  32. $search['order_num_alias'] = $order_num_alias;
  33. }
  34. $model=new GoodscommentModel();
  35. $data=$model->show_comment_page($search);
  36. $this->assign('empty',$data['empty']);// 赋值数据集
  37. $this->assign('list',$data['list']);// 赋值数据集
  38. $this->assign('page',$data['page']);// 赋值分页输出
  39. $this->display();
  40. }
  41. public function toggle_state_show()
  42. {
  43. $comment_id = I('post.gid');
  44. $order_comment_info = M('order_comment')->field('state')->where( array('comment_id' => $comment_id) )->find();
  45. $state = 1;
  46. if($order_comment_info['state'] == 1)
  47. {
  48. $state = 0;
  49. }
  50. M('order_comment')->where( array('comment_id' => $comment_id) )->save( array('state' => $state) );
  51. echo json_encode( array('code' => 0) );
  52. die();
  53. }
  54. public function backhuiche()
  55. {
  56. $comment_id = I('get.id');
  57. M('order_comment')->where(array('comment_id'=>$comment_id ))->delete();
  58. echo json_encode( array('code' => 0) );
  59. die();
  60. $ref_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER']:U('Goodscomment/index');
  61. $result = array(
  62. 'status'=>'success',
  63. 'message'=>'删除成功',
  64. 'jump'=>$ref_url
  65. );
  66. $this->osc_alert($result);
  67. }
  68. function add(){
  69. if(IS_POST){
  70. $model=new OptionModel();
  71. $data=I('post.');
  72. $data['store_id'] = SELLERUID;
  73. $return=$model->add_option($data);
  74. if($return){
  75. $r['redirect']=U('Option/index');
  76. $this->ajaxReturn($r);
  77. die;
  78. }else{
  79. $error['error']='新增失败';
  80. $this->ajaxReturn($error);
  81. die;
  82. }
  83. }
  84. $this->breadcrumb2='商品评价管理';
  85. $this->display('edit');
  86. }
  87. function get_member_ajax()
  88. {
  89. $keywords = I('post.keywords','');
  90. $page = I('post._pa',1);
  91. $perpage = 20;
  92. $offset = ( $page -1 ) * $perpage;
  93. $where = " 1=1 ";
  94. if( !empty($keywords) )
  95. {
  96. $where .= " and uname like '%".$keywords."%'";
  97. }
  98. $jia_list = M('member')->where( $where )->order('member_id desc')->limit($offset,20)->select();
  99. $this->page = $page;
  100. $this->jia_list = $jia_list;
  101. $html = $this->fetch('Goodscomment:fetch_comment_member_ajax_list');
  102. if( empty($jia_list) )
  103. {
  104. echo json_encode( array('code' => 1) );
  105. die();
  106. }else{
  107. echo json_encode( array('code' => 0 , 'html' => $html) );
  108. die();
  109. }
  110. }
  111. function get_jiqi_ajax()
  112. {
  113. $keywords = I('post.keywords','');
  114. $where = " 1=1 ";
  115. if( !empty($keywords) )
  116. {
  117. $where .= " and username like '%".$keywords."%'";
  118. }
  119. $jia_list = M('jiauser')->where( $where )->order('id desc')->limit(20)->select();
  120. $this->jia_list = $jia_list;
  121. $html = $this->fetch('Goodscomment:fetch_comment_ajax_list');
  122. echo json_encode( array('code' => 0 , 'html' => $html) );
  123. die();
  124. }
  125. function fetch_comment_ajax()
  126. {
  127. //.htmlSeller\Goodscomment\
  128. $html = $this->fetch('Goodscomment:fetch_comment_ajax');
  129. echo json_encode( array('code' => 0, 'html' => $html) );
  130. die();
  131. }
  132. public function save_vir_comment()
  133. {
  134. //{goods_id_str:goods_id_str,jia_id:jia_id,star:star,star2:star2,star3:star3,content:content},
  135. $goods_id_str = I('post.goods_id_str','');
  136. if(empty($goods_id_str))
  137. {
  138. echo json_encode( array('code' => 1, 'msg' => '请选择评价的商品') );
  139. die();
  140. }
  141. $goods_id_arr = explode(',', $goods_id_str);
  142. $jia_id = I('post.jia_id',0);
  143. if( empty($jia_id) || $jia_id <= 0 )
  144. {
  145. echo json_encode( array('code' => 1, 'msg' => '请选择评价的机器人') );
  146. die();
  147. }
  148. $begin_time = I('post.begin_time', '');
  149. $star = I('post.star', 0);
  150. $star2 = I('post.star2', 0);
  151. $star3 = I('post.star3', 0);
  152. $content = I('post.content', 0);
  153. $s_imgs_str = I('post.s_imgs_str', '');
  154. $s_imgs_arr = explode(',', $s_imgs_str);
  155. $is_picture = 0;
  156. if( !empty($s_imgs_arr) )
  157. {
  158. $is_picture = 1;
  159. }
  160. //order_comment,
  161. //order_id=0,goods_id state=1,member_id=jia_id,avatar=jia_avatar user_name=jia_name,
  162. //order_num_alias=0,//type=1,star,star3,star2, is_picture=0/1,content ,add_time
  163. //goods_name,goods_image,
  164. //,
  165. $jia_info = M('jiauser')->where( array('id' => $jia_id) )->find();
  166. $commen_data = array();
  167. $commen_data['order_id'] = 0;
  168. $commen_data['state'] = 1;
  169. $commen_data['type'] = 1;
  170. $commen_data['member_id'] = $jia_id;
  171. $commen_data['avatar'] = $jia_info['avatar'];
  172. $commen_data['user_name'] = $jia_info['username'];
  173. $commen_data['order_num_alias'] = 1;
  174. $commen_data['star'] = $star;
  175. $commen_data['star3'] = $star3;
  176. $commen_data['star2'] = $star2;
  177. $commen_data['is_picture'] = $is_picture;
  178. $commen_data['content'] = $content;
  179. $commen_data['images'] = serialize($s_imgs_arr);
  180. $i =1;
  181. $quan_model = D('Home/Quan');
  182. foreach($goods_id_arr as $goods_id)
  183. {
  184. $commen_data['goods_id'] = $goods_id;
  185. $commen_data['add_time'] = strtotime($begin_time);
  186. $goods_info = M('goods')->field('name,image')->where( array('goods_id' => $goods_id) )->find();
  187. $commen_data['goods_name'] = $goods_info['name'];
  188. $commen_data['goods_image'] = $goods_info['image'];
  189. $rs = M('order_comment')->add($commen_data);
  190. $post_data = array();
  191. $post_data['member_id'] = $jia_id;
  192. $post_data['group_id'] = 1;
  193. $post_data['is_vir'] = 1;
  194. $post_data['avatar'] = $commen_data['avatar'];
  195. $post_data['user_name'] = $commen_data['user_name'];
  196. $post_data['goods_id'] = $goods_id;
  197. $post_data['title'] = $content;
  198. $post_data['is_share'] = 1;
  199. $post_data['content'] = $commen_data['images'];
  200. $rs = $quan_model->send_group_post($post_data);
  201. $i++;
  202. }
  203. $ref_url = U('Goodscomment/index');
  204. echo json_encode( array('code' => 0, 'ref_url' => $ref_url) );
  205. die();
  206. }
  207. function get_goods_all()
  208. {
  209. $html = $this->fetch('Goodscomment:fetch_goods_ajax');
  210. echo json_encode( array('code' => 0 , 'html' => $html) );
  211. die();
  212. }
  213. function get_jiqi()
  214. {
  215. $html = $this->fetch('Goodscomment:fetch_comment_ajax');
  216. echo json_encode( array('code' => 0 , 'html' => $html) );
  217. die();
  218. }
  219. function get_member()
  220. {
  221. $html = $this->fetch('Goodscomment:fetch_comment_member_ajax');
  222. echo json_encode( array('code' => 0 , 'html' => $html) );
  223. die();
  224. }
  225. function edit(){
  226. if(IS_POST){
  227. $model=new OptionModel();
  228. $data=I('post.');
  229. //dump($data);
  230. $return=$model->edit_option($data);
  231. if($return){
  232. $r['redirect']=U('Option/index');
  233. $this->ajaxReturn($r);
  234. die;
  235. }else{
  236. $error['error']='编辑失败';
  237. $this->ajaxReturn($error);
  238. die;
  239. }
  240. }
  241. $this->option=M('Option')->find(I('id'));
  242. $this->option_values=M('OptionValue')->where(array('option_id'=>I('id')))->select();
  243. $this->crumbs='编辑';
  244. $this->action=U('Option/edit');
  245. $this->display();
  246. }
  247. function del(){
  248. M('option')->delete(I('id'));
  249. M('option_value')->where(array('option_id'=>I('id')))->delete();
  250. $this->redirect('Option/index');
  251. }
  252. function get_goodsajax_option_value()
  253. {
  254. $goods_id = I('post.goods_id');
  255. $goods_option = M('goods_option')->where( array('goods_id' => $goods_id) )->select();
  256. $result = array('code' => 0);
  257. if( !empty($goods_option) )
  258. {
  259. foreach($goods_option as $key => $val)
  260. {
  261. $goods_option_value_list = M('option_value')->where( array('option_id' => $val['option_id']) )->select();
  262. foreach($goods_option_value_list as $kk => $vv)
  263. {
  264. // $vv['option_value_id']
  265. $has_check_option_value_list = M('goods_option_value')->where( array('option_value_id' => $vv['option_value_id'],'goods_id' =>$goods_id ) )->select();
  266. if( !empty($has_check_option_value_list) )
  267. {
  268. $vv['selected'] = 'selected';
  269. } else{
  270. $vv['selected'] = '';
  271. }
  272. $goods_option_value_list[$kk] = $vv;
  273. }
  274. $val['goods_option_value_list'] = $goods_option_value_list;
  275. $goods_option[$key] = $val;
  276. }
  277. $result['code'] = 1;
  278. $result['data'] = $goods_option;
  279. }
  280. echo json_encode($result);
  281. die();
  282. }
  283. function get_ajax_option_value()
  284. {
  285. //option_value
  286. $option_id = I('post.option_id');
  287. $option_value_list = M('option_value')->where( array('option_id' =>$option_id) )->order('value_sort_order asc')->select();
  288. echo json_encode( array('code' =>1 , 'data' => $option_value_list) );
  289. die();
  290. }
  291. //获取选项
  292. function autocomplete(){
  293. $json = array();
  294. $filter_name=I('filter_name');
  295. if (isset($filter_name)) {
  296. //$m=D('Product');
  297. $m=new OptionModel();
  298. //getOptions
  299. $options = $m->getOptions($filter_name,SELLERUID);
  300. foreach ($options as $option) {
  301. $option_value_data = array();
  302. if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox') {
  303. $option_values = $m->getOptionValues($option['option_id']);
  304. foreach ($option_values as $option_value) {
  305. $option_value_data[] = array(
  306. 'option_value_id' => $option_value['option_value_id'],
  307. 'name' => html_entity_decode($option_value['value'], ENT_QUOTES, 'UTF-8'),
  308. 'image' => $option_value['image']
  309. );
  310. }
  311. $sort_order = array();
  312. foreach ($option_value_data as $key => $value) {
  313. $sort_order[$key] = $value['name'];
  314. }
  315. array_multisort($sort_order, SORT_ASC, $option_value_data);
  316. }
  317. $type = '';
  318. if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox' ) {
  319. $type = '选择';
  320. }
  321. $json[] = array(
  322. 'option_id' => $option['option_id'],
  323. 'name' => strip_tags(html_entity_decode($option['name'], ENT_QUOTES, 'UTF-8')),
  324. 'category' => $type,
  325. 'type' => $option['type'],
  326. 'option_value' => $option_value_data
  327. );
  328. }
  329. }
  330. $sort_order = array();
  331. foreach ($json as $key => $value) {
  332. $sort_order[$key] = $value['name'];
  333. }
  334. array_multisort($sort_order, SORT_ASC, $json);
  335. echo(json_encode($json));
  336. }
  337. }
  338. ?>