ActivityController.class.php 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496
  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 Seller\Controller;
  15. use Admin\Model\SubjectModel;
  16. use Admin\Model\SuperSpikeModel;
  17. use Admin\Model\SpikeModel;
  18. class ActivityController extends CommonController{
  19. protected function _initialize(){
  20. parent::_initialize();
  21. $this->breadcrumb1='活动中心';
  22. $this->breadcrumb2='';
  23. $this->sellerid = SELLERUID;
  24. $this->subjecttype = array('normal' => '正常活动','zeyuan' => '0元试用','niyuan' => '9.9元','oneyuan' => '1元购','haitao' => '海淘');
  25. }
  26. /**
  27. 普通主题活动
  28. **/
  29. public function subject(){
  30. $model=new SubjectModel();
  31. $now_time = time();
  32. $type = I('get.type','normal');
  33. //niyuan
  34. $where = " where type='{$type}' and can_shenqing =1 and begin_time< {$now_time} and end_time > {$now_time}";
  35. $data=$model->show_subject_page($where);
  36. $this->assign('empty',$data['empty']);// 赋值数据集
  37. $this->assign('list',$data['list']);// 赋值数据集
  38. $this->assign('page',$data['page']);// 赋值分页输出
  39. $this->state = $state;
  40. $get_status = 1;
  41. //'subject','zeyuan','niyuan','oneyuan','haitao'
  42. switch($type)
  43. {
  44. case 'normal':
  45. $get_status = 1;
  46. break;
  47. case 'niyuan':
  48. $get_status = 6;
  49. break;
  50. case 'oneyuan':
  51. $get_status = 7;
  52. break;
  53. case 'haitao':
  54. $get_status = 8;
  55. break;
  56. }
  57. $this->get_status = $get_status;
  58. $this->display();
  59. }
  60. /**
  61. 搜索可报名的商品
  62. **/
  63. public function goods_search()
  64. {
  65. $goods_name = I('post.goods_name','');
  66. $where = ' store_id='.SELLERUID." and type='normal' and lock_type='normal' and status=1 and quantity>0 ";
  67. if(!empty($goods_name))
  68. {
  69. $where .= " and name like '%".$goods_name."%' ";
  70. }
  71. $goods_list = M('goods')->where($where)->limit(20)->select();
  72. $this->goods_list = $goods_list;
  73. $result = array();
  74. $result['html'] = $this->fetch('Activity:goods_list_fetch');
  75. echo json_encode($result);
  76. die();
  77. }
  78. /**
  79. 限时秒杀
  80. **/
  81. public function take_spike()
  82. {
  83. $id = I('get.id','0');
  84. $subject = M('spike')->where( array('id' => $id) )->find();
  85. if(empty($subject))
  86. {
  87. $this->redirect('Activity/spike');
  88. die();
  89. }
  90. $this->subject = $subject;
  91. $this->display();
  92. }
  93. /**
  94. 报名主题活动
  95. **/
  96. public function take_subject()
  97. {
  98. $id = I('get.id','0');
  99. $subject = M('subject')->where( array('id' => $id) )->find();
  100. if(empty($subject))
  101. {
  102. $this->redirect('Activity/subject');
  103. die();
  104. }
  105. $this->subject = $subject;
  106. $this->display();
  107. }
  108. /**
  109. 报名超值大牌活动
  110. **/
  111. public function take_superspike()
  112. {
  113. $id = I('get.id','0');
  114. $subject = M('super_spike')->where( array('id' => $id) )->find();
  115. if(empty($subject))
  116. {
  117. $this->redirect('Activity/superspike');
  118. die();
  119. }
  120. $this->subject = $subject;
  121. $this->display();
  122. }
  123. /**
  124. 提交抽奖活动申请
  125. **/
  126. public function sub_lottery()
  127. {
  128. /**
  129. ["begin_time"]=>
  130. string(18) "2018-06-15 0:00:00"
  131. ["end_time"]=>
  132. string(18) "2018/06/16 0:00:00"
  133. **/
  134. $begin_time = I('post.begin_time');
  135. $end_time = I('post.end_time');
  136. $voucher_id = I('post.voucher_id',0);
  137. $win_quantity = I('post.win_quantity',0);
  138. $is_auto_open = I('post.is_auto_open',0);
  139. $pin_hour = I('post.pin_hour',0);
  140. $real_win_quantity = I('post.real_win_quantity',0);
  141. $result = array('code' => 0);
  142. $data = I('post.goods_ids_arr');
  143. /**
  144. array(1) {
  145. [0]=>
  146. array(3) {
  147. ["goods_id"]=>
  148. string(2) "27"
  149. ["pin_price"]=>
  150. string(4) "0.01"
  151. ["pin_count"]=>
  152. string(1) "2"
  153. }
  154. }
  155. **/
  156. if($voucher_id == 0){
  157. $result['msg'] = '请选择退款时赠送的优惠券';
  158. echo json_encode($result);
  159. die();
  160. }
  161. $can_bao = 1;
  162. $bao_count =0;
  163. foreach($data as $val)
  164. {
  165. $goods_id = $val['goods_id'];
  166. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  167. if(!$this->check_lottery_baom())
  168. {
  169. $can_bao = 0;
  170. break;
  171. }
  172. $bao_count++;
  173. M('lottery_goods')->where( array('goods_id' => $goods_id) )->save( array('state' => 3) );
  174. $spike_data = array();
  175. $spike_data['goods_id'] = $goods_id;
  176. $spike_data['state'] = 1;
  177. $spike_data['seller_id'] = SELLERUID;
  178. $spike_data['is_open_lottery'] = 0;
  179. $spike_data['voucher_id'] = $voucher_id;
  180. $spike_data['win_quantity'] = $win_quantity;
  181. $spike_data['is_auto_open'] = $is_auto_open;
  182. $spike_data['real_win_quantity'] = $real_win_quantity;
  183. $spike_data['quantity'] = $goods_info['quantity'];
  184. $spike_data['begin_time'] = strtotime($begin_time);
  185. $spike_data['end_time'] = strtotime($end_time);
  186. $spike_data['addtime'] = time();
  187. $rs = M('lottery_goods')->add($spike_data);
  188. if($rs) {
  189. M('pin_goods')->where( array('goods_id' => $goods_id) )->delete();
  190. //begin_time end_time
  191. //添加拼团数据
  192. M('pin_goods')->add( array('goods_id' => $goods_id,'customer_id' => SELLERUID,
  193. 'pin_price' => $val['pin_price'],'type' => 'lottery','begin_time' => strtotime($begin_time),
  194. 'end_time' => strtotime($end_time),'pin_hour' => $pin_hour,'pin_count' => $val['pin_count'],'addtime' =>time()
  195. )
  196. );
  197. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'lottery','type' =>'lottery', 'status' => 1) );
  198. }
  199. }
  200. $result['code'] = 1;
  201. $result['can_bao'] = $can_bao;
  202. $result['bao_count'] = $bao_count;
  203. echo json_encode($result);
  204. die();
  205. }
  206. /**
  207. 检测抽奖商品是否有限制报名
  208. **/
  209. public function check_lottery_baom()
  210. {
  211. $now_time = time();
  212. $where = " ( (state=0) or (state =1 and begin_time <{$now_time} and end_time > {$now_time}) )and seller_id = ".SELLERUID;
  213. $count = M('lottery_goods')->where($where)->count();
  214. $subject_bom = M('config')->field('value')->where( array('name' => 'subject_baom') )->find();
  215. if($subject_bom['value'] ==0 || $subject_bom['value']> $count)
  216. {
  217. return true;
  218. }else {
  219. return false;
  220. }
  221. }
  222. /**
  223. 提交限时秒杀
  224. **/
  225. public function sub_spike()
  226. {
  227. $subject_id = I('get.id');
  228. $data = I('post.goods_ids_arr');
  229. $result = array('code' => 0);
  230. if( empty($data))
  231. {
  232. $result['msg'] = '未选中商品';
  233. echo json_encode($result);
  234. die();
  235. }
  236. $subject = M('spike')->where( array('id' => $subject_id) )->find();
  237. $man_flag = 0;
  238. $bao_count = 0;
  239. foreach($data as $goods_id)
  240. {
  241. if(!$this->check_spike_goods())
  242. {
  243. $man_flag = 1;
  244. break;
  245. }
  246. $bao_count++;
  247. $super_data = array();
  248. $super_data['spike_id'] = $subject_id;
  249. $super_data['goods_id'] = $goods_id;
  250. $super_data['state'] = 0;
  251. $super_data['seller_id'] = SELLERUID;
  252. $super_data['begin_time'] = $subject['begin_time'];
  253. $super_data['end_time'] = $subject['end_time'];
  254. $super_data['addtime'] = time();
  255. $rs = M('spike_goods')->add($super_data);
  256. if($rs) {
  257. $up_data = array('lock_type' =>'spike');//,'status' => 0
  258. M('goods')->where( array('goods_id' => $goods_id) )->save( $up_data );
  259. }
  260. }
  261. $result['code'] = 1;
  262. $result['man_flag'] = $man_flag;
  263. $result['bao_count'] = $bao_count;
  264. echo json_encode($result);
  265. die();
  266. }
  267. public function check_spike_goods()
  268. {
  269. //
  270. $now_time = time();
  271. $where = " (state=0 or (state =1 and begin_time <{$now_time} and end_time>{$now_time}) ) and seller_id = ".SELLERUID;
  272. $count = M('spike_goods')->where($where)->count();
  273. $subject_bom = M('config')->field('value')->where( array('name' => 'subject_baom') )->find();
  274. if($subject_bom['value'] ==0 || $subject_bom['value']> $count)
  275. {
  276. return true;
  277. }else {
  278. return false;
  279. }
  280. }
  281. /**
  282. 提交超值大牌
  283. **/
  284. public function sub_superspike()
  285. {
  286. $subject_id = I('get.id');
  287. $data = I('post.goods_ids_arr');
  288. $result = array('code' => 0);
  289. if( empty($data))
  290. {
  291. $result['msg'] = '未选中商品';
  292. echo json_encode($result);
  293. die();
  294. }
  295. $subject = M('super_spike')->where( array('id' => $subject_id) )->find();
  296. $man_flag = 0;
  297. $bao_count = 0;
  298. foreach($data as $goods_id)
  299. {
  300. if(!$this->check_superspike_goods())
  301. {
  302. $man_flag =1;
  303. break;
  304. }
  305. $bao_count++;
  306. $super_data = array();
  307. $super_data['super_spike_id'] = $subject_id;
  308. $super_data['goods_id'] = $goods_id;
  309. $super_data['state'] = 0;
  310. $super_data['seller_id'] = SELLERUID;
  311. $super_data['begin_time'] = $subject['begin_time'];
  312. $super_data['end_time'] = $subject['end_time'];
  313. $super_data['addtime'] = time();
  314. $rs = M('super_spike_goods')->add($super_data);
  315. if($rs) {
  316. $up_data = array('lock_type' =>'super_spike');//,'status' => 0
  317. M('goods')->where( array('goods_id' => $goods_id) )->save( $up_data );
  318. }
  319. }
  320. $result['code'] = 1;
  321. $result['man_flag'] = $man_flag;
  322. $result['bao_count'] = $bao_count;
  323. echo json_encode($result);
  324. die();
  325. }
  326. public function check_superspike_goods()
  327. {
  328. //
  329. $now_time = time();
  330. $where = " (state=0 or (state =1 and begin_time <{$now_time} and end_time>{$now_time}) ) and seller_id = ".SELLERUID;
  331. $count = M('super_spike_goods')->where($where)->count();
  332. $subject_bom = M('config')->field('value')->where( array('name' => 'subject_baom') )->find();
  333. if($subject_bom['value'] ==0 || $subject_bom['value']> $count)
  334. {
  335. return true;
  336. }else {
  337. return false;
  338. }
  339. }
  340. /**
  341. 提交主题活动申请
  342. **/
  343. public function sub_subject()
  344. {
  345. $subject_id = I('get.id');
  346. $data = I('post.goods_ids_arr');
  347. $result = array('code' => 0);
  348. if( empty($data))
  349. {
  350. $result['msg'] = '未选中商品';
  351. echo json_encode($result);
  352. die();
  353. }
  354. $subject = M('subject')->where( array('id' => $subject_id) )->find();
  355. //type begin_time end_time price
  356. $bao_count = 0;
  357. $man_flag = 0;
  358. foreach($data as $goods_id)
  359. {
  360. $super_data = array();
  361. if(!$this->check_subject_goods())
  362. {
  363. $man_flag = 1;
  364. break;
  365. }
  366. $bao_count++;
  367. $super_data['subject_id'] = $subject_id;
  368. $super_data['goods_id'] = $goods_id;
  369. $super_data['state'] = 0;
  370. $super_data['seller_id '] = SELLERUID;
  371. $super_data['begin_time'] = $subject['begin_time'];
  372. $super_data['end_time'] = $subject['end_time'];
  373. $super_data['addtime'] = time();
  374. $rs = M('subject_goods')->add($super_data);
  375. if($rs) {
  376. if($subject['type'] =='normal')
  377. {
  378. $subject['type'] = 'subject';
  379. }
  380. $up_data = array('lock_type' =>$subject['type']);//,'status' => 0
  381. M('goods')->where( array('goods_id' => $goods_id) )->save( $up_data );
  382. }
  383. }
  384. $result['code'] = 1;
  385. $result['man_flag'] = $man_flag;
  386. $result['bao_count'] = $bao_count;
  387. echo json_encode($result);
  388. die();
  389. }
  390. public function check_subject_goods()
  391. {
  392. //
  393. $now_time = time();
  394. $where = " (state=0 or (state =1 and begin_time <{$now_time} and end_time>{$now_time}) ) and seller_id = ".SELLERUID;
  395. $count = M('subject_goods')->where($where)->count();
  396. $subject_bom = M('config')->field('value')->where( array('name' => 'subject_baom') )->find();
  397. if($subject_bom['value'] ==0 || $subject_bom['value']> $count)
  398. {
  399. return true;
  400. }else {
  401. return false;
  402. }
  403. }
  404. /**
  405. dan_lottery
  406. 将商品直接加入抽奖活动
  407. **/
  408. public function dan_lottery()
  409. {
  410. $voucher_list = M('voucher')->where( "store_id=".SELLERUID." and end_time>".time() )->select();
  411. $this->voucher_list = $voucher_list;
  412. $goods_id = I('get.goods_id');
  413. $goods = M('goods')->field('goods_id,name')->where( array('goods_id' => $goods_id) )->find();
  414. $this->goods = $goods;
  415. $this->display();
  416. }
  417. /**
  418. 将商品加入砍价活动
  419. add_bargain
  420. **/
  421. public function add_bargain()
  422. {
  423. $goods_id = I('get.goods_id');
  424. $goods = M('goods')->field('goods_id,name')->where( array('goods_id' => $goods_id) )->find();
  425. $this->goods = $goods;
  426. $this->display();
  427. }
  428. /**
  429. 抽奖活动
  430. **/
  431. public function lottery()
  432. {
  433. $voucher_list = M('voucher')->where( "store_id=".SELLERUID." and end_time>".time() )->select();
  434. $this->voucher_list = $voucher_list;
  435. $this->display();
  436. }
  437. /**
  438. 超值大牌
  439. **/
  440. public function superspike()
  441. {
  442. $model=new SuperSpikeModel();
  443. $now_time = time();
  444. $where = " where begin_time< {$now_time} and end_time > {$now_time}";
  445. $data=$model->show_superspike_page( $where );
  446. $this->assign('empty',$data['empty']);// 赋值数据集
  447. $this->assign('list',$data['list']);// 赋值数据集
  448. $this->assign('page',$data['page']);// 赋值分页输出
  449. $this->get_status = 4;
  450. $this->display();
  451. }
  452. /**
  453. 限时秒杀
  454. **/
  455. public function spike()
  456. {
  457. $model=new SpikeModel();
  458. $now_time = time();
  459. $where = " where begin_time< {$now_time} and end_time > {$now_time}";
  460. $data=$model->show_spike_page($where);
  461. $this->assign('empty',$data['empty']);// 赋值数据集
  462. $this->assign('list',$data['list']);// 赋值数据集
  463. $this->assign('page',$data['page']);// 赋值分页输出
  464. $this->get_status = 5;
  465. $this->display();
  466. }
  467. /**
  468. * 活动商品
  469. */
  470. public function activity()
  471. {
  472. $this->breadcrumb2='活动商品信息';
  473. $model=new GoodsModel();
  474. $filter=I('get.');
  475. $search=array('store_id' => SELLERUID);
  476. if(isset($filter['name'])){
  477. $search['name']=$filter['name'];
  478. }
  479. if(isset($filter['category'])){
  480. $search['category']=$filter['category'];
  481. $this->get_category=$search['category'];
  482. }
  483. if(isset($filter['status'])){
  484. $search['status']=$filter['status'];
  485. $this->get_status=$search['status'];
  486. }
  487. if(isset($filter['type'])){
  488. $search['type']=$filter['type'];
  489. $this->type=$search['type'];
  490. }else {
  491. $search['type']='activity';
  492. $this->type=$search['type'];
  493. }
  494. //type
  495. $data=$model->show_goods_page($search);
  496. $store_bind_class = M('store_bind_class')->where( array('seller_id' => SELLERUID) )->select();
  497. $cate_ids = array();
  498. foreach($store_bind_class as $val)
  499. {
  500. if( !empty($val['class_1'])) {
  501. $cate_ids[] = $val['class_1'];
  502. }
  503. if( !empty($val['class_2'])) {
  504. $cate_ids[] = $val['class_2'];
  505. }
  506. if( !empty($val['class_3'])) {
  507. $cate_ids[] = $val['class_3'];
  508. }
  509. }
  510. if(empty($cate_ids)) {
  511. $this->category = array();
  512. } else {
  513. $cate_ids_str = implode(',', $cate_ids);
  514. $category=M('goods_category')->where( array('id' => array('in',$cate_ids_str)) )->select();
  515. $category_tree =list_to_tree($category);
  516. $this->category = $category_tree;
  517. }
  518. foreach($data['list'] as $key => $goods)
  519. {
  520. $all_comment = M('order_comment')->where( array('goods_id' => $goods['goods_id']) )->count();
  521. $wait_comment = M('order_comment')->where( array('state' => 0 ,'goods_id' => $goods['goods_id']) )->count();
  522. $goods['all_comment'] = $all_comment;
  523. $goods['wait_comment'] = $wait_comment;
  524. $data['list'][$key] = $goods;
  525. }
  526. $this->assign('empty',$data['empty']);// 赋值数据集
  527. $this->assign('list',$data['list']);// 赋值数据集
  528. $this->assign('page',$data['page']);// 赋值分页输出
  529. $this->display();
  530. }
  531. ///Goods/delcomment/id/1
  532. /**
  533. * 删除评论
  534. */
  535. public function delcomment()
  536. {
  537. $id = I('get.id');
  538. $goods_id = I('get.goods_id');
  539. M('order_comment')->where( array('comment_id' => $id) )->delete();
  540. //echo
  541. $result = array(
  542. 'status'=>'success',
  543. 'message'=>'删除成功',
  544. 'jump'=>U('Goods/comment_info', array('id' => $goods_id))
  545. );
  546. $this->osc_alert($result);
  547. }
  548. /**
  549. * 审核评论
  550. */
  551. public function toggle_comment_state()
  552. {
  553. $comment_id = I('post.comment_id');
  554. $order_comment = M('order_comment')->where( array('comment_id' => $comment_id) )->find();
  555. //state
  556. $state = $order_comment['state'] == 1 ? 0: 1;
  557. M('order_comment')->where( array('comment_id' => $comment_id) )->save( array('state' => $state) );
  558. echo json_encode( array('code' => 1) );
  559. die();
  560. }
  561. /**
  562. * 商品评论信息
  563. */
  564. public function comment_info()
  565. {
  566. $goods_id = I('get.id');
  567. $model=new GoodsModel();
  568. $search = array();
  569. $search['goods_id'] = $goods_id;
  570. $data=$model->show_comment_page($search);
  571. $this->assign('empty',$data['empty']);// 赋值数据集
  572. $this->assign('list',$data['list']);// 赋值数据集
  573. $this->assign('page',$data['page']);// 赋值分页输出
  574. $this->display();
  575. }
  576. public function lotteryinfo()
  577. {
  578. $goods_id = I('get.id',0);
  579. $lottery_goods = M('lottery_goods')->where( array('goods_id' =>$goods_id) )->find();
  580. if(empty($lottery_goods)){
  581. die('非法操作');
  582. }//store_id
  583. $page = I('get.page',1);
  584. $per_page = 4;
  585. $offset = ($page - 1) * $per_page;
  586. $sql = "select m.uname,m.avatar,p.pin_id,p.lottery_state,o.lottery_win,o.order_id,o.pay_time from ".C('DB_PREFIX')."pin as p,".C('DB_PREFIX')."pin_order as po,
  587. ".C('DB_PREFIX')."order as o,".C('DB_PREFIX')."order_goods as og,".C('DB_PREFIX')."member as m
  588. where p.state = 1 and p.pin_id = po.pin_id and po.order_id = o.order_id
  589. and o.order_id = og.order_id and og.goods_id and o.member_id = m.member_id and og.store_id =".SELLERUID." and og.goods_id = {$goods_id}
  590. order by p.pin_id asc limit {$offset},{$per_page}";
  591. $list=M()->query($sql);
  592. $this->list = $list;
  593. $this->goods_id = $goods_id;
  594. $this->lottery_goods = $lottery_goods;
  595. if($page>1){
  596. $result = array();
  597. $result['code'] = 0;
  598. if(!empty($list)) {
  599. $content = $this->fetch('Goods:lottery_info_fetch');
  600. $result['code'] = 1;
  601. $result['html'] = $content;
  602. }
  603. echo json_encode($result);
  604. die();
  605. }
  606. $this->display();
  607. }
  608. public function openlottery()
  609. {
  610. $goods_id = I('get.id',0);
  611. $oids = I('post.oids');
  612. $order_model = D('Home/Order');
  613. $order_model->open_goods_lottery_order($goods_id,$oids,false);
  614. //$order_model->open_goods_lottery_order($goods_id,'',true);
  615. //$map['id'] = array('in','1,3,8')
  616. echo json_encode( array('code' => 1) );
  617. die();
  618. }
  619. public function lottery_shenqing()
  620. {
  621. $result = array('code' => 0);
  622. $goods_id = I('post.goods_id',0);
  623. if($goods_id == 0){
  624. $result['msg'] = '商品不存在';
  625. echo json_encode($result);
  626. die();
  627. }
  628. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  629. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  630. $spike_data = array();
  631. $spike_data['goods_id'] = $goods_id;
  632. $spike_data['state'] = 0;
  633. $spike_data['quantity'] = $goods_info['quantity'];
  634. $spike_data['begin_time'] = 0;
  635. $spike_data['end_time'] = 0;
  636. $spike_data['addtime'] = time();
  637. $rs = M('lottery_goods')->add($spike_data);
  638. if($rs) {
  639. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'lottery') );
  640. }
  641. $result['code'] = 1;
  642. echo json_encode($result);
  643. die();
  644. } else{
  645. $result['msg'] = '已存在其他活动中';
  646. echo json_encode($result);
  647. die();
  648. }
  649. }
  650. public function xianshimiaosha_shenqing()
  651. {
  652. $result = array('code' => 0);
  653. $goods_id = I('post.goods_id',0);
  654. if($goods_id == 0){
  655. $result['msg'] = '商品不存在';
  656. echo json_encode($result);
  657. die();
  658. }
  659. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  660. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  661. $spike_data = array();
  662. $spike_data['goods_id'] = $goods_id;
  663. $spike_data['state'] = 0;
  664. $spike_data['quantity'] = $goods_info['quantity'];
  665. $spike_data['begin_time'] = 0;
  666. $spike_data['end_time'] = 0;
  667. $spike_data['addtime'] = time();
  668. $rs = M('spike_goods')->add($spike_data);
  669. if($rs) {
  670. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'spike') );
  671. }
  672. $result['code'] = 1;
  673. echo json_encode($result);
  674. die();
  675. } else{
  676. $result['msg'] = '已存在其他活动中';
  677. echo json_encode($result);
  678. die();
  679. }
  680. }
  681. public function spike_sub()
  682. {
  683. $spike_id = I('post.spike',0);
  684. $goods_id = I('post.goods_id',0);
  685. if($goods_id == 0){
  686. $result['msg'] = '商品不存在';
  687. echo json_encode($result);
  688. die();
  689. }
  690. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  691. $spike_info = M('spike')->where( array('id' => $spike_id) )->find();
  692. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  693. $super_data = array();
  694. $super_data['spike_id'] = $spike_id;
  695. $super_data['goods_id'] = $goods_id;
  696. $super_data['state'] = 0;
  697. $super_data['begin_time'] = $spike_info['begin_time'];
  698. $super_data['end_time'] = $spike_info['end_time'];
  699. $super_data['addtime'] = time();
  700. $rs = M('spike_goods')->add($super_data);
  701. if($rs) {
  702. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'spike') );
  703. }
  704. $result['code'] = 1;
  705. echo json_encode($result);
  706. die();
  707. } else {
  708. $result['msg'] = '已存在其他活动中';
  709. echo json_encode($result);
  710. die();
  711. }
  712. }
  713. public function chaozhidapai_sub()
  714. {
  715. $super_spike_id = I('post.super_spike',0);
  716. $goods_id = I('post.goods_id',0);
  717. if($goods_id == 0){
  718. $result['msg'] = '商品不存在';
  719. echo json_encode($result);
  720. die();
  721. }
  722. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  723. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  724. $super_data = array();
  725. $super_data['super_spike_id'] = $super_spike_id;
  726. $super_data['goods_id'] = $goods_id;
  727. $super_data['state'] = 0;
  728. $super_data['begin_time'] = 0;
  729. $super_data['end_time'] = 0;
  730. $super_data['addtime'] = time();
  731. $rs = M('super_spike_goods')->add($super_data);
  732. if($rs) {
  733. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'super_spike') );
  734. }
  735. $result['code'] = 1;
  736. echo json_encode($result);
  737. die();
  738. } else {
  739. $result['msg'] = '已存在其他活动中';
  740. echo json_encode($result);
  741. die();
  742. }
  743. }
  744. public function oneyuansubject_sub()
  745. {
  746. $subject_id = I('post.subject',0);
  747. $goods_id = I('post.goods_id',0);
  748. if($goods_id == 0){
  749. $result['msg'] = '商品不存在';
  750. echo json_encode($result);
  751. die();
  752. }
  753. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  754. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  755. $super_data = array();
  756. $super_data['subject_id'] = $subject_id;
  757. $super_data['goods_id'] = $goods_id;
  758. $super_data['state'] = 0;
  759. $super_data['addtime'] = time();
  760. $rs = M('subject_goods')->add($super_data);
  761. if($rs) {
  762. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'oneyuan') );
  763. }
  764. $result['code'] = 1;
  765. echo json_encode($result);
  766. die();
  767. } else {
  768. $result['msg'] = '已存在其他活动中';
  769. echo json_encode($result);
  770. die();
  771. }
  772. }
  773. public function niyuansubject_sub()
  774. {
  775. $subject_id = I('post.subject',0);
  776. $goods_id = I('post.goods_id',0);
  777. if($goods_id == 0){
  778. $result['msg'] = '商品不存在';
  779. echo json_encode($result);
  780. die();
  781. }
  782. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  783. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  784. $super_data = array();
  785. $super_data['subject_id'] = $subject_id;
  786. $super_data['goods_id'] = $goods_id;
  787. $super_data['state'] = 0;
  788. $super_data['addtime'] = time();
  789. $rs = M('subject_goods')->add($super_data);
  790. if($rs) {
  791. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'niyuan') );
  792. }
  793. $result['code'] = 1;
  794. echo json_encode($result);
  795. die();
  796. } else {
  797. $result['msg'] = '已存在其他活动中';
  798. echo json_encode($result);
  799. die();
  800. }
  801. }
  802. public function mianfei_sub()
  803. {
  804. $subject_id = I('post.subject',0);
  805. $goods_id = I('post.goods_id',0);
  806. if($goods_id == 0){
  807. $result['msg'] = '商品不存在';
  808. echo json_encode($result);
  809. die();
  810. }
  811. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  812. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  813. $super_data = array();
  814. $super_data['subject_id'] = $subject_id;
  815. $super_data['goods_id'] = $goods_id;
  816. $super_data['state'] = 0;
  817. $super_data['addtime'] = time();
  818. $rs = M('subject_goods')->add($super_data);
  819. if($rs) {
  820. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'zeyuan') );
  821. }
  822. $result['code'] = 1;
  823. echo json_encode($result);
  824. die();
  825. } else {
  826. $result['msg'] = '已存在其他活动中';
  827. echo json_encode($result);
  828. die();
  829. }
  830. }
  831. public function putongsubject_sub()
  832. {
  833. $subject_id = I('post.subject',0);
  834. $goods_id = I('post.goods_id',0);
  835. if($goods_id == 0){
  836. $result['msg'] = '商品不存在';
  837. echo json_encode($result);
  838. die();
  839. }
  840. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  841. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  842. $super_data = array();
  843. $super_data['subject_id'] = $subject_id;
  844. $super_data['goods_id'] = $goods_id;
  845. $super_data['state'] = 0;
  846. $super_data['addtime'] = time();
  847. $rs = M('subject_goods')->add($super_data);
  848. if($rs) {
  849. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'subject') );
  850. }
  851. $result['code'] = 1;
  852. echo json_encode($result);
  853. die();
  854. } else {
  855. $result['msg'] = '已存在其他活动中';
  856. echo json_encode($result);
  857. die();
  858. }
  859. }
  860. public function haitaosubject_sub()
  861. {
  862. $subject_id = I('post.subject',0);
  863. $goods_id = I('post.goods_id',0);
  864. if($goods_id == 0){
  865. $result['msg'] = '商品不存在';
  866. echo json_encode($result);
  867. die();
  868. }
  869. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  870. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  871. $super_data = array();
  872. $super_data['subject_id'] = $subject_id;
  873. $super_data['goods_id'] = $goods_id;
  874. $super_data['state'] = 0;
  875. $super_data['addtime'] = time();
  876. $rs = M('subject_goods')->add($super_data);
  877. if($rs) {
  878. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'haitao') );
  879. }
  880. $result['code'] = 1;
  881. echo json_encode($result);
  882. die();
  883. } else {
  884. $result['msg'] = '已存在其他活动中';
  885. echo json_encode($result);
  886. die();
  887. }
  888. }
  889. public function yiyuan_form()
  890. {
  891. $result = array('code' => 0);
  892. $goods_id = I('post.goods_id',0);
  893. if($goods_id == 0){
  894. $result['msg'] = '商品不存在';
  895. echo json_encode($result);
  896. die();
  897. }
  898. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  899. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  900. $subject = M('subject')->where('can_shenqing=1 and type="oneyuan"')->select();
  901. $this->subject = $subject;
  902. $this->goods_id = $goods_id;
  903. $content = $this->fetch('Goods:goods_oneyuansubject_fetch');
  904. $result['code'] = 1;
  905. $result['html'] = $content;
  906. echo json_encode($result);
  907. die();
  908. } else {
  909. $result['msg'] = '已存在其他活动中';
  910. echo json_encode($result);
  911. die();
  912. }
  913. }
  914. public function jiukuaijiu_form()
  915. {
  916. $result = array('code' => 0);
  917. $goods_id = I('post.goods_id',0);
  918. if($goods_id == 0){
  919. $result['msg'] = '商品不存在';
  920. echo json_encode($result);
  921. die();
  922. }
  923. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  924. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  925. $subject = M('subject')->where('can_shenqing=1 and type="niyuan"')->select();
  926. $this->subject = $subject;
  927. $this->goods_id = $goods_id;
  928. $content = $this->fetch('Goods:goods_niyuansubject_fetch');
  929. $result['code'] = 1;
  930. $result['html'] = $content;
  931. echo json_encode($result);
  932. die();
  933. } else {
  934. $result['msg'] = '已存在其他活动中';
  935. echo json_encode($result);
  936. die();
  937. }
  938. }
  939. public function lottery_form()
  940. {
  941. $result = array('code' => 0);
  942. $goods_id = I('post.goods_id',0);
  943. if($goods_id == 0){
  944. $result['msg'] = '商品不存在';
  945. echo json_encode($result);
  946. die();
  947. }
  948. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  949. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  950. $voucher_list = M('voucher')->where( "store_id=".SELLERUID." and begin_time>".time() )->select();
  951. $this->voucher_list = $voucher_list;
  952. $this->goods_id = $goods_id;
  953. $content = $this->fetch('Goods:goods_lottery_fetch');
  954. $result['code'] = 1;
  955. $result['html'] = $content;
  956. echo json_encode($result);
  957. die();
  958. } else {
  959. $result['msg'] = '已存在其他活动中';
  960. echo json_encode($result);
  961. die();
  962. }
  963. }
  964. public function lottery_sub()
  965. {
  966. $voucher_id = I('post.voucher_id',0);
  967. $goods_id = I('post.goods_id',0);
  968. $win_quantity = I('post.win_quantity',0);
  969. $is_auto_open = I('post.is_auto_open',0);
  970. $real_win_quantity = I('post.real_win_quantity',0);
  971. if($goods_id == 0){
  972. $result['msg'] = '商品不存在';
  973. echo json_encode($result);
  974. die();
  975. }
  976. if($voucher_id == 0){
  977. $result['msg'] = '请选择退款时赠送的优惠券';
  978. echo json_encode($result);
  979. die();
  980. }
  981. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  982. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  983. $spike_data = array();
  984. $spike_data['goods_id'] = $goods_id;
  985. $spike_data['state'] = 0;
  986. $spike_data['is_open_lottery'] = 0;
  987. $spike_data['voucher_id'] = $voucher_id;
  988. $spike_data['win_quantity'] = $win_quantity;
  989. $spike_data['is_auto_open'] = $is_auto_open;
  990. $spike_data['real_win_quantity'] = $real_win_quantity;
  991. $spike_data['quantity'] = $goods_info['quantity'];
  992. $spike_data['begin_time'] = 0;
  993. $spike_data['end_time'] = 0;
  994. $spike_data['addtime'] = time();
  995. $rs = M('lottery_goods')->add($spike_data);
  996. if($rs) {
  997. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'lottery') );
  998. }
  999. $result['code'] = 1;
  1000. echo json_encode($result);
  1001. die();
  1002. die();
  1003. } else {
  1004. $result['msg'] = '已存在其他活动中';
  1005. echo json_encode($result);
  1006. die();
  1007. }
  1008. }
  1009. public function putongsubject_form()
  1010. {
  1011. $result = array('code' => 0);
  1012. $goods_id = I('post.goods_id',0);
  1013. if($goods_id == 0){
  1014. $result['msg'] = '商品不存在';
  1015. echo json_encode($result);
  1016. die();
  1017. }
  1018. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  1019. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  1020. $subject = M('subject')->where('can_shenqing=1 and type="normal"')->select();
  1021. $this->subject = $subject;
  1022. $this->goods_id = $goods_id;
  1023. $content = $this->fetch('Goods:goods_putongsubject_fetch');
  1024. $result['code'] = 1;
  1025. $result['html'] = $content;
  1026. echo json_encode($result);
  1027. die();
  1028. } else {
  1029. $result['msg'] = '已存在其他活动中';
  1030. echo json_encode($result);
  1031. die();
  1032. }
  1033. }
  1034. public function haitaosubject_form()
  1035. {
  1036. $result = array('code' => 0);
  1037. $goods_id = I('post.goods_id',0);
  1038. if($goods_id == 0){
  1039. $result['msg'] = '商品不存在';
  1040. echo json_encode($result);
  1041. die();
  1042. }
  1043. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  1044. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  1045. $subject = M('subject')->where('can_shenqing=1 and type="haitao"')->select();
  1046. $this->subject = $subject;
  1047. $this->goods_id = $goods_id;
  1048. $content = $this->fetch('Goods:goods_haitaosubject_fetch');
  1049. $result['code'] = 1;
  1050. $result['html'] = $content;
  1051. echo json_encode($result);
  1052. die();
  1053. } else {
  1054. $result['msg'] = '已存在其他活动中';
  1055. echo json_encode($result);
  1056. die();
  1057. }
  1058. }
  1059. public function mianfeishiyong_form()
  1060. {
  1061. $result = array('code' => 0);
  1062. $goods_id = I('post.goods_id',0);
  1063. if($goods_id == 0){
  1064. $result['msg'] = '商品不存在';
  1065. echo json_encode($result);
  1066. die();
  1067. }
  1068. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  1069. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  1070. $subject = M('subject')->where('can_shenqing=1 and type="zeyuan"')->select();
  1071. $this->subject = $subject;
  1072. $this->goods_id = $goods_id;
  1073. $content = $this->fetch('Goods:goods_mianfeishiyong_fetch');
  1074. $result['code'] = 1;
  1075. $result['html'] = $content;
  1076. echo json_encode($result);
  1077. die();
  1078. } else {
  1079. $result['msg'] = '已存在其他活动中';
  1080. echo json_encode($result);
  1081. die();
  1082. }
  1083. }
  1084. public function chaozhidapai_form()
  1085. {
  1086. $result = array('code' => 0);
  1087. $goods_id = I('post.goods_id',0);
  1088. if($goods_id == 0){
  1089. $result['msg'] = '商品不存在';
  1090. echo json_encode($result);
  1091. die();
  1092. }
  1093. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  1094. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  1095. $super_spike_list = M('super_spike')->where('begin_time>'.time())->select();
  1096. $this->super_spike_list = $super_spike_list;
  1097. $this->goods_id = $goods_id;
  1098. $content = $this->fetch('Goods:goods_chaozhidapai_fetch');
  1099. $result['code'] = 1;
  1100. $result['html'] = $content;
  1101. echo json_encode($result);
  1102. die();
  1103. } else {
  1104. $result['msg'] = '已存在其他活动中';
  1105. echo json_encode($result);
  1106. die();
  1107. }
  1108. }
  1109. public function spike_form()
  1110. {
  1111. $result = array('code' => 0);
  1112. $goods_id = I('post.goods_id',0);
  1113. if($goods_id == 0){
  1114. $result['msg'] = '商品不存在';
  1115. echo json_encode($result);
  1116. die();
  1117. }
  1118. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  1119. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  1120. $spike_list = M('spike')->where()->select();
  1121. //$spike_list = M('spike')->where('begin_time>'.time())->select();
  1122. $this->spike_list = $spike_list;
  1123. $this->goods_id = $goods_id;
  1124. $content = $this->fetch('Goods:goods_spike_fetch');
  1125. $result['code'] = 1;
  1126. $result['html'] = $content;
  1127. echo json_encode($result);
  1128. die();
  1129. } else {
  1130. $result['msg'] = '已存在其他活动中';
  1131. echo json_encode($result);
  1132. die();
  1133. }
  1134. }
  1135. public function get_json_category_tree($pid,$is_ajax=0)
  1136. {
  1137. // {pid:pid,is_ajax:1}
  1138. $pid = empty($_GET['pid']) ? 0: intval($_GET['pid']);
  1139. $is_ajax = empty($_GET['is_ajax']) ? 0:intval($_GET['is_ajax']);
  1140. $goods_cate_model = D('Seller/GoodsCategory');
  1141. $list = $goods_cate_model->get_parent_cateory($pid,SELLERUID);
  1142. $result = array();
  1143. if($is_ajax ==0)
  1144. {
  1145. return $list;
  1146. } else {
  1147. if(empty($list)){
  1148. $result['code'] = 0;
  1149. } else {
  1150. $result['code'] = 1;
  1151. $result['list'] = $list;
  1152. }
  1153. echo json_encode($result);
  1154. die();
  1155. }
  1156. }
  1157. function add(){
  1158. $model=new GoodsModel();
  1159. if(IS_POST){
  1160. $data=I('post.');
  1161. $data['goods_description']['tag'] = str_replace(',', ',', $data['goods_description']['tag']);
  1162. $data['store_id']=SELLERUID;
  1163. if($this->goods_is_shenhe()) {
  1164. $data['status'] = 2;
  1165. }
  1166. $return=$model->add_goods($data);
  1167. $this->osc_alert($return);
  1168. }
  1169. $parent_area = M('area')->where( array('area_parent_id' => 0) )->order('area_sort asc ,area_id asc')->select();
  1170. foreach($parent_area as $key => $val)
  1171. {
  1172. $child_ren = M('area')->where( array('area_parent_id' => $val['area_id']) )->order('area_sort asc ,area_id asc')->select();
  1173. $val['child'] = $child_ren;
  1174. $parent_area[$key] = $val;
  1175. }
  1176. $this->parent_area = $parent_area;
  1177. //库存状态
  1178. $this->stock_status=M('StockStatus')->select();
  1179. $this->cate_data = $this->get_json_category_tree(0);
  1180. $this->action=U('Goods/add');
  1181. $this->crumbs='新增';
  1182. $this->display('edit');
  1183. }
  1184. /**
  1185. 商品是否需要审核
  1186. **/
  1187. function goods_is_shenhe()
  1188. {
  1189. $shenhegoods = M('config')->where( array('name' => 'shenhegoods') )->find();
  1190. $is_need_shen = 0;
  1191. if(!empty($shenhegoods)) {
  1192. $is_need_shen = $shenhegoods['value'];
  1193. }
  1194. return $is_need_shen;
  1195. }
  1196. function edit(){
  1197. $model=new GoodsModel();
  1198. $cate_data = $this->get_json_category_tree(0);
  1199. if(IS_POST){
  1200. $data=I('post.');
  1201. if($this->goods_is_shenhe()) {
  1202. $data['status'] = 2;
  1203. }
  1204. $data['goods_description']['tag'] = str_replace(',', ',', $data['goods_description']['tag']);
  1205. $data['store_id']=SELLERUID;
  1206. $return=$model->edit_goods($data);
  1207. $this->osc_alert($return);
  1208. }
  1209. $goods_area = M('goods_area')->where( array('goods_id' => I('id')) )->find();
  1210. if(!empty($goods_area)) {
  1211. $goods_area['area_ids'] =unserialize( $goods_area['area_ids_text']);
  1212. }
  1213. $this->goods_area=$goods_area;
  1214. $parent_area = M('area')->where( array('area_parent_id' => 0) )->order('area_sort asc ,area_id asc')->select();
  1215. foreach($parent_area as $key => $val)
  1216. {
  1217. $child_ren = M('area')->where( array('area_parent_id' => $val['area_id']) )->order('area_sort asc ,area_id asc')->select();
  1218. $val['child'] = $child_ren;
  1219. $parent_area[$key] = $val;
  1220. }
  1221. $this->parent_area = $parent_area;
  1222. $this->crumbs='编辑';
  1223. $this->action=U('Goods/edit');
  1224. $this->description=M('goods_description')->find(I('id'));
  1225. //库存状态
  1226. $this->stock_status=M('StockStatus')->select();
  1227. $this->goods=$model->get_goods_data(I('id'));
  1228. $this->goods_images=$model->get_goods_image_data(I('id'));
  1229. $this->goods_discount=M('goods_discount')->where(array('goods_id'=>I('id')))->order('quantity ASC')->select();
  1230. $this->goods_categories=$model->get_goods_category_data(I('id'));
  1231. //transport_id
  1232. if($this->goods['transport_id'] > 0)
  1233. {
  1234. $this->transport = D('Seller/Transport')->getTransportInfo(array('id' => $this->goods['transport_id']));
  1235. }
  1236. //var_dump($this->transport);die();
  1237. $this->goods_options=$model->get_goods_options(I('id'));
  1238. //dump($this->goods_options);die;
  1239. $option_model=new \Admin\Model\OptionModel();
  1240. //选项值
  1241. foreach ($this->goods_options as $goods_option) {
  1242. $option_values[$goods_option['option_id']] = $option_model->getOptionValues($goods_option['option_id']);
  1243. }
  1244. //dump($this->goods_options);
  1245. //dump($option_values);die;
  1246. $this->option_values=$option_values;
  1247. $this->assign('cate_data',$cate_data);// 赋值数据集
  1248. $this->display('edit');
  1249. }
  1250. function copy_goods(){
  1251. $id =I('id');
  1252. $model=new GoodsModel();
  1253. if($id){
  1254. foreach ($id as $k => $v) {
  1255. $model->copy_goods($v);
  1256. }
  1257. $data['redirect']=U('Goods/index');
  1258. $this->ajaxReturn($data);
  1259. die;
  1260. }
  1261. }
  1262. function del(){
  1263. $model=new GoodsModel();
  1264. $return=$model->del_goods(I('get.id'));
  1265. $this->osc_alert($return);
  1266. }
  1267. }
  1268. ?>