GoodsController.class.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Admin\Controller;
  15. use Admin\Model\GoodsModel;
  16. class GoodsController extends CommonController{
  17. protected function _initialize(){
  18. parent::_initialize();
  19. $this->breadcrumb1='商品';
  20. $this->breadcrumb2='商品管理';
  21. }
  22. public function index(){
  23. $model=new GoodsModel();
  24. $filter=I('get.');
  25. $search=array();
  26. //$map['_string'] = 'status=1 AND score>10';
  27. //'type' => 'normal'
  28. $search['_string'] = " 1=1 ";
  29. if(isset($filter['name'])){
  30. $search['name']=$filter['name'];
  31. }
  32. if(isset($filter['category'])){
  33. $search['category']=$filter['category'];
  34. $this->get_category=$search['category'];
  35. }
  36. if(isset($filter['store_id'])){
  37. $search['store_id']=$filter['store_id'];
  38. $this->get_store=$search['store_id'];
  39. }
  40. if(isset($filter['status']) && $filter['status'] != -1){
  41. $search['status']=$filter['status'];
  42. if($search['status'] == 2)
  43. {
  44. unset($search['_string']);
  45. }
  46. $this->get_status=$search['status'];
  47. }else {
  48. $this->get_status=-1;
  49. }
  50. $data=$model->show_goods_page($search);
  51. $category=M('goods_category')->select();
  52. $category_tree =list_to_tree($category);
  53. $this->category = $category_tree;
  54. $seller_list = M('seller')->field('s_id,s_true_name')->where( array('s_status' => 1) )->select();
  55. $seller_key_list = array();
  56. foreach($seller_list as $key => $val)
  57. {
  58. $seller_key_list[$val['s_id']] = $val['s_true_name'];
  59. }
  60. $this->seller_key_list = $seller_key_list;
  61. $this->seller_list = $seller_list;
  62. $this->assign('empty',$data['empty']);// 赋值数据集
  63. $this->assign('list',$data['list']);// 赋值数据集
  64. $this->assign('page',$data['page']);// 赋值分页输出
  65. $this->display();
  66. }
  67. /**
  68. 商品审核失败
  69. **/
  70. public function change_goods_shenhe()
  71. {
  72. //goods_id:goods_id,reason:reason
  73. $goods_id = I('post.goods_id');
  74. $reason = I('post.reason');
  75. M('goods_description')->where( array('goods_id' =>$goods_id) )->save( array('reason' =>$reason) );
  76. M('goods')->where( array('goods_id' => $goods_id) )->save( array('status' => 3) );
  77. echo json_encode( array('code' =>1) );
  78. die();
  79. //_goods_description
  80. }
  81. public function guobie()
  82. {
  83. $model=new GoodsModel();
  84. $data=$model->show_guobie_page();
  85. $this->breadcrumb2='海淘国别';
  86. $this->assign('empty',$data['empty']);// 赋值数据集
  87. $this->assign('list',$data['list']);// 赋值数据集
  88. $this->assign('page',$data['page']);// 赋值分页输出
  89. $this->display();
  90. }
  91. public function editguobie()
  92. {
  93. $id = I('get.id');
  94. $guobie = M('guobie')->where( array('id' =>$id) )->find();
  95. $this->guobie = $guobie;
  96. $this->breadcrumb2='海淘国别';
  97. $this->display('addguobie');
  98. }
  99. public function addguobie()
  100. {
  101. $this->breadcrumb2='海淘国别';
  102. $this->display();
  103. }
  104. public function delguobie()
  105. {
  106. $id = I('get.id');
  107. M('guobie')->where( array('id' =>$id) )->delete();
  108. $return = array(
  109. 'status'=>'success',
  110. 'message'=>'删除成功',
  111. 'jump'=>U('Goods/guobie')
  112. );
  113. M('goods')->where(array('guobie_id' => $id) )->save( array('type' => 'normal','lock_type' => 'normal','status' => 0) );
  114. $this->osc_alert($return);
  115. }
  116. /**
  117. 存储国别
  118. **/
  119. public function saveguobie()
  120. {
  121. $data = I('post.');
  122. $data['add_time'] = time();
  123. if(isset($data['id']) && !empty($data['id']))
  124. {
  125. $res = M('guobie')->save($data);
  126. $return = array(
  127. 'status'=>'success',
  128. 'message'=>'修改成功',
  129. 'jump'=>U('Goods/guobie')
  130. );
  131. } else {
  132. $res = M('guobie')->add($data);
  133. $return = array(
  134. 'status'=>'success',
  135. 'message'=>'添加成功',
  136. 'jump'=>U('Goods/guobie')
  137. );
  138. }
  139. $this->osc_alert($return);
  140. }
  141. /**
  142. 回收站商品重新上架
  143. **/
  144. public function goback()
  145. {
  146. $goods_id = I('get.id',0,'intval');
  147. $result = array('code' => 0);
  148. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  149. if(empty($goods_info))
  150. {
  151. $result['msg'] = '非法操作';
  152. echo json_encode($result);
  153. die();
  154. }
  155. $up_data = array();
  156. $up_data['lock_type'] = 'normal';
  157. $up_data['status'] = 1;//下架
  158. M('goods')->where( array('goods_id' => $goods_id) )->save($up_data);
  159. $result['code'] = 1;
  160. echo json_encode($result);
  161. die();
  162. }
  163. /**
  164. 加入回车站
  165. **/
  166. public function backhuiche()
  167. {
  168. $goods_id = I('get.id',0,'intval');
  169. $result = array('code' => 0);
  170. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  171. if(empty($goods_info))
  172. {
  173. $result['msg'] = '非法操作';
  174. echo json_encode($result);
  175. die();
  176. }
  177. $lock_type = $goods_info['lock_type'];
  178. switch($lock_type)
  179. {
  180. case 'lottery':
  181. M('lottery_goods')->where( array('goods_id' => $goods_id) )->delete();
  182. break;
  183. case 'super_spike':
  184. M('super_spike_goods')->where( array('goods_id' => $goods_id) )->delete();
  185. break;
  186. case 'spike':
  187. M('spike_goods')->where( array('goods_id' => $goods_id) )->delete();
  188. break;
  189. case 'subject':
  190. case 'free_trial':
  191. case 'niyuan':
  192. case 'oneyuan':
  193. case 'haitao':
  194. M('subject_goods')->where( array('goods_id' => $goods_id) )->delete();
  195. break;
  196. }
  197. $up_data = array();
  198. $up_data['type'] = 'normal';
  199. $up_data['lock_type'] = 'normal';
  200. $up_data['status'] = 4;//下架
  201. M('goods')->where( array('goods_id' => $goods_id) )->save($up_data);
  202. $result['code'] = 1;
  203. echo json_encode($result);
  204. die();
  205. }
  206. /**
  207. * 活动商品
  208. */
  209. public function activity()
  210. {
  211. $this->breadcrumb2='活动商品管理';
  212. $model=new GoodsModel();
  213. $filter=I('get.');
  214. $search=array();
  215. if(isset($filter['store_id'])){
  216. $search['store_id']=$filter['store_id'];
  217. $this->get_store=$search['store_id'];
  218. }
  219. if(isset($filter['name'])){
  220. $search['name']=$filter['name'];
  221. }
  222. if(isset($filter['category'])){
  223. $search['category']=$filter['category'];
  224. $this->get_category=$search['category'];
  225. }
  226. if(isset($filter['status'])){
  227. $search['status']=$filter['status'];
  228. $this->get_status=$search['status'];
  229. }
  230. if(isset($filter['type'])){
  231. $search['type']=$filter['type'];
  232. $this->type=$search['type'];
  233. }else {
  234. $search['type']='activity';
  235. $this->type=$search['type'];
  236. }
  237. //type
  238. $data=$model->show_goods_page($search);
  239. $store_bind_class = M('store_bind_class')->where( array('seller_id' => SELLERUID) )->select();
  240. $cate_ids = array();
  241. foreach($store_bind_class as $val)
  242. {
  243. if( !empty($val['class_1'])) {
  244. $cate_ids[] = $val['class_1'];
  245. }
  246. if( !empty($val['class_2'])) {
  247. $cate_ids[] = $val['class_2'];
  248. }
  249. if( !empty($val['class_3'])) {
  250. $cate_ids[] = $val['class_3'];
  251. }
  252. }
  253. if(empty($cate_ids)) {
  254. $this->category = array();
  255. } else {
  256. $cate_ids_str = implode(',', $cate_ids);
  257. $category=M('goods_category')->where( array('id' => array('in',$cate_ids_str)) )->select();
  258. $category_tree =list_to_tree($category);
  259. $this->category = $category_tree;
  260. }
  261. $category=M('goods_category')->select();
  262. $category_tree =list_to_tree($category);
  263. $this->category = $category_tree;
  264. $seller_list = M('seller')->field('s_id,s_true_name')->where( array('s_status' => 1) )->select();
  265. $this->seller_list = $seller_list;
  266. $seller_key_list = array();
  267. foreach($seller_list as $key => $val)
  268. {
  269. $seller_key_list[$val['s_id']] = $val['s_true_name'];
  270. }
  271. $this->seller_key_list = $seller_key_list;
  272. $this->assign('empty',$data['empty']);// 赋值数据集
  273. $this->assign('list',$data['list']);// 赋值数据集
  274. $this->assign('page',$data['page']);// 赋值分页输出
  275. $this->display();
  276. }
  277. function add(){
  278. if(IS_POST){
  279. $model=new GoodsModel();
  280. $data=I('post.');
  281. //dump($data);die;
  282. $return=$model->add_goods($data);
  283. $this->osc_alert($return);
  284. }
  285. //库存状态
  286. $this->stock_status=M('StockStatus')->select();
  287. //长度单位
  288. $this->length_class=M('LengthClass')->select();
  289. //重量单位
  290. $this->weight_class=M('WeightClass')->select();
  291. $this->action=U('Goods/add');
  292. $this->crumbs='新增';
  293. $this->display('edit');
  294. }
  295. public function get_json_category_tree($pid,$is_ajax=0)
  296. {
  297. // {pid:pid,is_ajax:1}
  298. $pid = empty($_GET['pid']) ? 0: intval($_GET['pid']);
  299. $is_ajax = empty($_GET['is_ajax']) ? 0:intval($_GET['is_ajax']);
  300. $list = M('goods_category')->field('id,pid,name')->where( array('pid'=>$pid) )->order('sort_order asc')->select();
  301. $result = array();
  302. if($is_ajax ==0)
  303. {
  304. return $list;
  305. } else {
  306. if(empty($list)){
  307. $result['code'] = 0;
  308. } else {
  309. $result['code'] = 1;
  310. $result['list'] = $list;
  311. }
  312. echo json_encode($result);
  313. die();
  314. }
  315. }
  316. /**
  317. 搜索可报名的商品
  318. **/
  319. public function goods_search()
  320. {
  321. $goods_name = I('post.goods_name','');
  322. $where = " type='normal' and lock_type='normal' and status=1 and quantity>0 ";
  323. if(!empty($goods_name))
  324. {
  325. $where .= " and name like '%".$goods_name."%' ";
  326. }
  327. $goods_list = M('goods')->where($where)->limit(20)->select();
  328. $this->goods_list = $goods_list;
  329. $result = array();
  330. $result['html'] = $this->fetch('Goods:goods_list_fetch');
  331. echo json_encode($result);
  332. die();
  333. }
  334. function edit(){
  335. $model=new GoodsModel();
  336. $cate_data = $this->get_json_category_tree(0);
  337. $goods_info = $model->get_goods_data(I('id'));
  338. $seller_id = $goods_info['store_id'];
  339. if(IS_POST){
  340. $data=I('post.');
  341. $data['goods_description']['tag'] = str_replace(',', ',', $data['goods_description']['tag']);
  342. $return=$model->edit_goods($data);
  343. $this->osc_alert($return);
  344. }
  345. $relation_express = array();
  346. $seller_express_relat = M('seller_express_relat')->where( array('store_id' => $seller_id) )->select();
  347. if(!empty($seller_express_relat))
  348. {
  349. $exp_ids = array();
  350. foreach($seller_express_relat as $val)
  351. {
  352. $exp_ids[] = $val['express_id'];
  353. }
  354. if(!empty($exp_ids))
  355. {
  356. $exp_ids_str = implode(',', $exp_ids);
  357. $express_list = M('seller_express')->where( array('id' => array('in',$exp_ids_str) ) )->select();
  358. $relation_express = $express_list;
  359. }
  360. }
  361. $this->relation_express = $relation_express;
  362. $pick_up_list = M('pick_up')->where( array('store_id' => $seller_id) )->select();
  363. $this->pick_up_list = $pick_up_list;
  364. $goods_info['pick_up'] = unserialize($goods_info['pick_up']);
  365. $express_list = unserialize($goods_info['express_list']);
  366. $express_ids = array_keys($express_list);
  367. $goods_info['express_ids'] = $express_ids;
  368. $goods_info['express_list'] = $express_list;
  369. $goods_area = M('goods_area')->where( array('goods_id' => I('id')) )->find();
  370. if(!empty($goods_area)) {
  371. $goods_area['area_ids'] =unserialize( $goods_area['area_ids_text']);
  372. }
  373. $this->goods_area=$goods_area;
  374. $parent_area = M('area')->where( array('area_parent_id' => 0) )->order('area_sort asc ,area_id asc')->select();
  375. foreach($parent_area as $key => $val)
  376. {
  377. $child_ren = M('area')->where( array('area_parent_id' => $val['area_id']) )->order('area_sort asc ,area_id asc')->select();
  378. $val['child'] = $child_ren;
  379. $parent_area[$key] = $val;
  380. }
  381. $this->parent_area = $parent_area;
  382. $this->crumbs='编辑';
  383. $this->action=U('Goods/edit');
  384. $this->description=M('goods_description')->find(I('id'));
  385. //库存状态
  386. $this->stock_status=M('StockStatus')->select();
  387. $this->goods=$goods_info;
  388. $guobie_list = M('guobie')->order('is_index desc,id asc')->select();
  389. $this->guobie_list = $guobie_list;
  390. $this->goods_images=$model->get_goods_image_data(I('id'));
  391. $this->goods_discount=M('goods_discount')->where(array('goods_id'=>I('id')))->order('quantity ASC')->select();
  392. $this->goods_categories=$model->get_goods_category_data(I('id'));
  393. //transport_id
  394. if($this->goods['transport_id'] > 0)
  395. {
  396. $this->transport = D('Seller/Transport')->getTransportInfo(array('id' => $this->goods['transport_id']));
  397. }
  398. $this->goods_options=$model->get_goods_options(I('id'));
  399. $option_model=new \Admin\Model\OptionModel();
  400. //选项值
  401. foreach ($this->goods_options as $goods_option) {
  402. $option_values[$goods_option['option_id']] = $option_model->getOptionValues($goods_option['option_id']);
  403. }
  404. $this->option_values=$option_values;
  405. //dump($this->goods_options);die;
  406. $m=new \Admin\Model\OptionModel();
  407. //getOptions
  408. $options_list = $m->getOptions('',$goods_info['store_id']);
  409. $this->options_list = $options_list;
  410. $goods_option_mult_value = M('goods_option_mult_value')->where( array('goods_id' => I('id')) )->select();
  411. $goods_option_mult_str = '';
  412. if( !empty($goods_option_mult_value) )
  413. {
  414. $goods_option_mult_arr = array();
  415. foreach($goods_option_mult_value as $key => $val)
  416. {
  417. $goods_option_mult_arr[] = 'mult_id:'.$val['rela_goodsoption_valueid'].'@@mult_qu:'.$val['quantity'].'@@mult_image:'.$val['image'];
  418. //option_value option_value_id value_name
  419. $option_name_arr = explode('_', $val['rela_goodsoption_valueid']);
  420. $option_name_list = array();
  421. foreach($option_name_arr as $option_value_id_tp)
  422. {
  423. $tp_op_val_info =M('option_value')->where( array('option_value_id' => $option_value_id_tp) )->find();
  424. $option_name_list[] = $tp_op_val_info['value_name'];
  425. }
  426. $val['option_name_list'] = $option_name_list;
  427. $goods_option_mult_value[$key] = $val;
  428. }
  429. $goods_option_mult_str = implode(',', $goods_option_mult_arr);
  430. }
  431. $this->goods_option_mult_value = $goods_option_mult_value;
  432. $this->goods_option_mult_str = $goods_option_mult_str;
  433. $this->assign('cate_data',$cate_data);// 赋值数据集
  434. $this->display('edit');
  435. }
  436. function copy_goods(){
  437. $id =I('id');
  438. $model=new GoodsModel();
  439. if($id){
  440. foreach ($id as $k => $v) {
  441. $model->copy_goods($v);
  442. }
  443. $data['redirect']=U('Goods/index');
  444. $this->ajaxReturn($data);
  445. die;
  446. }
  447. }
  448. function toggle_index_sort()
  449. {
  450. $goods_id = I('post.gid',0);
  451. $index_sort = I('post.index_sort',0,'intval');
  452. $res = M('Goods')->where( array('goods_id' => $goods_id) )->save( array('index_sort' => $index_sort) );
  453. echo json_encode( array('code' => 1) );
  454. die();
  455. }
  456. function toggle_quantity()
  457. {
  458. $goods_id = I('post.gid',0);
  459. $quantity = I('post.quantity',0,'intval');
  460. $res = M('Goods')->where( array('goods_id' => $goods_id) )->save( array('quantity' => $quantity) );
  461. echo json_encode( array('code' => 1) );
  462. die();
  463. }
  464. function toggle_guobie_show()
  465. {
  466. $id = I('post.gid',0);
  467. $guobie_info =M('guobie')->where( array('id' => $id) )->find();
  468. $is_index = $guobie_info['is_index'] == 1 ? 0: 1;
  469. $res = M('guobie')->where( array('id' => $id) )->save( array('is_index' => $is_index) );
  470. echo json_encode( array('code' => 1) );
  471. die();
  472. }
  473. function toggle_index_show()
  474. {
  475. $goods_id = I('post.gid',0);
  476. $goods_info =M('Goods')->where( array('goods_id' => $goods_id) )->find();
  477. $is_index_show = $goods_info['is_index_show'] == 1 ? 0: 1;
  478. $res = M('Goods')->where( array('goods_id' => $goods_id) )->save( array('is_index_show' => $is_index_show) );
  479. echo json_encode( array('code' => 1) );
  480. die();
  481. }
  482. function toggle_statues_show()
  483. {
  484. $goods_id = I('post.gid',0);
  485. $goods_info =M('Goods')->where( array('goods_id' => $goods_id) )->find();
  486. $status = $goods_info['status'] == 1 ? 2: 1;
  487. $res = M('Goods')->where( array('goods_id' => $goods_id) )->save( array('status' => $status) );
  488. echo json_encode( array('code' => 1) );
  489. die();
  490. }
  491. function del(){
  492. $model=new GoodsModel();
  493. $return=$model->del_goods(I('get.id'));
  494. $this->osc_alert($return);
  495. }
  496. }
  497. ?>