SellerController.class.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Home\Controller;
  15. class SellerController extends CommonController {
  16. public function info(){
  17. $pre_page = 10;
  18. $page = I('post.page',1);
  19. $seller_id = I('get.seller_id',0);
  20. $is_ajax = I('post.is_ajax',0);
  21. $gid = I('post.gid',0);
  22. $order_by = I('post.order_by','default');
  23. if(empty($seller_id))
  24. {
  25. $seller_id = I('post.seller_id',0);
  26. }
  27. switch($order_by)
  28. {
  29. case 'default':
  30. $order_by = 'sort_order asc';
  31. break;
  32. case 'hot':
  33. $order_by = 'seller_count desc';
  34. break;
  35. case 'new':
  36. $order_by = 'goods_id desc';
  37. break;
  38. case 'price':
  39. $order_by = 'danprice asc';
  40. break;
  41. }
  42. //default hot new
  43. $where = " and g.store_id = {$seller_id} and g.status =1 and g.quantity > 0 ";
  44. //$condition = array('store_id' => $seller_id, 'status'=>1,'quantity' =>array('gt',0) );
  45. $offset = ($page -1) * $pre_page;
  46. //$list = M('goods')->where($condition)->order($order_by)->limit($offset,$pre_page)->select();
  47. //goods_to_category
  48. if( $gid > 0)
  49. {
  50. $where .= " and (gt.class_id1 = {$gid} or gt.class_id2 = {$gid} or gt.class_id3 = {$gid}) ";
  51. }
  52. $sql = "select g.* from ".C('DB_PREFIX')."goods as g ,".C('DB_PREFIX')."goods_to_category as gt
  53. where g.goods_id = gt.goods_id {$where} order by {$order_by} limit {$offset},{$pre_page} ";
  54. $list = M()->query($sql);
  55. $goods_model = D('Home/Goods');
  56. if(!empty($list)) {
  57. foreach($list as $key => $v){
  58. $list[$key]['seller_count'] += $v['virtual_count'];
  59. $price_arr = $goods_model->get_goods_price($v['goods_id']);
  60. $list[$key]['danprice'] = $price_arr['danprice'];
  61. if(empty($v['fan_image'])){
  62. $list[$key]['image']=resize($v['fan_image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  63. }else{
  64. $list[$key]['image']=resize($v['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  65. }
  66. }
  67. }
  68. $this->list = $list;
  69. $this->seller_id = $seller_id;
  70. $seller_info = M('seller')->where( array('s_id' => $seller_id) )->find();
  71. $this->seller_info = $seller_info;
  72. $where = "total_count>send_count and store_id ={$seller_id} and is_index_show=1 and end_time>".time();
  73. $quan_list = M('voucher')->where($where)->order('add_time desc')->limit(5)->select();
  74. $this->quan_list = $quan_list;
  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, 'status' => 1) )->count();
  78. $this->goods_count = $goods_count;
  79. $this->seller_count = $seller_count;
  80. $store_class_list = M('store_bind_class')->where( array('seller_id' => $seller_id) )->order('bid asc')->select();
  81. $store_class_ids = array();
  82. foreach($store_class_list as $class_val)
  83. {
  84. $store_class_ids[] = $class_val['class_1'];
  85. }
  86. $category_list = array();
  87. if( !empty($store_class_ids) )
  88. {
  89. //$store_class_ids_str = implode(',', $store_class_ids);
  90. $category_list = M('goods_category')->where( array('id' => array('in', $store_class_ids) ) )->select();
  91. //var_dump($category_list);die();
  92. }
  93. $this->category_list = $category_list;
  94. if($page > 1 || $is_ajax == 1) {
  95. $result = array('code' => 0);
  96. if(!empty($list)) {
  97. $result['code'] = 1;
  98. $result['html'] = $this->fetch('Widget:seller_ajax_goods_list_fetch');
  99. }
  100. echo json_encode($result);
  101. die();
  102. }
  103. $goods_model = D('Home/Goods');
  104. $member_id = is_login();
  105. $fans_count = M('user_favstore')->where( array('store_id' => $seller_id) )->count();
  106. $this->fans_count = $fans_count;
  107. $is_fav_seller = $goods_model->check_store_fav($seller_id, $member_id);
  108. $goods_count = M('goods')->where( array('store_id' => $seller_id) )->count();
  109. $this->is_fav_seller = $is_fav_seller;
  110. $this->open_web_kefu = C('open_duokefu');
  111. $this->display('index');
  112. }
  113. /**
  114. 连接后台客服
  115. @param room_id 卖家id
  116. **/
  117. public function kefu_seller()
  118. {
  119. //login_data = '{"type":"login","domain":"'+domain+'","uid":"2","room_id":1}';
  120. $room_id = I('get.store_id');
  121. $goods_id = I('get.goods_id',0);
  122. $site_url_arr = M('config')->field('value')->where( array('name' => 'SITE_URL') )->find();
  123. $site_url = $site_url_arr['value'];
  124. $goods_info = array();
  125. if($goods_id >0)
  126. {
  127. $goods_info = M('goods')->field('name,type,image,danprice')->where( array('goods_id' => $goods_id) )->find();
  128. $goods_info['image']=$site_url. resize($goods_info['image'], 200, 200);
  129. $goods_info['pinprice'] = $goods_info['danprice'];
  130. //type pintuan
  131. if( $goods_info['type'] == 'pintuan' || $goods_info['type'] == 'lottery' )
  132. {
  133. $pin_goods = M('pin_goods')->where( array('goods_id' => $goods_id) )->find();
  134. $goods_info['pinprice'] = $pin_goods['pin_price'];
  135. $goods_info['pin_count'] = $pin_goods['pin_count'];
  136. }
  137. }
  138. $this->goods_info = $goods_info;
  139. $member_id = is_login();
  140. $member_info = M('member')->field('name,avatar')->where( array('member_id' => $member_id) )->find();
  141. $seller_info = M('seller')->field('s_id,s_true_name,s_logo')->where( array('s_id' => $room_id) )->find();
  142. $seller_info['s_logo'] = $site_url.'Uploads/image/'.$seller_info['s_logo'];
  143. $this->seller_info = $seller_info;
  144. $this->member_id = $member_id;
  145. $this->member_info = $member_info;
  146. $this->display();
  147. }
  148. public function pickup_pickage()
  149. {
  150. $member_id = is_login();
  151. //pick_id/2.
  152. //$member_id = is_login();
  153. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  154. $pick_member_info = M('pick_member')->where( array('member_id' => $member_id) )->find();
  155. if(empty($pick_member_info))
  156. {
  157. echo json_encode( array('code' => 0,'msg' => '您不是核销人员') );
  158. die();
  159. }
  160. $pick_id = I('get.pick_id');
  161. $pick_order = M('pick_order')->where( array('id' => $pick_id) )->find();
  162. //$pick_member_info = M('pick_member')->where( array('member_id' => $member_id) )->find();
  163. if($pick_member_info['pick_up_id'] > 0 && $pick_member_info['pick_up_id'] != $pick_order['pick_id'])
  164. {
  165. echo json_encode( array('code' => 0,'msg' => '您无此门店核销权限') );
  166. die();
  167. }
  168. //order_id pick_id
  169. $order_id = $pick_order['order_id'];
  170. $order_goods = M('order_goods')->where( array('order_id' => $pick_order['order_id']) )->find();
  171. if($order_goods['store_id'] != $pick_member_info['store_id'])
  172. {
  173. echo json_encode( array('code' => 0,'msg' => '您无此商家核销权限') );
  174. die();
  175. }
  176. $pick_id = $pick_order['id'];
  177. //$pick_id = I('get.pick_id');
  178. $pick_order = M('pick_order')->where( array('id' => $pick_id) )->find();
  179. $member_id = is_login();
  180. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  181. $result = array('code' => 1,'msg' => '');
  182. $order_goods = M('order_goods')->where( array('order_id' => $pick_order['order_id']) )->find();
  183. //pick_member_id
  184. $res = M('pick_order')->where( array('id' => $pick_id) )->save( array('pick_member_id' => $member_id, 'state' => 1, 'tihuo_time' => time()) );
  185. if($res)
  186. {
  187. M('order')->where( array('order_id' => $pick_order['order_id']) )->save( array('order_status_id' => 6) );
  188. $history_data = array();
  189. $history_data['order_id'] = $pick_order['order_id'];
  190. $history_data['order_status_id'] = 6;
  191. $history_data['notify'] = 0;
  192. $history_data['comment'] = '用户提货,核销';
  193. $history_data['date_added'] = time();
  194. M('order_history')->add($history_data);
  195. $notify_model = D('Home/Weixinnotify');
  196. $notify_model->sendPickupsuccessMsg($pick_order['order_id']);
  197. $result['code'] = 1;
  198. }
  199. echo json_encode($result);
  200. die();
  201. }
  202. public function pickup_pickage2()
  203. {
  204. $pick_id = I('get.pick_id');
  205. $pick_order = M('pick_order')->where( array('id' => $pick_id) )->find();
  206. $member_id = is_login();
  207. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  208. $result = array('code' => 0,'msg' => '');
  209. if($member_info['bind_seller_pickup'] <= 0)
  210. {
  211. $result['msg'] = '您不是核销管理员';
  212. echo json_encode($result);
  213. die();
  214. }
  215. $order_goods = M('order_goods')->where( array('order_id' => $pick_order['order_id']) )->find();
  216. if($order_goods['store_id'] != $member_info['bind_seller_pickup'])
  217. {
  218. $result['msg'] = '您不是该店铺的核销管理员';
  219. echo json_encode($result);
  220. die();
  221. }
  222. $res = M('pick_order')->where( array('id' => $pick_id) )->save( array('state' => 1, 'tihuo_time' => time()) );
  223. if($res)
  224. {
  225. M('order')->where( array('order_id' => $pick_order['order_id']) )->save( array('order_status_id' => 6) );
  226. $history_data = array();
  227. $history_data['order_id'] = $pick_order['order_id'];
  228. $history_data['order_status_id'] = 6;
  229. $history_data['notify'] = 0;
  230. $history_data['comment'] = '用户提货,核销';
  231. $history_data['date_added'] = time();
  232. M('order_history')->add($history_data);
  233. $notify_model = D('Home/Weixinnotify');
  234. $notify_model->sendPickupsuccessMsg($pick_order['order_id']);
  235. $result['code'] = 1;
  236. }
  237. echo json_encode($result);
  238. die();
  239. }
  240. public function hexiao_pickup()
  241. {
  242. $pick_sn = I('get.pick_sn');
  243. $pick_order = M('pick_order')->where( array('pick_sn' => $pick_sn) )->find();
  244. //order_id pick_id
  245. $order_id = $pick_order['order_id'];
  246. $order_goods = M('order_goods')->where( array('order_id' => $pick_order['order_id']) )->find();
  247. $order_info = M('order')->where( array('order_id' => $order_id) )->find();
  248. $order_status_info = M('order_status')->where( array('order_status_id' => $order_info['order_status_id']) )->find();
  249. $order_option_info = M('order_option')->where( array('order_id' =>$order_id,'order_goods_id' => $order_goods['goods_id']) )->select();
  250. $goods_info = M('goods')->where( array('goods_id' => $order_goods['goods_id']) )->find();
  251. $voucher_info = array();
  252. if($order_info['voucher_id'] > 0) {
  253. $voucher_info = M('voucher_list')->where( array('id' => $order_info['voucher_id']) )->find();
  254. }
  255. $goods_info['image']=resize($goods_info['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  256. $pin_model = D('Home/Pin');
  257. if($order_info['order_status_id'] == 2)
  258. {
  259. //判断拼团是否失败
  260. if($order_info['is_pin'] == 1 && $order_info['pin_id'] > 0)
  261. {
  262. $state = $pin_model->getNowPinState($order_info['pin_id']);
  263. if($state == 2){
  264. $order_status_info['name'] = '拼团失败,等待退款';
  265. }
  266. }
  267. }
  268. //判断是否抽奖订单
  269. //组团成功,等待抽奖 已成团,待抽奖 组团成功一等奖 已成团,一等奖
  270. if($order_info['order_status_id'] == 1)
  271. {
  272. //待发货订单,并且未中奖
  273. if($order_info['is_pin'] == 1 && $order_info['pin_id'] > 0 && $order_info['lottery_win'] ==0)
  274. {
  275. $pin_info = M('pin')->where( array('pin_id' =>$order_info['pin_id'] ) )->find();
  276. if($pin_info['is_lottery'] == 1)
  277. {
  278. if($pin_info['lottery_state'] == 0){
  279. $order_status_info['name'] = '已成团,待抽奖';
  280. }else if($pin_info['lottery_state'] == 1){
  281. $order_status_info['name'] = '二等奖,待退款并送券';
  282. }
  283. }
  284. }else if($order_info['is_pin'] == 1 && $order_info['pin_id'] > 0 && $order_info['lottery_win'] ==1)
  285. {
  286. $order_status_info['name'] = '一等奖,待发货';
  287. }
  288. }
  289. $pick_order_info = array();
  290. $pick_up = array();
  291. if($order_info['delivery'] == 'pickup')
  292. {
  293. $pick_order_info = M('pick_order')->where( array('order_id' => $order_info['order_id']) )->find();
  294. $pick_up = M('pick_up')->where( array('id' => $pick_order_info['pick_id']) )->find();
  295. }
  296. $this->pick_order_info = $pick_order_info;
  297. $this->pick_up = $pick_up;
  298. $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
  299. //$order_id order_id $val['hash_order_id']= $hashids->encode($val['order_id']);
  300. $order_info['hash_order_id']= $hashids->encode($order_info['order_id']);
  301. $this->order_info = $order_info;
  302. $this->order_status_info = $order_status_info;
  303. $this->shipping_province = $shipping_province;
  304. $this->shipping_city = $shipping_city;
  305. $this->shipping_country = $shipping_country;
  306. $this->order_goods = $order_goods;
  307. $this->store_info = $store_info;
  308. $this->order_option_info = $order_option_info;
  309. $this->goods_info = $goods_info;
  310. $this->voucher_info = $voucher_info;
  311. $this->display();
  312. }
  313. /**
  314. 绑定自提订单核销管理员
  315. **/
  316. public function bind_pickup_order()
  317. {
  318. $seller_id = I('get.seller_id');
  319. $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
  320. $seller_arr=$hashids->decode($seller_id);
  321. $seller_id = $seller_arr[0];
  322. $pick_up_id = I('get.pick_up_id',0);
  323. $pick_up_info = array();
  324. if( $pick_up_id > 0 )
  325. {
  326. //id
  327. $pick_up_info = M('pick_up')->where( array('id' => $pick_up_id,'store_id' => $seller_id) )->find();
  328. }
  329. $this->pick_up_info = $pick_up_info;
  330. $this->pick_up_id = $pick_up_id;
  331. $this->seller_id = $seller_id;
  332. $this->display();
  333. }
  334. /**
  335. 解除绑定自提订单核销管理员
  336. **/
  337. public function unbind_pickup_order()
  338. {
  339. $seller_id = get_url_id('seller_id');
  340. $member_id = is_login();
  341. $data = array();
  342. $data['bind_seller_pickup'] = 0;
  343. $res = M('member')->where( array('member_id' => $member_id) )->save($data);
  344. $this->display();
  345. }
  346. public function bind_pickup_post()
  347. {
  348. $seller_id = I('get.seller_id');
  349. $pick_up_id = I('get.pick_up_id',0);
  350. $member_id = is_login();
  351. //'pick_up_id' =>$pick_up_id
  352. //$data = array();
  353. //$data['bind_seller_pickup'] = $seller_id;
  354. $pick_member_info = M('pick_member')->where( array('member_id' =>$member_id) )->find();
  355. $data = array();
  356. $data['member_id'] = $member_id;
  357. $data['pick_up_id'] = $pick_up_id;
  358. $data['state'] = 1;
  359. $data['store_id'] = $seller_id;
  360. $data['addtime'] = time();
  361. if( !empty($pick_member_info) )
  362. {
  363. $res = M('pick_member')->where( array('member_id' =>$member_id) )->save($data);
  364. }else{
  365. $res = M('pick_member')->where( array('member_id' =>$member_id) )->add($data);
  366. }
  367. //$res = M('member')->where( array('member_id' => $member_id) )->save($data);
  368. $result = array('code' => 100,'msg' => '绑定失败');
  369. if($res) {
  370. $result['code'] = 200;
  371. }
  372. echo json_encode($result);
  373. die();
  374. }
  375. /**
  376. * 绑定发送消息管理员
  377. */
  378. public function bind_order_notify()
  379. {
  380. $seller_id = get_url_id('seller_id');
  381. $this->seller_id = $seller_id;
  382. $this->display();
  383. }
  384. /**
  385. 解除管理员消息绑定
  386. **/
  387. public function unbind_order_notify()
  388. {
  389. $seller_id = get_url_id('seller_id');
  390. $member_id = is_login();
  391. $data = array();
  392. $data['bind_seller_id'] = 0;
  393. $res = M('member')->where( array('member_id' => $member_id) )->save($data);
  394. $this->display();
  395. }
  396. public function bind_post()
  397. {
  398. $seller_id = I('get.seller_id');
  399. $member_id = is_login();
  400. $data = array();
  401. $data['bind_seller_id'] = $seller_id;
  402. $res = M('member')->where( array('member_id' => $member_id) )->save($data);
  403. $result = array('code' => 100,'msg' => '绑定失败');
  404. if($res) {
  405. $result['code'] = 200;
  406. }
  407. echo json_encode($result);
  408. die();
  409. }
  410. public function apply()
  411. {
  412. $goods_category = M('goods_category')->where( array('pid' => 0) )->select();
  413. $this->goods_category = $goods_category;
  414. $this->display();
  415. }
  416. public function apply_post()
  417. {
  418. $member_id = is_login();
  419. //result.code=='200'
  420. $result = array('code' => 0,'data'=>'');
  421. $count = M('apply')->where( array('member_id' => $member_id) )->count();
  422. $ck_apply_name = M('apply')->where( array('store_name' => I('post.businessName','','htmlspecialchars')) )->find();
  423. if(!empty($ck_apply_name))
  424. {
  425. $result['data'] = '该店铺名称已经被申请';
  426. echo json_encode($result);
  427. die();
  428. }
  429. $ck_apply_mobile = M('apply')->where( array('mobile' => I('post.managerMobile','','htmlspecialchars')) )->find();
  430. if(!empty($ck_apply_mobile))
  431. {
  432. $result['data'] = '该手机号已经申请入驻';
  433. echo json_encode($result);
  434. die();
  435. }
  436. $ckname = M('seller')->where( array('s_true_name' =>I('post.businessName','','htmlspecialchars') ) )->find();
  437. if(!empty($ckname))
  438. {
  439. $result['data'] = '该店铺名称已经存在';
  440. echo json_encode($result);
  441. die();
  442. }
  443. $ckmobile = M('seller')->where( array('s_mobile' =>I('post.managerMobile','','htmlspecialchars')) )->find();
  444. if(!empty($ckname))
  445. {
  446. $result['data'] = '该手机号已经被店铺注册';
  447. echo json_encode($result);
  448. die();
  449. }
  450. if($count >= 3)
  451. {
  452. $result['data'] = '您已申请过了!';
  453. echo json_encode($result);
  454. die();
  455. }
  456. $data = array();
  457. $data['username'] = I('post.managerName','','htmlspecialchars');
  458. $data['member_id'] = $member_id;
  459. $data['mobile'] = I('post.managerMobile','','htmlspecialchars');
  460. $data['email'] = I('post.managerEmail','','htmlspecialchars');
  461. $data['store_name'] = I('post.businessName','','htmlspecialchars');
  462. $data['city'] = I('post.businessCity','','htmlspecialchars');
  463. $data['category_id'] = I('post.businessMainCategory','','htmlspecialchars');
  464. $data['addtime'] = time();
  465. M('apply')->add($data);
  466. $result['code'] = 200;
  467. echo json_encode($result);
  468. die();
  469. }
  470. public function getQuan()
  471. {
  472. $result = array('code' => 0,'msg' => '被抢光啦');
  473. $quan_id = I('post.quan_id',0);
  474. if($quan_id >0){
  475. $quan_model = D('Home/Voucher');
  476. $res = $quan_model->send_user_voucher_byId($quan_id,is_login(),true);
  477. //1 被抢光了 2 已领过 3 领取成功
  478. $mes_arr = array(1 => '被抢光了',2 => '已领过', 3 => '领取成功');
  479. $result['msg'] = $mes_arr[$res];
  480. }
  481. echo json_encode($result);
  482. die();
  483. }
  484. }