ApigoodsController.class.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538
  1. <?php
  2. // $Id:$
  3. /**
  4. * lionfish 商城系统
  5. *
  6. * ==========================================================================
  7. * @link http://www.liofis.com/
  8. * @copyright Copyright (c) 2015 liofis.com.
  9. * @license http://www.liofis.com/license.html License
  10. * ==========================================================================
  11. *
  12. * @author fish
  13. *
  14. */
  15. namespace Home\Controller;
  16. class ApigoodsController extends CommonController {
  17. protected function _initialize() {
  18. parent::_initialize();
  19. $this->cur_page = 'apigoods';
  20. }
  21. public function get_goods_option_data()
  22. {
  23. $id = I('get.id',28);
  24. $token = I('get.token');
  25. $sku_str = I('get.sku_str','45_53');
  26. //45_53
  27. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  28. $member_id = $weprogram_token['member_id'];
  29. $goods_model = D('Home/Goods');
  30. $goods_option_mult_value = M('goods_option_mult_value')->where(array(
  31. 'goods_id' => $id
  32. ))->order('id asc')->select();
  33. $goods_option_mult_value_ref = array();
  34. foreach ($goods_option_mult_value as $key => $val) {
  35. $val['image'] = C('SITE_URL') . resize($val['image'], 200, 200);
  36. $goods_option_mult_value[$key] = $val;
  37. $goods_option_mult_value_ref[$val['rela_goodsoption_valueid']] = $val;
  38. }
  39. $need_data = array();
  40. $level_info = $goods_model->get_member_level_info($member_id, $id);
  41. $member_disc = 100;
  42. if( !empty($level_info) )
  43. {
  44. $member_disc = $level_info['member_discount'];
  45. }
  46. $max_member_level = M('member_level')->order('level desc')->find();
  47. /**
  48. $max_member_level = M('member_level')->order('level desc')->find();
  49. $goods[0]['memberprice'] = round( ($goods[0]['danprice'] * $member_disc) / 100 ,2);
  50. $max_get_money = round( ($goods[0]['danprice'] * (100 - $max_member_level['discount']) ) / 100 ,2);
  51. if(!empty($pin_info))
  52. {
  53. $pin_info['member_pin_price'] = round( ($pin_info['pin_price'] * $member_disc) / 100 ,2);
  54. $max_get_money = round( ($pin_info['pin_price'] * (100 - $max_member_level['discount']) ) / 100 ,2);
  55. }
  56. **/
  57. $goods_option_mult_value_ref[$sku_str]['member_pin_price'] = round( ($goods_option_mult_value_ref[$sku_str]['pin_price'] * $member_disc) / 100 ,2);
  58. $goods_option_mult_value_ref[$sku_str]['memberprice'] = round( ($goods_option_mult_value_ref[$sku_str]['dan_price'] * $member_disc) / 100 ,2);
  59. $goods_option_mult_value_ref[$sku_str]['max_member_pin_price'] = 0;
  60. $goods_option_mult_value_ref[$sku_str]['max_memberprice'] = 0;
  61. if( !empty($max_member_level) )
  62. {
  63. $goods_option_mult_value_ref[$sku_str]['max_member_pin_price'] = round( ($goods_option_mult_value_ref[$sku_str]['pin_price'] * (100 - $max_member_level['discount']) ) / 100 ,2);
  64. $goods_option_mult_value_ref[$sku_str]['max_memberprice'] = round( ($goods_option_mult_value_ref[$sku_str]['dan_price'] * (100 - $max_member_level['discount']) ) / 100 ,2);
  65. }
  66. $need_data['value'] = $goods_option_mult_value_ref[$sku_str];
  67. echo json_encode( array('code' =>0 , 'data' =>$need_data ) );
  68. die();
  69. }
  70. public function seller_info2()
  71. {
  72. $seller_id = I('get.id');
  73. $seller_info = M('seller')->field('s_true_name,s_logo')->where( array('s_id' => $seller_id) )->find();
  74. $seller_info['s_logo'] = C('SITE_URL').'Uploads/image/'.$seller_info['s_logo'];
  75. $seller_model = D('Home/Seller');
  76. $seller_count = $seller_model->getStoreSellerCount($seller_id);
  77. $goods_count = M('goods')->where( array('store_id' => $seller_id) )->count();
  78. $store_class_list = M('store_bind_class')->where( array('seller_id' => $seller_id) )->order('bid asc')->select();
  79. $store_class_ids = array();
  80. foreach($store_class_list as $class_val)
  81. {
  82. $store_class_ids[] = $class_val['class_1'];
  83. }
  84. $category_list = array();
  85. if( !empty($store_class_ids) )
  86. {
  87. $category_list = M('goods_category')->field('id,name')->where( array('id' => array('in', $store_class_ids) ) )->select();
  88. }
  89. $seller_info['seller_count'] = $seller_count;
  90. $seller_info['goods_count'] = $goods_count;
  91. $need_data = array();
  92. $need_data['seller_info'] = $seller_info;
  93. $need_data['category_list'] = $category_list;
  94. echo json_encode( array('code' => 0 , 'data' => $need_data) );
  95. die();
  96. }
  97. public function search()
  98. {
  99. /**
  100. C('SITE_URLS').resize($val['fan_image'], 220, 220)
  101. **/
  102. $parent_list = M('goods_category')->where( array('pid' =>0, 'is_search' =>1) )->order('c_sort_order desc,sort_order desc')->select();
  103. //logo
  104. foreach($parent_list as $key => $val)
  105. {
  106. if( !empty($val['logo']) )
  107. {
  108. $val['logo'] = C('SITE_URL').resize($val['logo'], 220, 220);
  109. }
  110. $child_list = M('goods_category')->where( array('pid' => $val['id'], 'is_search' =>1) )->order('c_sort_order desc,sort_order desc')->select();
  111. foreach($child_list as $kk => $vv)
  112. {
  113. if( !empty($vv['logo']) )
  114. {
  115. $vv['logo'] = C('SITE_URL').resize($vv['logo'], 220, 220);
  116. }
  117. $child_list[$kk] = $vv;
  118. }
  119. $val['child_list'] = $child_list;
  120. $parent_list[$key] = $val;
  121. }
  122. echo json_encode( array('code' => 0, 'data' => $parent_list) );
  123. die();
  124. //$this->parent_list = $parent_list;
  125. }
  126. /**
  127. 获取积分兑换商品
  128. **/
  129. public function get_integral_goods()
  130. {
  131. $goods_model = D('Home/Goods');
  132. $pre_page = 10;
  133. $page = I('get.page',1);
  134. $condition = array('type' => 'integral', 'status'=>1,'quantity' =>array('gt',0) );
  135. $offset = ($page -1) * $pre_page;
  136. $list = M('goods')->where($condition)->order('seller_count+virtual_count desc,goods_id asc')->limit($offset,$pre_page)->select();
  137. if(!empty($list)) {
  138. foreach($list as $key => $v){
  139. $goods_price_arr = $goods_model->get_goods_price($v['goods_id']);
  140. $list[$key]['pinprice'] = $goods_price_arr['price'];
  141. $list[$key]['image']=C('SITE_URL'). resize($v['image'], 400, 400);
  142. }
  143. }
  144. foreach($list as $key => $val)
  145. {
  146. $val['seller_count'] += $val['virtual_count'];
  147. $list[$key] = $val;
  148. }
  149. $integral_rules = C('integral_description');
  150. $qian=array("\r\n");
  151. $hou=array("@F@");
  152. $integral_rules_str = str_replace($qian,$hou,$integral_rules);
  153. $integral_rules_str = explode('@F@',$integral_rules_str);
  154. if( !empty($list) )
  155. {
  156. echo json_encode( array('code' => 0, 'data' => $list , 'integral_rules_str' => $integral_rules_str ) );
  157. die();
  158. } else {
  159. echo json_encode( array('code' => 1 , 'integral_rules_str' => $integral_rules_str) );
  160. die();
  161. }
  162. }
  163. public function get_category_goods()
  164. {
  165. $goods_model = D('Home/Goods');
  166. $pre_page = 10;
  167. $page = I('get.page',1);
  168. $id = I('get.id',0);
  169. $goods_ids_arr = M('goods_to_category')->where("class_id1 ={$id} or class_id2 ={$id} or class_id3 = {$id} ")->field('goods_id')->select();
  170. $ids_arr = array();
  171. foreach($goods_ids_arr as $val){
  172. $ids_arr[] = $val['goods_id'];
  173. }
  174. $ids_str = implode(',',$ids_arr);
  175. //lottery pintuan oneyuan normal
  176. $condition = array('goods_id' => array('in',$ids_str),'type' => array('in', array('normal','oneyuan','lottery','pintuan') ) , 'status'=>1,'quantity' =>array('gt',0) );
  177. $offset = ($page -1) * $pre_page;
  178. $list = M('goods')->where($condition)->order('seller_count+virtual_count desc,goods_id asc')->limit($offset,$pre_page)->select();
  179. if(!empty($list)) {
  180. foreach($list as $key => $v){
  181. $goods_price_arr = $goods_model->get_goods_price($v['goods_id']);
  182. $list[$key]['pinprice'] = $goods_price_arr['price'];
  183. //
  184. //$goods[0]['danprice'] = $goods_price_arr['danprice'];
  185. //$price_dol = explode('.', $goods_price_arr['pin_price']);
  186. $list[$key]['image']=C('SITE_URL'). resize($v['image'], 400, 400);
  187. }
  188. }
  189. foreach($list as $key => $val)
  190. {
  191. $val['seller_count'] += $val['virtual_count'];
  192. $list[$key] = $val;
  193. }
  194. if( !empty($list) )
  195. {
  196. echo json_encode( array('code' => 0, 'data' => $list ) );
  197. die();
  198. } else {
  199. echo json_encode( array('code' => 1) );
  200. die();
  201. }
  202. }
  203. /**
  204. 我的助力
  205. **/
  206. public function assist_free_coupon_me()
  207. {
  208. $token = I('get.token');
  209. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  210. $member_id = $weprogram_token['member_id'];
  211. $free_ad_list = M('plugins_slider')->where( array('type' => 'free_ad') )->order('slider_id desc')->find();
  212. $per_page = 10;
  213. $page = I('get.page',1);
  214. $offset = ($page - 1) * $per_page;
  215. $sql = 'select z.id,z.need_person,z.total_money as pinprice,z.deal_money,z.end_time,z.state,g.goods_id,g.name,g.quantity,g.price,g.danprice,g.image,g.fan_image,g.store_id,g.seller_count,g.virtual_count
  216. from '.C('DB_PREFIX').'goods as g ,'.C('DB_PREFIX').'bargain_order as z
  217. where z.member_id = '.$member_id.' and z.goods_id = g.goods_id order by z.end_time desc limit '.$offset.','.$per_page;
  218. $list = M()->query($sql);
  219. foreach($list as $key => $v){
  220. //$has_zan_count = M('zan_order_detail')->where( array('zan_order_id' => $v['id']) )->count();
  221. //$list[$key]['has_zan_count'] = $has_zan_count;
  222. if($v['state'] == 0 && $v['end_time'] < time())
  223. {
  224. $list[$key]['state'] = 2;
  225. }
  226. $list[$key]['seller_count'] += $v['virtual_count'];
  227. $list[$key]['image']= C('SITE_URL').resize($v['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  228. }
  229. if(!empty($list))
  230. {
  231. echo json_encode( array('code' => 0, 'data' => $list ) );
  232. die();
  233. }else{
  234. echo json_encode( array('code' => 1) );
  235. die();
  236. }
  237. }
  238. /**
  239. 砍价详情
  240. **/
  241. public function bargain_detail()
  242. {
  243. $is_me = false;
  244. $has_kan = false;
  245. $token = I('get.token');
  246. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  247. $member_id = $weprogram_token['member_id'];
  248. $id = I('get.id');
  249. $bargain_info = M('bargain_order')->where( array('id' => $id) )->find();
  250. $bargain_info['already_money'] = round($bargain_info['total_money']-$bargain_info['deal_money'],2);
  251. if($bargain_info['member_id'] == $member_id)
  252. {
  253. $is_me = true;
  254. }
  255. if($bargain_info['state'] != 1 && $bargain_info['end_time'] > time() )
  256. {
  257. $bargain_info['state'] = 3;
  258. }
  259. $has_kan_count = M('bargain_order_detail')->where( array('member_id' => $member_id,'bargain_order_id' => $id) )->count();
  260. if($has_kan_count >0)
  261. {
  262. $has_kan = true;
  263. }
  264. //end_time
  265. $now_time = time();
  266. $goods_info = M('goods')->field('name,price,seller_count,virtual_count,image,fan_image')->where( array('goods_id' => $bargain_info['goods_id']) )->find();
  267. $goods_info['image'] = C('SITE_URL').resize($goods_info['image'],300,300);
  268. //fan_image
  269. if(!empty($goods_info['fan_image']))
  270. {
  271. $goods_info['image'] = C('SITE_URL').resize($goods_info['fan_image'],300,300);
  272. }
  273. $goods_info['seller_count'] += $goods_info['virtual_count'];
  274. $kan_order_list = M('bargain_order_detail')->where( array('bargain_order_id' =>$id) )->order('addtime desc')->limit(15)->select();
  275. $need_data = array();
  276. $need_data['kan_order_list'] = $kan_order_list;
  277. $need_data['bargain_info'] = $bargain_info;
  278. $need_data['goods_info'] = $goods_info;
  279. $need_data['is_me'] = $is_me;
  280. $need_data['has_kan'] = $has_kan;
  281. //$this->kan_order_list = $kan_order_list;
  282. //$this->bargain_info = $bargain_info;
  283. //$this->goods_info = $goods_info;
  284. //$this->is_me = $is_me;
  285. //$this->has_kan = $has_kan;
  286. //member_id
  287. $member_info = M('member')->where( array('member_id' => $bargain_info['member_id']) )->find();
  288. $need_data['member_info'] = $member_info;
  289. //$this->member_info = $member_info;
  290. $kan_description = C('kan_description');
  291. $qian=array("\r\n");
  292. $hou=array("@F@");
  293. $kan_description_str = str_replace($qian,$hou,$kan_description);
  294. $kan_description_str = explode('@F@',$kan_description_str);
  295. //$this->kan_description_str = $kan_description_str;
  296. //$this->kan_description_str = $kan_description_str;
  297. $need_data['kan_description_str'] = $kan_description_str;
  298. $kan_rules = C('kan_rules');
  299. $qian=array("\r\n");
  300. $hou=array("@F@");
  301. $kan_rules_str = str_replace($qian,$hou,$kan_rules);
  302. $kan_rules_str = explode('@F@',$kan_rules_str);
  303. //$this->kan_rules_str = $kan_rules_str;
  304. $need_data['kan_rules_str'] = $kan_rules_str;
  305. $kan_person_count = C('kan_person_count');
  306. //$this->kan_person_count = $kan_person_count;
  307. $need_data['kan_person_count'] = $kan_person_count;
  308. //随机商品 8 个
  309. $sql='SELECT goods_id,image,fan_image,price,danprice,name,seller_count,virtual_count FROM '.C('DB_PREFIX').'goods WHERE status=1 and type="normal" and quantity >0 ORDER BY rand() LIMIT 0,8';
  310. $list=M()->query($sql);
  311. $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
  312. foreach ($list as $k => $v) {
  313. $list[$k]['seller_count'] += $list[$k]['virtual_count'];
  314. $list[$k]['image']= C('SITE_URL').resize($v['image'], C('goods_related_thumb_width'), C('goods_related_thumb_height'));
  315. if(!empty($v['fan_image'])){
  316. $list[$k]['image']= C('SITE_URL').resize($v['fan_image'], C('goods_related_thumb_width'), C('goods_related_thumb_height'));
  317. }else {
  318. $list[$k]['image']= C('SITE_URL').resize($v['image'], C('goods_related_thumb_width'), C('goods_related_thumb_height'));
  319. }
  320. }
  321. //$this->related_goods=$list;
  322. $need_data['related_goods'] = $list;
  323. $bargain_order = M('bargain_order')->where( array('id' => $id) )->find();
  324. $goods_id = $bargain_order['goods_id'];
  325. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  326. //"我正在参加拼多多官方砍价,砍到0元就可以免费拿啦,帮我砍一下吧"
  327. $desc = "我正在参加".C('SITE_NAME')."砍价,砍到0元就可以免费拿啦,帮我砍一下吧";
  328. //$this->share_logo = C('SITE_URL').resize($goods_info['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  329. $need_data['share_logo'] = C('SITE_URL').resize($goods_info['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  330. $share_logo = '';
  331. if(!empty($goods_info['fan_image'])){
  332. $share_logo = C('SITE_URL').resize($goods_info['fan_image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  333. }else {
  334. $share_logo = C('SITE_URL').resize($goods_info['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  335. }
  336. if(!empty($goods_description['water_image']))
  337. {
  338. $share_logo = C('SITE_URL').'/Uploads/image/'.$goods_description['water_image'];
  339. }
  340. $need_data['share_logo'] = $share_logo;
  341. //Subject/assist_bargain_coupon_detail/id/10.html kan_rules_str
  342. $need_data['indexsharetitle'] = '['.C('SITE_NAME')."]我在砍价免费拿".$goods_info['name'].",帮我砍价,0元拿回家!";
  343. $need_data['url'] = C('SITE_URL')."/index.php?s=/Subject/assist_bargain_coupon_detail/id/{$id}/rmid/{$hash_member_id}";
  344. $need_data['indexsharesummary'] = $desc;
  345. $need_data['cur_time'] = time();
  346. echo json_encode( array('code' => 0, 'data' => $need_data) );
  347. die();
  348. }
  349. /**
  350. 分享成功后,砍
  351. **/
  352. public function share_success_kan()
  353. {
  354. $id = I('get.id');
  355. $token = I('get.token');
  356. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  357. $member_id = $weprogram_token['member_id'];
  358. //$member_id = session('user_auth.uid');
  359. $bargain_order = M('bargain_order')->where( array('id' => $id) )->find();
  360. //is_share
  361. if($bargain_order['is_share'] == 0 && $member_id == $bargain_order['member_id'] )
  362. {
  363. $order_detail = M('bargain_order_detail')->where( array('member_id' => $member_id, 'bargain_order_id' => $id) )->find();
  364. $old = $order_detail['kan_money'];
  365. $state = $this->_bang_kan_order($id,$member_id,true,true );
  366. $bargain_order = M('bargain_order')->where( array('id' => $id) )->find();
  367. $bargain_order['kan_money'] = round($bargain_order['total_money'] - $bargain_order['deal_money'],2);
  368. $bargain_order['deal_money'] = round($bargain_order['deal_money'],2);
  369. $bargain_order['already_money'] = round($bargain_order['total_money']-$bargain_order['deal_money'],2);
  370. if($bargain_order['state'] != 1 && $bargain_order['end_time'] > time() )
  371. {
  372. $bargain_order['state'] = 3;
  373. }
  374. //{"code":0,"li_html":"","order_detail":{"id":"45","member_id":"456","kan_money":0.28,"bargain_order_id":"26","addtime":"1531465747","is_sleft":"1","avatar":"https:\/\/wx.qlogo.cn\/mmopen\/vi_32\/DYAIOgq83eqiajGaVicwDKXSNwdia7lyovicLib6cMDWNdR9Ce6sA9icfqibYbPYbXSq8x8uMB8zArckA67icRzSjDsSFA\/132","nickname":"\u4f59\u5efa"},"bargain_order":{"total_money":"5.00","deal_money":3.37,"kan_money":1.63,"already_money":1.63}}
  375. $order_detail = M('bargain_order_detail')->where( array('member_id' => $member_id, 'bargain_order_id' => $id) )->find();
  376. $order_detail['kan_money'] = round($order_detail['kan_money'] - $old, 2);
  377. $li_html = "";
  378. $kan_order_list = M('bargain_order_detail')->where( array('bargain_order_id' =>$id) )->order('addtime desc')->limit(15)->select();
  379. echo json_encode( array('code' => 0,'li_html' => $li_html,'kan_order_list' => $kan_order_list, 'order_detail' => $order_detail, 'bargain_order' => $bargain_order) );
  380. die();
  381. }else{
  382. echo json_encode( array('code' => 1) );
  383. die();
  384. }
  385. }
  386. /**
  387. 帮忙别人砍价
  388. **/
  389. public function kan_others_bargain()
  390. {
  391. $id = I('get.id',0);
  392. $token = I('get.token');
  393. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  394. $member_id = $weprogram_token['member_id'];
  395. if(empty($member_id))
  396. {
  397. echo json_encode( array('code' => 5, 'msg' => '请先登录') );
  398. die();
  399. }
  400. $state = $this->_bang_kan_order($id,$member_id,false);
  401. //1;//已经帮忙砍过
  402. //2; //活动已经成功,或者已经结束
  403. //3;//今天已经不能再帮别人砍价
  404. //4 砍价失败
  405. //0成功
  406. if($state > 0)
  407. {
  408. $msg = '';
  409. switch($state)
  410. {
  411. case 1 :
  412. $msg = '已经帮忙砍过了';
  413. break;
  414. case 2:
  415. $msg = '活动已经结束';
  416. break;
  417. case 3:
  418. $msg = '今天已经不能再帮别人砍价了';
  419. break;
  420. case 4:
  421. $msg = '砍价失败';
  422. break;
  423. }
  424. echo json_encode( array('code' => $state, 'msg' => $msg) );
  425. die();
  426. }else{
  427. $bargain_order = M('bargain_order')->field('total_money,deal_money')->where( array('id' => $id) )->find();
  428. $bargain_order['kan_money'] = round($bargain_order['total_money'] - $bargain_order['deal_money'],2);
  429. $bargain_order['deal_money'] = round($bargain_order['deal_money'],2);
  430. $bargain_order['already_money'] = round($bargain_order['total_money']-$bargain_order['deal_money'],2);
  431. $bargain_order['state'] = 3;
  432. $order_detail = M('bargain_order_detail')->where( array('member_id' => $member_id, 'bargain_order_id' => $id) )->find();
  433. $order_detail['kan_money'] = round($order_detail['kan_money'], 2);
  434. $li_html = "";
  435. echo json_encode( array('code' => 0,'li_html' => $li_html, 'order_detail' => $order_detail, 'bargain_order' => $bargain_order) );
  436. die();
  437. }
  438. }
  439. public function get_user_goods_qrcode2()
  440. {
  441. $token = I('get.token');
  442. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  443. $member_id = $weprogram_token['member_id'];
  444. $goods_id = I('get.goods_id');
  445. $goods_share_image = M('goods_share_image')->where( array('member_id' =>$member_id,'goods_id' => $goods_id ) )->find();
  446. if( !empty($goods_share_image) )
  447. {
  448. $result = array('code' => 0, 'image_path' => $goods_share_image['image_path']);
  449. echo json_encode($result);
  450. die();
  451. }else {
  452. $goods_model = D('Home/Goods');
  453. $goods_description = M('goods_description')->where( array('goods_id' =>$goods_id) )->find();
  454. if( empty($goods_description['wepro_qrcode_image']) || true)
  455. {
  456. $this->get_weshare_image($goods_id);
  457. $goods_description = M('goods_description')->where( array('goods_id' =>$goods_id) )->find();
  458. }
  459. $rocede_path = $goods_model->_get_goods_user_wxqrcode($goods_id,$member_id);
  460. $res = $goods_model->_get_compare_qrcode_bgimg($goods_description['wepro_qrcode_image'], $rocede_path);
  461. $data = array();
  462. $data['member_id'] = $member_id;
  463. $data['goods_id'] = $goods_id;
  464. $data['image_path'] = $res['full_path'];
  465. $data['addtime'] = time();
  466. M('goods_share_image')->add($data);
  467. $result = array('code' => 0, 'image_path' => $res['full_path']);
  468. echo json_encode($result);
  469. die();
  470. }
  471. }
  472. private function get_weshare_image($goods_id)
  473. {
  474. //400*400 fan_image
  475. //get_goods_price($goods_id)
  476. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  477. $goods_img = ROOT_PATH.'Uploads/image/'.$goods_info['image'];
  478. if( !empty($goods_info['fan_image']) )
  479. {
  480. $goods_img = ROOT_PATH.'Uploads/image/'.$goods_info['fan_image'];
  481. }
  482. $goods_model = D('Home/Goods');
  483. $goods_price = $goods_model->get_goods_price($goods_id);
  484. $goods_price['market_price'] = $goods_info['price'];
  485. //price
  486. $goods_title = $goods_info['name'];
  487. $need_img = $goods_model->_get_compare_zan_img($goods_img,$goods_title,$goods_price);
  488. //贴上二维码图
  489. //$rocede_path = $goods_model->_get_goods_user_wxqrcode($goods_id,$member_id);
  490. //$res = $goods_model->_get_compare_qrcode_bgimg($need_img['need_path'], $rocede_path);
  491. M('goods_description')->where( array('goods_id' =>$goods_id) )->save( array('wepro_qrcode_image' =>$need_img['need_path']) );
  492. return true;
  493. }
  494. /**
  495. 砍价开始
  496. **/
  497. public function get_user_goods_qrcode()
  498. {
  499. $token = I('get.token');
  500. //user_favgoods
  501. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  502. $member_id = $weprogram_token['member_id'];
  503. $data_json = file_get_contents('php://input');
  504. $data = json_decode($data_json, true);
  505. if(empty($data))
  506. {
  507. $this->get_user_goods_qrcode2();
  508. die();
  509. }
  510. $address_id = $data['address_id'];
  511. $goods_id = $data['goods_id'];
  512. $need_optionc = $data['sku_str'];
  513. $goods_model = D('Home/Goods');
  514. //寻找现在是否有未完成的订单,如果有的话,那么就不要继续生成了
  515. $goods_info = M('goods')->field('image,name')->where( array('goods_id' => $goods_id) )->find();
  516. $bargain_goods_info = M('bargain_goods')->where( array('goods_id' => $goods_id) )->find();
  517. //pin_count,pin_hour,
  518. //pin_price
  519. $now_time = time();
  520. $old_zan_order = M('bargain_order')->where("member_id={$member_id} and goods_id={$goods_id} and state =0 and begin_time < {$now_time} and end_time > {$now_time}")->find();
  521. if( !empty($old_zan_order) )
  522. {
  523. //一个会员当前一个商品 只能发出去一个二维码
  524. echo json_encode( array('code' => 0, 'id' => $old_zan_order['id']) );
  525. die();
  526. }
  527. //zan_order
  528. $zan_order_data = array();
  529. $zan_order_data['member_id'] = $member_id;
  530. $zan_order_data['goods_id'] = $goods_id;
  531. $zan_order_data['sku_str'] = $need_optionc;
  532. $zan_order_data['state'] = 0;
  533. $price = $bargain_goods_info['bargain_price'];
  534. //goods_option_mult_value
  535. if( !empty($need_optionc) )
  536. {
  537. $goods_option_mult_value = M('goods_option_mult_value')->where( array('rela_goodsoption_valueid' => $need_optionc,'goods_id' =>$goods_id) )->find();
  538. if(!empty($goods_option_mult_value))
  539. {
  540. $price = $goods_option_mult_value['pin_price'];
  541. }
  542. }
  543. $zan_order_data['need_person'] = empty($bargain_goods_info['bargain_count']) ? 1: $bargain_goods_info['bargain_count'];
  544. $zan_order_data['total_person'] = empty($bargain_goods_info['bargain_count']) ? 1: $bargain_goods_info['bargain_count'];
  545. $zan_order_data['deal_money'] = $price;
  546. $zan_order_data['total_money'] = $price;
  547. $zan_order_data['begin_time'] = $now_time;
  548. $zan_order_data['end_time'] = $now_time + 3600 * $bargain_goods_info['hour'];
  549. $zan_order_data['add_time'] = time();
  550. $zan_order_data['order_id'] = 0;
  551. $zan_order_data['address_id'] = $address_id;
  552. $zan_order_id = M('bargain_order')->add($zan_order_data);
  553. //bargain_order_detail
  554. //member_id kan_money bargain_order_id addtime avatar nickname
  555. $state = $this->_bang_kan_order($zan_order_id,$member_id,true);
  556. echo json_encode( array('code' =>0, 'id' => $zan_order_id) );
  557. die();
  558. }
  559. /**
  560. 开始砍价表
  561. **/
  562. private function _bang_kan_order($bargain_order_id,$member_id,$is_self = false, $just_update = false )
  563. {
  564. //检测是否砍过了
  565. $has_order = M('bargain_order_detail')->where( array('member_id'=>$member_id, 'bargain_order_id' =>$bargain_order_id) )->find();
  566. if(!empty($has_order) && !$just_update)
  567. {
  568. return 1;//已经帮忙砍过
  569. }
  570. //活动是否正常
  571. $bargain_order_info = M('bargain_order')->where( array('id' => $bargain_order_id) )->find();
  572. if( $bargain_order_info['state'] != 0 )
  573. {
  574. return 2; //活动已经成功,或者已经结束
  575. }
  576. $now_time = strtotime( date('Y-m-d').' 00:00:00' );
  577. $end_time = $now_time + 86400;
  578. $kan_person_count = C('kan_person_count');
  579. if(!$is_self)
  580. {
  581. //检测今天帮别人砍价的次数
  582. //addtime
  583. //bargain_order_detail
  584. $kan_count = M('bargain_order_detail')->where( array('addtime' =>array('between', array($now_time,$end_time) ), 'member_id'=>$member_id,'is_sleft' =>0 ) )->count();
  585. //$condition['id'] = array(between,array('1','8'));
  586. if($kan_person_count >0 && $kan_count >= $kan_person_count)
  587. {
  588. return 3;//今天已经不能再帮别人砍价
  589. }
  590. }
  591. //开始砍价流程
  592. if($bargain_order_info['need_person'] > 0)
  593. {
  594. $per_money = $bargain_order_info['deal_money'] / $bargain_order_info['need_person'];
  595. if($bargain_order_info['need_person'] >2)
  596. {
  597. $per_money = $per_money * 2;
  598. }
  599. }else{
  600. $per_money = round($bargain_order_info['deal_money'] ,2);
  601. }
  602. $min = 1;
  603. $max = $per_money * 100;
  604. $ran_money = round( mt_rand($min,$max) / 100 , 2) ;
  605. if($bargain_order_info['need_person'] < 0)
  606. {
  607. $win_rd = mt_rand(1,9);
  608. if($win_rd >=5)
  609. {
  610. $ran_money = $bargain_order_info['deal_money'];
  611. }
  612. }
  613. $member_info = M('member')->field('uname,avatar,we_openid')->where( array('member_id' => $member_id) )->find();
  614. //TODO 插入砍价详细订单
  615. if($just_update)
  616. {
  617. $res = M('bargain_order_detail')->where( array('bargain_order_id' => $bargain_order_id,'member_id' =>$member_id ) )->setInc('kan_money',$ran_money);
  618. //setInc
  619. M('bargain_order')->where( array('id' => $bargain_order_id) )->save( array('is_share' => 1) );
  620. } else{
  621. $ins_data = array();
  622. $ins_data['member_id'] = $member_id;
  623. $ins_data['kan_money'] = $ran_money;
  624. $ins_data['bargain_order_id'] = $bargain_order_id;
  625. $ins_data['addtime'] = time();
  626. $ins_data['is_sleft'] = $is_self ? 1: 0;
  627. $ins_data['avatar'] = $member_info['avatar'];
  628. $ins_data['nickname'] = $member_info['uname'];
  629. $res = M('bargain_order_detail')->add($ins_data);
  630. }
  631. if($res)
  632. {
  633. if(!$just_update)
  634. {
  635. M('bargain_order')->where( array('id' => $bargain_order_id) )->setDec('need_person',1);
  636. }
  637. M('bargain_order')->where( array('id' => $bargain_order_id) )->setDec('deal_money',$ran_money);
  638. $bargain_order_info = M('bargain_order')->where( array('id' => $bargain_order_id) )->find();
  639. if($bargain_order_info['deal_money'] <=0 )
  640. {
  641. //TODO send msg
  642. $model = D('Home/Goods');
  643. $order_id = $model->_zan_bargain_order($bargain_order_id);
  644. //M('zan_order')->where( array('id' => $zan_order_id) )->save( array('order_id' => $order_id,'state' => 1) );
  645. M('bargain_order')->where( array('id' => $bargain_order_id) )->save( array('order_id' => $order_id,'state' => 1) );
  646. //add order
  647. $or_member_info = M('member')->field('openid,we_openid')->where( array('member_id' => $bargain_order_info['member_id']) )->find();
  648. $or_open_id = $or_member_info['we_openid'];
  649. //$or_open_id = 'o0n_HwcGIfwf5b8PN8-gmNfsJBLA';
  650. $goods_info = M('goods')->field('name')->where( array('goods_id' => $bargain_order_info['goods_id']) )->find();
  651. //转小程序模板消息
  652. /**
  653. 5zZUGZhK46PzcJeAIidv_cdsJ6OaCCXe0PtGen0yvOA
  654. 复制
  655. 标题
  656. 砍价成功通知
  657. 关键词
  658. 商品名称
  659. {{keyword1.DATA}}
  660. 砍价状态
  661. {{keyword2.DATA}}
  662. 备注
  663. {{keyword3.DATA}}
  664. **/
  665. $first_title = "您参与:".$goods_info['name'];
  666. $keyword1 = '您的活动已砍价成功';
  667. $url = C('SITE_URL')."/index.php?s=/Order/info/id/{$order_id}.html";
  668. $template_data['keyword1'] = array('value' => $first_title, 'color' => '#030303');
  669. $template_data['keyword2'] = array('value' => '砍价成功', 'color' => '#030303');
  670. $template_data['keyword3'] = array('value' => '当前活动已成功,等待发货', 'color' => '#030303');
  671. $pay_order_msg_info = M('config')->where( array('name' => 'weprogram_template_kan_msg') )->find();
  672. $template_id = $pay_order_msg_info['value'];
  673. $pagepath = 'pages/order/order?id='.$order_id;
  674. $member_formid_info = M('member_formid')->where( array('member_id' => $bargain_order_info['member_id'], 'formid' =>array('neq',''),'state' => 0) )->order('id desc')->find();
  675. if( !empty($member_formid_info) )
  676. {
  677. $rs = send_wxtemplate_msg($template_data,$url,$pagepath,$or_open_id,$template_id,$member_formid_info['formid']);
  678. //更新
  679. M('member_formid')->where( array('id' => $member_formid_info['id']) )->save( array('state' => 1) );
  680. }
  681. }
  682. return 0;
  683. }else{
  684. return 4;//砍价失败
  685. }
  686. }
  687. public function get_category_keyword_goods()
  688. {
  689. $pre_page = 10;
  690. $page = I('get.page',1);
  691. $keyword = I('get.keyword','');
  692. $sort = I('get.sort', 'desc');
  693. $cur_type = I('get.cur_type','default');//default seller_count price
  694. $cur_price_index = I('get.cur_price_index',0);
  695. $search_min_price = I('get.search_min_price',0);
  696. $search_max_price = I('get.search_max_price',0);
  697. $goods_model = D('Home/Goods');
  698. $condition = array('name' => array('like','%'.$keyword.'%'), 'status'=>1,'quantity' =>array('gt',0) );
  699. $condition['type'] = array('NEQ','assistance');//'normal';
  700. $orderby = "seller_count {$sort},goods_id {$sort}";
  701. if($cur_type == 'seller_count')
  702. {
  703. $orderby = "seller_count+virtual_count desc";
  704. }else if($cur_type == 'price'){
  705. $orderby = "danprice {$sort}";
  706. }
  707. if($cur_price_index > 0)
  708. {
  709. if($search_min_price > 0 && $search_max_price > 0)
  710. {
  711. //$sql['jobSalary'] = array('between','0,1000');
  712. $condition['danprice'] = array('between',"{$search_min_price},{$search_max_price}");
  713. }else if($search_min_price > 0)
  714. {
  715. //'quantity' =>array('gt',0)
  716. $condition['danprice'] = array('egt', $search_min_price);
  717. } else if($search_max_price > 0){
  718. $condition['danprice'] = array('elt', $search_max_price);
  719. }
  720. //$search_min_price = I('get.search_min_price');
  721. //$search_max_price = I('get.search_max_price');
  722. }
  723. //$condition['lock_type'] = 'normal';
  724. $offset = ($page -1) * $pre_page;
  725. $list = M('goods')->where($condition)->order($orderby)->limit($offset,$pre_page)->select();
  726. if(!empty($list)) {
  727. foreach($list as $key => $v){
  728. $goods_price_arr = $goods_model->get_goods_price($v['goods_id']);
  729. $list[$key]['pinprice'] = $goods_price_arr['price'];
  730. $list[$key]['image']=C('SITE_URL'). resize($v['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  731. }
  732. }
  733. foreach($list as $key => $val)
  734. {
  735. $val['seller_count'] += $val['virtual_count'];
  736. $list[$key] = $val;
  737. }
  738. if( !empty($list) )
  739. {
  740. echo json_encode( array('code' => 0, 'data' => $list ) );
  741. die();
  742. } else {
  743. echo json_encode( array('code' => 1) );
  744. die();
  745. }
  746. }
  747. public function get_goods_fujin_tuan()
  748. {
  749. $id = I('get.id');
  750. $count = I('get.count',2);
  751. $pin_model = D('Home/Pin');
  752. //正在进行中的商品团
  753. $fujin_tuan = $pin_model->get_goods_pintuan($id,$count);
  754. $fujin_list = $fujin_tuan['list'];
  755. echo json_encode( array('code' => 0, 'cur_time' => time(), 'data' => $fujin_list) );
  756. die();
  757. //$this->fujin_tuan = $fujin_tuan;
  758. }
  759. public function upload_image(){
  760. $dir=I('get.dir','goods');
  761. $dir .= '/'.date('Y-m-d');
  762. //$this->del_old_image();
  763. $upload = new \Think\Upload();// 实例化上传类
  764. $image_dir=ROOT_PATH.'Uploads/image/'.$dir;
  765. RecursiveMkdir($image_dir);
  766. $upload->autoSub = false;
  767. $upload->maxSize = 3145728 ;// 设置附件上传大小
  768. $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
  769. $upload->rootPath = $image_dir.'/';
  770. $info = $upload->upload();
  771. if(!$info) {
  772. $data['result'] = false;
  773. $this->ajaxReturn($data);
  774. }else{// 上传成功
  775. //{"image_thumb":"Uploads\/image\/cache\/goods\/2017-11-01\/59f9460eac183-100x100.jpg",
  776. //"image":"goods\/2017-11-01\/59f9460eac183.jpg"}
  777. $filename=$dir.'/'.$info['file']['savepath'].$info['file']['savename'];
  778. $data['image_thumb'] = C('SITE_URL').resize($filename, 300, 300);
  779. $data['image'] = C('SITE_URL').'Uploads/image/'.$filename;
  780. $data['image_o'] = $filename;
  781. $this->ajaxReturn($data);
  782. }
  783. }
  784. public function get_goods_simple() {
  785. $id = I('get.id');
  786. $goods_info = M('goods')->where( array('goods_id' => $id) )->find();
  787. $goods_info['image'] = C('SITE_URL') . resize($goods_info['image'], 400 , 400);
  788. if ($goods[0]['type'] == 'pintuan' || $goods[0]['type'] == 'lottery') {
  789. $pin_info = M('pin_goods')->where(array(
  790. 'goods_id' => $id
  791. ))->find();
  792. }
  793. $need_data = array();
  794. $need_data['goods_id'] = $id;
  795. $need_data['name'] = $goods_info['name'];
  796. $need_data['price'] = empty($pin_info) ? $goods_info['danprice'] : $pin_info['pin_price'];
  797. $need_data['image'] = $goods_info['image'];
  798. echo json_encode( array('code' =>0, 'data' => $need_data) );
  799. die();
  800. }
  801. public function get_goods_detail() {
  802. die();
  803. }
  804. /**
  805. 商品评价
  806. **/
  807. public function comment_info()
  808. {
  809. $goods_id = I('get.goods_id',0);
  810. $token = I('get.token');
  811. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  812. $member_id = $weprogram_token['member_id'];
  813. $result = array('code' =>0);
  814. if( empty($member_id))
  815. {
  816. $result['msg'] = '未登录';
  817. echo json_encode($result);
  818. die();
  819. }
  820. $goods_info = M('goods')->where( array('goods_id' => $goods_id ) )->find();
  821. if(empty($goods_info)) {
  822. $result['msg'] = '没有此商品';
  823. echo json_encode($result);
  824. die();
  825. }
  826. $page = I('get.page',1);
  827. $per_page = I('get.per_page',10);
  828. // $per_page = 4;
  829. $offset = ($page - 1) * $per_page;
  830. $sql = "select o.*,m.name as name2,m.avatar as avatar2 from ".C('DB_PREFIX')."order_comment as o left join ".C('DB_PREFIX')."member as m on o.member_id=m.member_id
  831. where o.state =1 and o.goods_id = {$goods_id} order by o.add_time desc limit {$offset},{$per_page}";
  832. $list=M()->query($sql);
  833. foreach($list as $key => $val)
  834. {
  835. if( empty($val['user_name']) )
  836. {
  837. $val['name'] = $val['name2'];
  838. $val['avatar'] = $val['avatar2'];
  839. }else{
  840. $val['name'] = $val['user_name'];
  841. }
  842. if($val['type'] == 0)
  843. {
  844. $order_goods_info = M('order_goods')->field('order_goods_id')->where( array('order_id' => $val['order_id'],'goods_id' => $id) )->find();
  845. $order_option_info = M('order_option')->field('value')->where( array('order_id' =>$val['order_id'],'order_goods_id' => $order_goods_info['order_goods_id']) )->select();
  846. $option_arr = array();
  847. foreach($order_option_info as $option)
  848. {
  849. $option_arr[] = $option['value'];
  850. }
  851. $option_str = implode(',', $option_arr);
  852. }else{
  853. $option_str = '';
  854. }
  855. if( !empty($val['images']) )
  856. {
  857. $img_list = unserialize($val['images']);
  858. if(!empty($img_list))
  859. {
  860. $need_img_list = array();
  861. foreach($img_list as $kk => $vv)
  862. {
  863. if( empty($vv) )
  864. {
  865. continue;
  866. }
  867. $vv = C('SITE_URL'). resize($vv, C('goods_thumb_width'), C('goods_thumb_height'));
  868. $img_list[$kk] = $vv;
  869. $need_img_list[$kk] = $vv;
  870. }
  871. $val['images'] = $need_img_list;
  872. }else{
  873. $val['images'] = array();
  874. }
  875. }
  876. //<view class="time span">{{item.addtime}}</view>
  877. // <view class="style span">{{item.option_str}} </view>
  878. $val['add_time'] = date('Y-m-d', $val['add_time']) ;
  879. $val['option_str'] = $option_str;
  880. $list[$key] = $val;
  881. }
  882. $result = array();
  883. $result['code'] = 1;
  884. $result['list'] = $list;
  885. echo json_encode($result);
  886. die();
  887. }
  888. public function get_lottery_info()
  889. {
  890. ///goods_id/30
  891. $goods_id = I('get.goods_id',0);
  892. // $goods_info = M('goods')->where( array('goods_id' => $goods_id,'type' => 'lottery') )->find();
  893. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  894. $pin_goods = M('pin_goods')->where( array('goods_id' => $goods_id) )->find();
  895. if(empty($goods_info)) {
  896. die('非法操作');
  897. }
  898. $page = I('get.page',1);
  899. $per_page = I('get.per_page',4);
  900. $per_page = 1000;
  901. $offset = ($page - 1) * $per_page;
  902. $goods_info['image'] = C('SITE_URL').resize($goods_info['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  903. $sql = "select m.avatar,m.uname,o.order_num_alias,o.shipping_tel from ".C('DB_PREFIX')."order as o ,".C('DB_PREFIX')."order_goods as og,".C('DB_PREFIX')."member as m
  904. where o.lottery_win = 1 and o.order_id = og.order_id and og.goods_id and o.member_id = m.member_id and og.goods_id = {$goods_id} and o.date_added > ".$pin_goods['begin_time']." order by o.order_id asc limit {$offset},{$per_page}";
  905. //begin_time
  906. $this->goods_info = $goods_info;
  907. $list=M()->query($sql);
  908. $count_sql = "select count(o.order_num_alias) as count from ".C('DB_PREFIX')."order as o ,".C('DB_PREFIX')."order_goods as og,".C('DB_PREFIX')."member as m
  909. where o.lottery_win = 1 and o.order_id = og.order_id and og.goods_id and o.member_id = m.member_id and og.goods_id = {$goods_id} ";
  910. $count=M()->query($count_sql);
  911. $count = $count[0]['count'];
  912. $max_page = ceil($count / $per_page);
  913. $this->pin_goods = $pin_goods;
  914. $this->list = $list;
  915. $this->goods_id = $goods_id;
  916. //if(empty($list)) {
  917. // $jia_page = $page - $max_page;
  918. // $offset = ($jia_page - 1) * $per_page;
  919. $sql = "select avatar,uname,order_sn as order_num_alias,mobile as shipping_tel from
  920. ".C('DB_PREFIX')."jiaorder
  921. where goods_id = {$goods_id} and addtime > ".$pin_goods['begin_time']." order by id asc limit {$offset},{$per_page}";
  922. // where goods_id = {$goods_id} order by id asc limit {$offset},{$per_page}";
  923. $lists=M()->query($sql);
  924. foreach($lists as $vv)
  925. {
  926. $list[] = $vv;
  927. }
  928. // $this->list = $list;
  929. // }
  930. if(!empty($list))
  931. {
  932. foreach($list as $key => $val)
  933. {
  934. $list[$key]['shipping_tel'] = substr($val['shipping_tel'],0,3)."*****".substr($val['shipping_tel'],-3,3);
  935. }
  936. $need_data = array();
  937. $need_data['code'] = 0;
  938. $need_data['goods_info'] = $goods_info;
  939. $need_data['pin_goods'] = $pin_goods;
  940. $need_data['data'] = $list;
  941. }else {
  942. $need_data = array();
  943. $need_data['code'] = 0;
  944. $need_data['goods_info'] = $goods_info;
  945. $need_data['pin_goods'] = $pin_goods;
  946. $need_data['data'] = $list;
  947. }
  948. echo json_encode($need_data);
  949. die();
  950. }
  951. function get_subcategory()
  952. {
  953. // /id/'+cur_pid
  954. $cate_id = I('get.id',0);
  955. $level = 0;
  956. $cur_cate_name = '';
  957. //name
  958. if($cate_id > 0)
  959. {
  960. $parinfo = M('goods_category')->where( array('id' => $cate_id) )->find();
  961. $cur_cate_name = $parinfo['name'];
  962. if($parinfo['pid'] > 0)
  963. {
  964. $level = 2;
  965. }
  966. }
  967. $goods_category_list = M('goods_category')->where( array('pid' => $cate_id) )->order('sort_order desc, id asc')->select();
  968. foreach($goods_category_list as $key => $val)
  969. {
  970. $val['logo'] = C('SITE_URL').'Uploads/image/'.$val['logo'];
  971. $goods_category_list[$key] = $val;
  972. }
  973. if(!empty($goods_category_list))
  974. {
  975. echo json_encode( array('code' => 0,'level' => $level, 'cur_cate_name' => $cur_cate_name,'data' => $goods_category_list) );
  976. die();
  977. } else{
  978. echo json_encode( array('code' => 1,'level' => $level,'cur_cate_name' => $cur_cate_name) );
  979. die();
  980. }
  981. }
  982. /**
  983. 获得商户优惠券
  984. **/
  985. public function get_seller_quan()
  986. {
  987. $seller_id = I('get.store_id',1);
  988. $where = "";
  989. $where = "total_count>send_count and store_id ={$seller_id} and is_index_show=1 and end_time>".time();
  990. $quan_list = M('voucher')->where($where)->order('add_time desc')->limit(4)->select();
  991. echo json_encode( array('code' => 0, 'quan_list' => $quan_list) );
  992. die();
  993. }
  994. public function seller_info()
  995. {
  996. $seller_id = I('get.id',0);
  997. //s_true_name s_logo
  998. $seller_info = M('seller')->field('s_true_name,s_logo,s_banner')->where( array('s_id' => $seller_id) )->find();
  999. $seller_info['s_logo'] = C('SITE_URL').'Uploads/image/'.$seller_info['s_logo'];
  1000. if( empty($seller_info['s_banner']) )
  1001. {
  1002. $seller_info['s_banner'] = C('SITE_URL').'Common/mogu/image/170923_1bk3970j2eb9jia57aa8k3i661ck5_750x270.jpg';
  1003. } else{
  1004. $seller_info['s_banner'] = C('SITE_URL').'Uploads/image/'.$seller_info['s_banner'];
  1005. }
  1006. //s_banner
  1007. $seller_model = D('Home/Seller');
  1008. $seller_count = $seller_model->getStoreSellerCount($seller_id);
  1009. $goods_count = M('goods')->where( array('store_id' => $seller_id) )->count();
  1010. $seller_info['seller_count'] = $seller_count;
  1011. $seller_info['goods_count'] = $goods_count;
  1012. //$this->goods_count = $goods_count;
  1013. //$this->seller_count = $seller_count;
  1014. $store_class_list = M('store_bind_class')->where( array('seller_id' => $seller_id) )->order('bid asc')->select();
  1015. $store_class_ids = array();
  1016. foreach($store_class_list as $class_val)
  1017. {
  1018. $store_class_ids[] = $class_val['class_1'];
  1019. }
  1020. $category_list = array();
  1021. if( !empty($store_class_ids) )
  1022. {
  1023. $category_list = M('goods_category')->field('id,name,logo')->where( array('id' => array('in', $store_class_ids) ) )->select();
  1024. foreach($category_list as $key => $val)
  1025. {
  1026. $val['logo'] = C('SITE_URL').'Uploads/image/'.$val['logo'];
  1027. $category_list[$key] = $val;
  1028. }
  1029. }
  1030. //["name"]=> string(12) "食品食品" ["logo"]=>
  1031. //$this->category_list = $category_list;
  1032. $fans_count = M('user_favstore')->where( array('store_id' => $seller_id) )->count();
  1033. $seller_info['fans_count'] = $fans_count;
  1034. $seller_info['category_list'] = $category_list;
  1035. $where = "";
  1036. $where = "total_count>send_count and store_id ={$seller_id} and is_index_show=1 and end_time>".time();
  1037. $quan_list = M('voucher')->where($where)->order('add_time desc')->limit(4)->select();
  1038. $seller_info['quan_list'] = $quan_list;
  1039. //$this->quan_list = $quan_list;
  1040. echo json_encode( array('code' =>0, 'data' => $seller_info) );
  1041. die();
  1042. }
  1043. public function getQuan()
  1044. {
  1045. $token = I('get.token');
  1046. //user_favgoods
  1047. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  1048. $member_id = $weprogram_token['member_id'];
  1049. $data_json = file_get_contents('php://input');
  1050. $data = json_decode($data_json, true);
  1051. $result = array('code' => 0,'msg' => '被抢光啦');
  1052. $quan_id = $data['quan_id'];
  1053. if($quan_id >0){
  1054. $quan_model = D('Home/Voucher');
  1055. $res = $quan_model->send_user_voucher_byId($quan_id,$member_id,true);
  1056. //1 被抢光了 2 已领过 3 领取成功
  1057. $mes_arr = array(1 => '被抢光了',2 => '已领过', 3 => '领取成功');
  1058. $result['code'] = $res;
  1059. $result['msg'] = $mes_arr[$res];
  1060. }
  1061. echo json_encode($result);
  1062. die();
  1063. }
  1064. public function notify_order()
  1065. {
  1066. //$map['id'] = array('neq',100);
  1067. $notify_order = M('notify_order')->where( array('state' => array('lt', 1)) )->order('state asc,id asc')->find();
  1068. //username
  1069. $result = array('ret' => 0);
  1070. if(empty($notify_order))
  1071. {
  1072. echo json_encode($result);
  1073. die();
  1074. }
  1075. M('notify_order')->where( array('id' => $notify_order['id']) )->setInc('state', 1);
  1076. $miao = (time() -$notify_order['order_time']) % 60;
  1077. $result['ret'] = 1;
  1078. $result['username'] = $notify_order['username'];
  1079. $result['avatar'] = $notify_order['avatar'];
  1080. $result['order_id'] = $notify_order['order_id'];
  1081. $result['order_url'] = $notify_order['order_url'];
  1082. $result['miao'] = $miao;
  1083. //->save( array('state' => 1) );
  1084. echo json_encode($result);
  1085. die();
  1086. }
  1087. public function seller_goods_list()
  1088. {
  1089. $pre_page = I('get.pre_page',2);
  1090. $page = I('get.page',1);
  1091. $seller_id = I('get.seller_id',0);
  1092. $gid = I('get.gid',0);
  1093. $keyword = I('get.keyword','');
  1094. $order_by = I('get.order_by','default');
  1095. switch($order_by)
  1096. {
  1097. case 'default':
  1098. $order_by = 'sort_order asc';
  1099. break;
  1100. case 'hot':
  1101. $order_by = 'seller_count desc';
  1102. break;
  1103. case 'new':
  1104. $order_by = 'goods_id desc';
  1105. break;
  1106. }
  1107. $where = " and (g.type='pintuan' or g.type='lottery') and g.store_id = {$seller_id} and g.status =1 and g.quantity > 0 ";
  1108. $offset = ($page -1) * $pre_page;
  1109. if( $gid > 0)
  1110. {
  1111. $where .= " and (gt.class_id1 = {$gid} or gt.class_id2 = {$gid} or gt.class_id3 = {$gid}) ";
  1112. }
  1113. if( !empty($keyword) )
  1114. {
  1115. $where .= " and g.name like '%{$keyword}%' ";
  1116. }
  1117. $sql = "select g.* from ".C('DB_PREFIX')."goods as g ,".C('DB_PREFIX')."goods_to_category as gt
  1118. where g.goods_id = gt.goods_id {$where} order by {$order_by} limit {$offset},{$pre_page} ";
  1119. $list = M()->query($sql);
  1120. $goods_data = array();
  1121. if(!empty($list)) {
  1122. foreach($list as $key => $v){
  1123. //$list[$key]['seller_count'] += $v['virtual_count'];
  1124. $tmp_goods = array();
  1125. $tmp_goods['goods_id'] = $v['goods_id'];
  1126. $tmp_goods['name'] = $v['name'];
  1127. $tmp_goods['quantity'] = $v['quantity'];
  1128. $tmp_goods['image'] = C('SITE_URL').'Uploads/image/' .$v['image'];
  1129. $tmp_goods['price'] = $v['price'];
  1130. $tmp_goods['danprice'] = $v['danprice'];
  1131. $tmp_goods['seller_count'] = $v['seller_count']+$v['virtual_count'];
  1132. $tmp_goods['fav_count'] = M('user_favgoods')->where( array('goods_id' => $v['goods_id']) ) ->count();
  1133. $goods_data[] = $tmp_goods;
  1134. //$list[$key]['image']=resize($v['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  1135. }
  1136. }
  1137. if( empty($goods_data) )
  1138. {
  1139. echo json_encode( array('code' => 1) );
  1140. die();
  1141. } else {
  1142. echo json_encode( array('code' => 0, 'data' => $goods_data) );
  1143. die();
  1144. }
  1145. }
  1146. }