PickupController.class.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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 Seller\Model\PickupModel;
  16. use Admin\Model\OrderModel;
  17. class PickupController extends CommonController{
  18. protected function _initialize(){
  19. parent::_initialize();
  20. $this->breadcrumb1='自提管理';
  21. $this->breadcrumb2='自提管理';
  22. }
  23. public function manage()
  24. {
  25. $model=new OrderModel();
  26. $filter=I('get.');
  27. $order_status_id = I('get.order_status_id', 0);
  28. $search=array('store_id' => SELLERUID);
  29. $search['delivery'] = 'pickup';
  30. if(isset($filter['order_num'])){
  31. $search['order_num']=$filter['order_num'];
  32. }
  33. if(isset($filter['user_name'])){
  34. $search['user_name']=$filter['user_name'];
  35. }
  36. if(isset($filter['order_status_id']) && $filter['order_status_id'] > 0){
  37. $search['order_status_id']=$filter['order_status_id'];
  38. }
  39. if(isset($filter['status']) && $filter['status'] != 0){
  40. $search['status']=$filter['status'];
  41. $this->get_status=$search['status'];
  42. }
  43. $post_data = array();
  44. if(IS_POST){
  45. $post_data = I('post.');
  46. //order_num_alias
  47. if(isset($post_data['order_num_alias']) && !empty($post_data['order_num_alias']))
  48. {
  49. $search['order_num'] = $post_data['order_num_alias'];
  50. }
  51. //member_id
  52. if(isset($post_data['member_id']) && !empty($post_data['member_id']))
  53. {
  54. $search['member_id'] = $post_data['member_id'];
  55. }
  56. if(isset($post_data['shipping_name']) && !empty($post_data['shipping_name']))
  57. {
  58. $search['shipping_name'] = $post_data['shipping_name'];
  59. }
  60. if(isset($post_data['telephone']) && !empty($post_data['telephone']))
  61. {
  62. $search['telephone'] = $post_data['telephone'];
  63. }
  64. //name
  65. if(isset($post_data['name']) && !empty($post_data['name']))
  66. {
  67. $search['user_name'] = $post_data['name'];
  68. }
  69. //shipping_tel
  70. if(isset($post_data['shipping_tel']) && !empty($post_data['shipping_tel']))
  71. {
  72. $search['shipping_tel'] = $post_data['shipping_tel'];
  73. }
  74. //shipping_no
  75. if(isset($post_data['shipping_no']) && !empty($post_data['shipping_no']))
  76. {
  77. $search['shipping_no'] = $post_data['shipping_no'];
  78. }
  79. //goods_id
  80. if(isset($post_data['goods_id']) && !empty($post_data['goods_id']))
  81. {
  82. $search['goods_id'] = $post_data['goods_id'];
  83. }
  84. //date_added_begin
  85. if(isset($post_data['date_added_begin']) && !empty($post_data['date_added_begin']))
  86. {
  87. $search['date_added_begin'] = strtotime($post_data['date_added_begin']);
  88. }
  89. //date_added_end
  90. if(isset($post_data['date_added_end']) && !empty($post_data['date_added_end']))
  91. {
  92. $search['date_added_end'] = strtotime($post_data['date_added_end']);
  93. }
  94. //is_pin
  95. if(isset($post_data['is_pin']) && $post_data['is_pin'] >=0)
  96. {
  97. $search['is_pin'] = $post_data['is_pin'];
  98. }
  99. }
  100. if( isset($post_data['subtype']) && $post_data['subtype'] == 'export') {
  101. //导出
  102. $data=$model->show_order_page($search,true);
  103. //order_status_id/1
  104. $need_data = array();
  105. $sql="select s.* from ".C('DB_PREFIX')."seller_express as s, ".C('DB_PREFIX')."seller_express_relat as ser
  106. where s.id = ser.express_id and ser.store_id = ".SELLERUID;
  107. $express_list= M()->query($sql);
  108. $express_str = ' 请填写以下快递对应的编号: ';
  109. foreach($express_list as $express)
  110. {
  111. $express_str .= $express['express_name'].":".$express['id'].' ';
  112. }
  113. foreach($data['list'] as $val)
  114. {
  115. if($val['pin_id'] > 0 && $val['lottery_win'] == 0){
  116. $tmp_pin_info = M('pin')->where( array('pin_id' => $val['pin_id']) )->find();
  117. if($tmp_pin_info['is_lottery'] == 1)
  118. {
  119. continue;
  120. }
  121. }
  122. if($val['is_zhuli'] == 2)
  123. {
  124. $val['goods_name'] = '[砍价]'.$val['goods_name'];
  125. }
  126. if($val['type'] == 'lottery')
  127. {
  128. $val['goods_name'] = '[抽奖]'.$val['goods_name'];
  129. }
  130. $tmp_arr = array();
  131. $tmp_arr['order_sn'] = ' '.$val['order_num_alias'].' ';
  132. if($val['type'] == 'lottery')
  133. {
  134. $val['goods_name'] = '[抽奖]'.$val['goods_name'];
  135. }
  136. if($val['is_zhuli'] == 2)
  137. {
  138. $val['goods_name'] = '[砍价]'.$val['goods_name'];
  139. }
  140. if($val['head_disc'] < 100)
  141. {
  142. if($val['head_disc'] == 0)
  143. {
  144. $val['goods_name'] = '[团长免单]'.$val['goods_name'];
  145. }else{
  146. $val['goods_name'] = '[团长'.($val['head_disc']/10).'折]'.$val['goods_name'];
  147. }
  148. }
  149. $tmp_arr['goods_name'] = $val['goods_name'];
  150. $tmp_arr['quantity'] = $val['quantity'];
  151. $tmp_arr['total'] = $val['total'];
  152. $tmp_arr['delivery'] = ($val['delivery'] == 'express') ? '快递': '自提';
  153. $tmp_arr['pick_name'] = '';
  154. $tmp_arr['pick_telephone'] = '';
  155. $tmp_arr['pick_sn'] = '';
  156. $tmp_arr['pick_huo'] = '';
  157. if($val['delivery'] == 'pickup')
  158. {
  159. $pick_order_info = M('pick_order')->where( array('order_id' => $val['order_id']) )->find();
  160. $pick_up = M('pick_up')->where( array('id' => $pick_order_info['pick_id']) )->find();
  161. $tmp_arr['pick_name'] = $pick_up['pick_name'];
  162. $tmp_arr['pick_telephone'] = ' '.$pick_up['telephone'];
  163. $tmp_arr['pick_sn'] = ' '.$pick_order_info['pick_sn'];
  164. $tmp_arr['pick_huo'] = ($pick_order_info['state'] == 0) ? '未提货': '已提货';
  165. }
  166. $tmp_arr['date_added'] = date('Y-m-d H:i:s', $val['date_added']);
  167. if(!empty($val['shipping_method'])) {
  168. $shipping_method = M('seller_express')->where( array('id' => $val['shipping_method']) )->find();
  169. $tmp_arr['shipping_method'] = $val['shipping_method'];
  170. }else {
  171. $tmp_arr['shipping_method'] = '';
  172. }
  173. $tmp_arr['shipping_no'] = $val['shipping_no'];
  174. $order_goods_info = M('order_goods')->field('order_goods_id')->where( array('order_id' => $val['order_id']) )->find();
  175. $order_goods_id = $order_goods_info['order_goods_id'];
  176. $option_list = M('order_option')->where( array('order_goods_id' =>$order_goods_id,'order_id'=> $val['order_id']) )->select();
  177. if(!empty($option_list))
  178. {
  179. $str = '';
  180. foreach ($option_list as $option) {
  181. $str .= $option['name'].': '.$option['value'].' ';
  182. }
  183. $tmp_arr['option'] = $str;
  184. } else {
  185. $tmp_arr['option'] = '无';
  186. }
  187. $tmp_arr['shipping_name'] = $val['shipping_name'];
  188. $tmp_arr['shipping_tel'] = $val['shipping_tel'];
  189. $province_info = M('area')->where( array('area_id' => $val['shipping_province_id']) )->find();
  190. $city_info = M('area')->where( array('area_id' => $val['shipping_city_id']) )->find();
  191. $country_info = M('area')->where( array('area_id' => $val['shipping_country_id']) )->find();
  192. $tmp_arr['shipping_province_id'] = $province_info['area_name'];
  193. $tmp_arr['shipping_city_id'] = $city_info['area_name'];
  194. $tmp_arr['shipping_country_id'] = $country_info['area_name'];
  195. $tmp_arr['shipping_address'] = $val['shipping_address'];
  196. $tmp_arr['all_address'] = $province_info['area_name'].$city_info['area_name'].$country_info['area_name'].$val['shipping_address'];
  197. $tmp_arr['comment'] = $val['comment'];
  198. $tmp_arr['telephone'] = ' '. $val['telephone'];
  199. $need_data[] = $tmp_arr;
  200. }
  201. $xlsCell = array(
  202. array('order_sn','订单号'),
  203. array('goods_name','货物名称'),
  204. array('quantity','数量'),
  205. array('total','订单金额'),
  206. array('date_added','下单时间'),
  207. array('shipping_method','系统快递'.$express_str),
  208. array('shipping_no','快递单号 '),
  209. array('delivery','配送方式'),
  210. array('pick_name','提货地点'),
  211. array('pick_telephone','提货电话'),
  212. array('pick_sn','提货单序号'),
  213. array('pick_huo','是否提货'),
  214. array('option','商品规格 '),
  215. array('shipping_name','提货人姓名 '),
  216. array('telephone','提货人电话 '),
  217. array('comment','备注')
  218. );
  219. $expTitle = '订单信息_'.date('Y-m-d H:i:s');
  220. export_excel($expTitle,$xlsCell,$need_data);
  221. } else {
  222. //var_dump($search);
  223. //die();
  224. $data=$model->show_order_page($search);
  225. }
  226. $this->type = -1;
  227. $this->search = $search;//搜索条件
  228. $this->order_status_id = $order_status_id;
  229. $this->assign('empty',$data['empty']);// 赋值数据集
  230. $this->assign('list',$data['list']);// 赋值数据集
  231. $this->assign('page',$data['page']);// 赋值分页输出
  232. $this->status=M('order_status')->select();
  233. $this->display();
  234. }
  235. public function index(){
  236. $model=new PickupModel();
  237. $search = array();
  238. $search['store_id'] = SELLERUID;
  239. $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
  240. $has_seller_id = $hashids->encode(SELLERUID);
  241. //qrcode
  242. $jssdk = new \Lib\Weixin\Jssdk( C('weprogram_appid'), C('weprogram_appscret') );
  243. //保存图片
  244. $data=$model->show_pickup_page($search);
  245. foreach($data['list'] as $key => $val)
  246. {
  247. $pick_link = C('SITE_URL')."/index.php?s=/seller/bind_pickup_order/pick_up_id/{$val[id]}/seller_id/{$has_seller_id}";
  248. $val['pick_link'] = $pick_link;
  249. $val['member_count'] = M('pick_member')->where( array('store_id' => SELLERUID,'pick_up_id' => $val['id']) )->count();
  250. if( empty($val['we_qrcode']) || isset($_GET['reflush']) )
  251. {
  252. $weqrcode = $jssdk->getAllWeQrcode('pages/order/hexiao_bind',SELLERUID.'_'.$val['id'] );
  253. //$weqrcode = $jssdk->getAllWeQrcode('pages/dan/index','5' );
  254. $image_dir = ROOT_PATH.'Uploads/image/goods';
  255. $image_dir .= '/'.date('Y-m-d').'/';
  256. $file_path = C('SITE_URL').'Uploads/image/goods/'.date('Y-m-d').'/';
  257. $kufile_path = $dir.'/'.date('Y-m-d').'/';
  258. RecursiveMkdir($image_dir);
  259. $file_name = md5('qrcode_'.$pick_order_info['pick_sn'].time()).'.png';
  260. //qrcode
  261. file_put_contents($image_dir.$file_name, $weqrcode);
  262. M('pick_up')->where( array('id' => $val['id']) )->save( array('we_qrcode' => $file_path.$file_name) );
  263. $val['we_qrcode'] = $file_path.$file_name;
  264. }
  265. //member_count pick_member
  266. $data['list'][$key] = $val;
  267. }
  268. $this->assign('seller_id',SELLERUID);
  269. $this->assign('empty',$data['empty']);// 赋值数据集
  270. $this->assign('list',$data['list']);// 赋值数据集
  271. $this->assign('page',$data['page']);// 赋值分页输出
  272. $this->display();
  273. }
  274. public function toggle_statues_show()
  275. {
  276. $gid = I('post.gid');
  277. $pick_member = M('pick_member')->where( array('id' => $gid ) )->find();
  278. if($pick_member['state'] ==0)
  279. {
  280. M('pick_member')->where( array('id' => $gid ) )->save( array('state' => 1) );
  281. }else{
  282. M('pick_member')->where( array('id' => $gid ) )->save( array('state' => 0) );
  283. }
  284. echo json_encode( array('code'=>1) );
  285. die();
  286. }
  287. public function member()
  288. {
  289. $model=new PickupModel();
  290. //pick_up_id/5
  291. $pick_up_id = I('get.pick_up_id',0);
  292. $search = array();
  293. $search['store_id'] = SELLERUID;
  294. if($pick_up_id >0)
  295. {
  296. $search['pick_up_id'] = $pick_up_id;
  297. }
  298. $data=$model->show_pickup_member_page($search);
  299. $this->type = 2;
  300. $this->assign('seller_id',SELLERUID);
  301. $this->assign('empty',$data['empty']);// 赋值数据集
  302. $this->assign('list',$data['list']);// 赋值数据集
  303. $this->assign('page',$data['page']);// 赋值分页输出
  304. $this->display();
  305. }
  306. public function hexiao_sub()
  307. {
  308. $id = I('get.id',0,'intval');
  309. $result = array( 'code' => 0,'msg' => '提货失败');
  310. $res = M('pick_order')->where( array('id' => $id) )->save( array('state' => 1, 'tihuo_time' => time()) );
  311. if($res)
  312. {
  313. $pick_order = M('pick_order')->where( array('id' => $id) )->find();
  314. M('order')->where( array('order_id' => $pick_order['order_id']) )->save( array('order_status_id' => 6) );
  315. $history_data = array();
  316. $history_data['order_id'] = $pick_order['order_id'];
  317. $history_data['order_status_id'] = 6;
  318. $history_data['notify'] = 0;
  319. $history_data['comment'] = '商家后台:用户提货,核销';
  320. $history_data['date_added'] = time();
  321. M('order_history')->add($history_data);
  322. $notify_model = D('Home/Weixinnotify');
  323. $notify_model->sendPickupsuccessMsg($pick_order['order_id']);
  324. $result['code'] = 1;
  325. }
  326. echo json_encode($result);
  327. die();
  328. }
  329. public function hexiao()
  330. {
  331. $pick_order = array();
  332. if(IS_POST){
  333. $pick_sn = I('post.pick_sn','','trim');
  334. $pick_order = M('pick_order')->where( array('pick_sn' => $pick_sn) )->find();
  335. //pick_id order_id state addtime
  336. $pick_up = M('pick_up')->where( array('id' => $pick_order['id']) )->find();
  337. $order_goods = M('order_goods')->where( array('order_id' => $pick_order['order_id']) )->find();
  338. $is_cur_dian = (SELLERUID == $order_goods['store_id']) ? true : false;
  339. $option_list = M('order_option')->where( array('order_goods_id' =>$order_goods['goods_id'],'order_id'=> $pick_order['order_id']) )->select();
  340. $option_str = '';
  341. if(!empty($option_list))
  342. {
  343. $str = '';
  344. foreach ($option_list as $option) {
  345. $str .= $option['name'].': '.$option['value'].' ';
  346. }
  347. $option_str = $str;
  348. } else {
  349. $option_str = '无';
  350. }
  351. $this->option_str = $option_str;
  352. $this->pick_up = $pick_up;
  353. $this->order_goods = $order_goods;
  354. $this->pick_sn = $pick_sn;
  355. $this->is_cur_dian = $is_cur_dian;
  356. }
  357. $this->pick_order = $pick_order;
  358. $this->type = 1;
  359. $this->display();
  360. }
  361. function add(){
  362. if(IS_POST){
  363. $data=I('post.');
  364. $data['store_id'] = SELLERUID;
  365. $data['addtime'] = time();
  366. $res = M('pick_up')->add($data);
  367. if($res) {
  368. $return = array(
  369. 'status'=>'success',
  370. 'message'=>'新增成功',
  371. 'jump'=>U('Pickup/index')
  372. );
  373. } else {
  374. $return = array(
  375. 'status'=>'fail',
  376. 'message'=>'新增失败',
  377. 'jump'=>U('Pickup/index')
  378. );
  379. }
  380. $this->osc_alert($return);
  381. }
  382. $this->crumbs='新增';
  383. $this->action=U('Pickup/add');
  384. $this->display('edit');
  385. }
  386. function edit(){
  387. if(IS_POST){
  388. $data=I('post.');
  389. $data['addtime'] = time();
  390. $ck_info = M('pick_up')->where(array('id' =>$data['id'],'store_id' =>SELLERUID))->find();
  391. if(empty($ck_info)) {
  392. $return = array(
  393. 'status'=>'fail',
  394. 'message'=>'非法操作',
  395. 'jump'=>U('Pickup/index')
  396. );
  397. $this->osc_alert($return);
  398. }
  399. $res = M('pick_up')->save($data);
  400. if($res) {
  401. $return = array(
  402. 'status'=>'success',
  403. 'message'=>'编辑成功',
  404. 'jump'=>U('Pickup/index')
  405. );
  406. } else {
  407. $return = array(
  408. 'status'=>'fail',
  409. 'message'=>'编辑失败',
  410. 'jump'=>U('Pickup/index')
  411. );
  412. }
  413. $this->osc_alert($return);
  414. }
  415. $this->crumbs='编辑';
  416. $this->action=U('Pickup/edit');
  417. $this->d=M('pick_up')->find(I('id'));
  418. $this->display('edit');
  419. }
  420. public function del_member()
  421. {
  422. //id
  423. $id = I('get.id', 0);
  424. $res = M('pick_member')->where( array('id' => $id) )->delete();
  425. if($res) {
  426. $return = array(
  427. 'status'=>'success',
  428. 'message'=>'删除成功',
  429. 'jump'=>$_SERVER['HTTP_REFERER']
  430. );
  431. } else {
  432. $return = array(
  433. 'status'=>'fail',
  434. 'message'=>'删除失败',
  435. 'jump'=>$_SERVER['HTTP_REFERER']
  436. );
  437. }
  438. $this->osc_alert($return);
  439. }
  440. public function del(){
  441. $id = I('get.id', 0);
  442. $res = M('pick_up')->where( array('id' => $id) )->delete();
  443. if($res) {
  444. $return = array(
  445. 'status'=>'success',
  446. 'message'=>'删除成功',
  447. 'jump'=>U('Pickup/index')
  448. );
  449. } else {
  450. $return = array(
  451. 'status'=>'fail',
  452. 'message'=>'删除失败',
  453. 'jump'=>U('Pickup/index')
  454. );
  455. }
  456. $this->osc_alert($return);
  457. }
  458. }
  459. ?>