OrderController.class.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. <?php
  2. /**
  3. * 小梦科技资源nanodreamtech.com
  4. *
  5. * ==========================================================================
  6. * @link https://www.nanodreamtech.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license https://www.nanodreamtech.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Admin\Controller;
  15. use Admin\Model\OrderModel;
  16. class OrderController extends CommonController{
  17. protected function _initialize(){
  18. parent::_initialize();
  19. $this->breadcrumb1='订单';
  20. $this->breadcrumb2='订单管理';
  21. }
  22. public function index(){
  23. $model=new OrderModel();
  24. //$w=new \Lib\Kuaidiniao();
  25. //$w->subscribe('470');
  26. //die();
  27. $filter=I('get.');
  28. $order_status_id = I('get.order_status_id', 0);
  29. $search=array();
  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 = $_GET = array_merge($_GET,$_POST);
  44. $post_data = $_POST;
  45. if(isset($post_data['transaction_id'])){
  46. $search['transaction_id']=$post_data['transaction_id'];
  47. }
  48. //store_id
  49. if(isset($post_data['store_id']) && !empty($post_data['store_id']))
  50. {
  51. $search['store_id'] = $post_data['store_id'];
  52. }
  53. //order_num_alias
  54. if(isset($post_data['order_num_alias']) && !empty($post_data['order_num_alias']))
  55. {
  56. $search['order_num'] = $post_data['order_num_alias'];
  57. }
  58. //member_id
  59. if(isset($post_data['member_id']) && !empty($post_data['member_id']))
  60. {
  61. $search['member_id'] = $post_data['member_id'];
  62. }
  63. //name
  64. if(isset($post_data['name']) && !empty($post_data['name']))
  65. {
  66. $search['user_name'] = $post_data['name'];
  67. }
  68. //shipping_tel
  69. if(isset($post_data['shipping_tel']) && !empty($post_data['shipping_tel']))
  70. {
  71. $search['shipping_tel'] = $post_data['shipping_tel'];
  72. }
  73. //shipping_no
  74. if(isset($post_data['shipping_no']) && !empty($post_data['shipping_no']))
  75. {
  76. $search['shipping_no'] = $post_data['shipping_no'];
  77. }
  78. //goods_id
  79. if(isset($post_data['goods_id']) && !empty($post_data['goods_id']))
  80. {
  81. $search['goods_id'] = $post_data['goods_id'];
  82. }
  83. //date_added_begin
  84. if(isset($post_data['date_added_begin']) && !empty($post_data['date_added_begin']))
  85. {
  86. $search['date_added_begin'] = strtotime($post_data['date_added_begin']);
  87. }
  88. //date_added_end
  89. if(isset($post_data['date_added_end']) && !empty($post_data['date_added_end']))
  90. {
  91. $search['date_added_end'] = strtotime($post_data['date_added_end']);
  92. }
  93. //is_pin
  94. if(isset($post_data['is_pin']) && $post_data['is_pin'] >=0)
  95. {
  96. $search['is_pin'] = $post_data['is_pin'];
  97. }
  98. if( isset($post_data['subtype']) && $post_data['subtype'] == 'export') {
  99. //导出
  100. $data=$model->show_order_page($search,true);
  101. $need_data = array();
  102. foreach($data['list'] as $val)
  103. {
  104. if($val['pin_id'] > 0 && $val['lottery_win'] == 0){
  105. $tmp_pin_info = M('pin')->where( array('pin_id' => $val['pin_id']) )->find();
  106. if($tmp_pin_info['is_lottery'] == 1)
  107. {
  108. continue;
  109. }
  110. }
  111. $tmp_arr = array();
  112. $tmp_arr['order_sn'] = $val['order_num_alias'].' ';
  113. //$tmp_arr['goods_name'] = $val['goods_name'];
  114. $tmp_arr['quantity'] = $val['quantity'];
  115. $tmp_arr['total'] = $val['total'];
  116. $tmp_arr['delivery'] = ($val['delivery'] == 'express') ? '快递': '自提';
  117. $tmp_arr['pick_name'] = '';
  118. $tmp_arr['pick_telephone'] = '';
  119. $tmp_arr['pick_sn'] = '';
  120. $tmp_arr['pick_huo'] = '';
  121. if($val['delivery'] == 'pickup')
  122. {
  123. $pick_order_info = M('pick_order')->where( array('order_id' => $val['order_id']) )->find();
  124. $pick_up = M('pick_up')->where( array('id' => $pick_order_info['pick_id']) )->find();
  125. $tmp_arr['pick_name'] = $pick_up['pick_name'];
  126. $tmp_arr['pick_telephone'] = ' '.$pick_up['telephone'];
  127. $tmp_arr['pick_sn'] = ' '.$pick_order_info['pick_sn'];
  128. $tmp_arr['pick_huo'] = ($pick_order_info['state'] == 0) ? '未提货': '已提货';
  129. }
  130. $tmp_arr['date_added'] = date('Y-m-d H:i:s', $val['date_added']);
  131. if(!empty($val['shipping_method'])) {
  132. $shipping_method = M('seller_express')->where( array('id' => $val['shipping_method']) )->find();
  133. $tmp_arr['shipping_method'] = $shipping_method['express_name'];
  134. }else {
  135. $tmp_arr['shipping_method'] = '';
  136. }
  137. $tmp_arr['shipping_no'] = $val['shipping_no'];
  138. // $tmp_arr['goods_name'] = $val['goods_name'];
  139. $order_goods_info_list = M('order_goods')->field('order_goods_id,total,name,quantity')->where( array('order_id' => $val['order_id']) )->select();
  140. $tmp_arr['shipping_name'] = $val['shipping_name'];
  141. $tmp_arr['shipping_tel'] = $val['shipping_tel'];
  142. $province_info = M('area')->where( array('area_id' => $val['shipping_province_id']) )->find();
  143. $city_info = M('area')->where( array('area_id' => $val['shipping_city_id']) )->find();
  144. $country_info = M('area')->where( array('area_id' => $val['shipping_country_id']) )->find();
  145. $tmp_arr['shipping_province_id'] = $province_info['area_name'];
  146. $tmp_arr['shipping_city_id'] = $city_info['area_name'];
  147. $tmp_arr['shipping_country_id'] = $country_info['area_name'];
  148. $tmp_arr['shipping_address'] = $val['shipping_address'];
  149. $tmp_arr['all_address'] = $province_info['area_name'].$city_info['area_name'].$country_info['area_name'].$val['shipping_address'];
  150. foreach($order_goods_info_list as $order_goods_info)
  151. {
  152. $order_goods_id = $order_goods_info['order_goods_id'];
  153. $option_list = M('order_option')->where( array('order_goods_id' =>$order_goods_id,'order_id'=> $val['order_id']) )->select();
  154. if(!empty($option_list))
  155. {
  156. $str = '';
  157. foreach ($option_list as $option) {
  158. $str .= $option['name'].': '.$option['value'].' ';
  159. }
  160. $tmp_arr['option'] = $str;
  161. $tmp_arr['goods_name'] = $order_goods_info['name'];
  162. } else {
  163. $tmp_arr['option'] = '无';
  164. $tmp_arr['goods_name'] = $order_goods_info['name'];
  165. }
  166. $tmp_arr['total'] = $order_goods_info['total'];
  167. $tmp_arr['quantity'] = $order_goods_info['quantity'];
  168. $tmp_arr['comment'] = $val['comment'];
  169. $need_data[] = $tmp_arr;
  170. }
  171. }
  172. $xlsCell = array(
  173. array('order_sn','订单号'),
  174. array('goods_name','货物名称'),
  175. array('quantity','数量'),
  176. array('total','订单金额'),
  177. array('date_added','下单时间'),
  178. array('shipping_method','系统快递'),
  179. array('shipping_no','快递单号 '),
  180. array('delivery','配送方式'),
  181. array('pick_name','提货地点'),
  182. array('pick_telephone','提货电话'),
  183. array('pick_sn','提货单序号'),
  184. array('pick_huo','是否提货'),
  185. array('option','商品规格 '),
  186. array('shipping_name','姓名 '),
  187. array('shipping_tel','电话 '),
  188. array('shipping_province_id','省 '),
  189. array('shipping_city_id','市 '),
  190. array('shipping_country_id','区 '),
  191. array('shipping_address','街道 '),
  192. array('all_address','完整地址 '),
  193. array('comment','备注')
  194. );
  195. $expTitle = '订单信息_'.date('Y-m-d H:i:s');
  196. export_excel($expTitle,$xlsCell,$need_data);
  197. } else {
  198. $data=$model->show_order_page($search);
  199. }
  200. $seller_list = M('seller')->where( array('s_status' => 1) )->select();
  201. $this->seller_list = $seller_list;
  202. $this->search = $search;//搜索条件
  203. $this->order_status_id = $order_status_id;
  204. $this->assign('empty',$data['empty']);// 赋值数据集
  205. $this->assign('list',$data['list']);// 赋值数据集
  206. $this->assign('page',$data['page']);// 赋值分页输出
  207. $this->status=M('order_status')->select();
  208. $this->display();
  209. }
  210. function print_order(){
  211. $model=new OrderModel();
  212. $this->order=$model->order_info(I('id'));
  213. $this->print=true;
  214. $this->display('./Themes/Home/default/Mail/order.html');
  215. }
  216. public function refunddone()
  217. {
  218. $id = I('get.id',0,'intval');
  219. $comment = I('post.comment');
  220. $order_refund_type = I('post.order_refund_type',0,'intval');
  221. $result = array('code' =>1);
  222. $order_refund_history = array();
  223. $order_refund_history['order_id'] = $id;
  224. $order_refund_history['message'] = htmlspecialchars($comment);
  225. $order_refund_history['type'] = 3;
  226. $order_refund_history['addtime'] = time();
  227. M('order_refund_history')->add($order_refund_history);
  228. if($order_refund_type ==1)
  229. {
  230. //拒绝
  231. M('order_refund')->where( array('order_id' => $id) )->save( array('state' => 1) );
  232. } else {
  233. $weixin_model = D('Home/Weixin');
  234. //通过
  235. M('order_refund')->where( array('order_id' => $id) )->save( array('state' => 3) );
  236. $order_refund = M('order_refund')->where( array('order_id' => $id) )->find();
  237. $weixin_model->refundOrder($id, $order_refund['ref_money']);
  238. }
  239. echo json_encode($result);
  240. die();
  241. }
  242. public function show_refund()
  243. {
  244. $this->crumbs='订单退款详情';
  245. $model=new OrderModel();
  246. $data = $model->order_info(I('id'));
  247. $order_statuses = $data['order_statuses'];
  248. $need_status = array();
  249. foreach($order_statuses as $key => $val)
  250. {
  251. if( in_array($val['order_status_id'], array(4)) )
  252. {
  253. $need_status[$key] = $val;
  254. }
  255. }
  256. $data['order_statuses'] = $need_status;
  257. $refund_reason = array(
  258. '97' =>'商品有质量问题',
  259. '98' =>'没有收到货',
  260. '99' =>'商品少发漏发发错',
  261. '100' =>'商品与描述不一致',
  262. '101' =>'收到商品时有划痕或破损',
  263. '102' =>'质疑假货',
  264. '111' =>'其他',
  265. );
  266. $order_refund = M('order_refund')->where( array('order_id' =>I('id')) )->find();
  267. //ref_type
  268. $order_refund['ref_type'] = $order_refund['ref_type'] ==1 ? '仅退款': '退款退货';
  269. $order_refund['ref_name'] = $refund_reason[$order_refund['ref_name']];
  270. $refund_state = array(
  271. 0 => '申请中',
  272. 1 => '商家拒绝',
  273. 2 => '平台介入',
  274. 3 => '退款成功',
  275. 4 => '退款失败',
  276. 5 => '撤销申请',
  277. );
  278. $order_refund['state'] = $refund_state[$order_refund['state']];
  279. $this->order_refund = $order_refund;
  280. $order_refund_image = M('order_refund_image')->where( array('ref_id' => $order_refund['ref_id']) )->select();
  281. $refund_images = array();
  282. if(!empty($order_refund_image))
  283. {
  284. foreach($order_refund_image as $refund_image)
  285. {
  286. $refund_image['thumb_image'] = resize($refund_image['image'], 100, 100);
  287. $refund_images[] = $refund_image;
  288. }
  289. }
  290. $order_refund_history = M('order_refund_history')->where( array('order_id' => I('id')) )->order('addtime asc')->select();
  291. foreach($order_refund_history as $key => $val)
  292. {
  293. switch($val['type'])
  294. {
  295. case 1:
  296. $val['type'] = '用户反馈';
  297. break;
  298. case 2:
  299. $val['type'] = '商家反馈';
  300. break;
  301. case 3:
  302. $val['type'] = '平台反馈';
  303. break;
  304. }
  305. $order_refund_history_image = M('order_refund_history_image')->where( array('orh_id' => $val['id']) )->select();
  306. if(!empty($order_refund_history_image))
  307. {
  308. foreach($order_refund_history_image as $kk => $vv)
  309. {
  310. $vv['thumb_image'] = resize($vv['image'], 100, 100);
  311. $order_refund_history_image[$kk] = $vv;
  312. }
  313. }
  314. $val['order_refund_history_image'] = $order_refund_history_image;
  315. $order_refund_history[$key] = $val;
  316. }
  317. $this->order_refund_history = $order_refund_history;
  318. $this->refund_images = $refund_images;
  319. $this->data = $data;
  320. $this->display('refund');
  321. }
  322. public function show_order(){
  323. $this->crumbs='订单详情';
  324. $model=new OrderModel();
  325. $data = $model->order_info(I('id'));
  326. $this->data=$data;
  327. $pick_order_info = array();
  328. $pick_up = array();
  329. if($data['order']['delivery'] == 'pickup')
  330. {
  331. $pick_order_info = M('pick_order')->where( array('order_id' => $data['order']['order_id']) )->find();
  332. $pick_up = M('pick_up')->where( array('id' => $pick_order_info['pick_id']) )->find();
  333. }
  334. $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
  335. $order_id = $hashids->encode(I('id'));
  336. $config_info = M('config')->where( array('name' => 'SITE_URL') )->find();
  337. $pin_url = $config_info['value'].'/index.php?s=/group/info/group_order_id/'.$order_id.'.html';
  338. $this->pin_url = $pin_url;
  339. $this->pick_order_info = $pick_order_info;
  340. $this->pick_up = $pick_up;
  341. $sql="select s.* from ".C('DB_PREFIX')."seller_express as s";
  342. $express_list= M()->query($sql);
  343. $this->express_list = $express_list;
  344. $order_goods_haitao = M('order_goods_haitao')->where( array('order_id' => $data['order']['order_id']) )->find();
  345. $this->order_goods_haitao = $order_goods_haitao;
  346. $this->display('show');
  347. }
  348. function history(){
  349. $model=new OrderModel();
  350. if(IS_POST){
  351. if(I('order_status_id')==C('cancel_order_status_id')){
  352. $Order = new \Home\Model\OrderModel();
  353. $Order->cancel_order($_GET['id']);
  354. storage_user_action(session('user_auth.uid'),session('user_auth.username'),C('BACKEND_USER'),'取消了订单 '.$_GET['id']);
  355. $result=true;
  356. }else{
  357. $result=$model->addOrderHistory($_GET['id'],$_POST);
  358. }
  359. if($result){
  360. $this->success='新增成功!!';
  361. }else{
  362. $this->error='新增失败!!';
  363. }
  364. }
  365. $results = $model->getOrderHistories($_GET['id']);
  366. foreach ($results as $result) {
  367. $histories[] = array(
  368. 'notify' => $result['notify'] ? '是' : '否',
  369. 'status' => $result['status'],
  370. 'comment' => nl2br($result['comment']),
  371. 'date_added' => date('Y/m/d H:i:s', $result['date_added'])
  372. );
  373. }
  374. $this->histories=$histories;
  375. $this->display();
  376. }
  377. function del(){
  378. $model=new OrderModel();
  379. $return=$model->del_order(I('get.id'));
  380. $this->osc_alert($return);
  381. }
  382. }
  383. ?>