vr_order.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. /**
  3. * 虚拟订单管理
  4. *
  5. *
  6. *
  7. ***/
  8. defined('InShopNC') or exit('Access Invalid!');
  9. class vr_orderControl extends SystemControl{
  10. /**
  11. * 每次导出订单数量
  12. * @var int
  13. */
  14. const EXPORT_SIZE = 1000;
  15. public function __construct(){
  16. parent::__construct();
  17. Language::read('trade');
  18. }
  19. public function indexOp(){
  20. $model_vr_order = Model('vr_order');
  21. $condition = array();
  22. if($_GET['order_sn']) {
  23. $condition['order_sn'] = $_GET['order_sn'];
  24. }
  25. if($_GET['store_name']) {
  26. $condition['store_name'] = $_GET['store_name'];
  27. }
  28. if(!empty($_GET['order_state'])){
  29. $condition['order_state'] = intval($_GET['order_state']);
  30. }
  31. if($_GET['payment_code']) {
  32. $condition['payment_code'] = $_GET['payment_code'];
  33. }
  34. if($_GET['buyer_name']) {
  35. $condition['buyer_name'] = $_GET['buyer_name'];
  36. }
  37. $if_start_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['query_start_time']);
  38. $if_end_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['query_end_time']);
  39. $start_unixtime = $if_start_time ? strtotime($_GET['query_start_time']) : null;
  40. $end_unixtime = $if_end_time ? strtotime($_GET['query_end_time']): null;
  41. if ($start_unixtime || $end_unixtime) {
  42. $condition['add_time'] = array('time',array($start_unixtime,$end_unixtime));
  43. }
  44. $order_list = $model_vr_order->getOrderList($condition,30);
  45. foreach ($order_list as $k => $order_info) {
  46. //显示取消订单
  47. $order_list[$k]['if_cancel'] = $model_vr_order->getOrderOperateState('system_cancel',$order_info);
  48. //显示收到货款
  49. $order_list[$k]['if_system_receive_pay'] = $model_vr_order->getOrderOperateState('system_receive_pay',$order_info);
  50. }
  51. //显示支付接口列表(搜索)
  52. $payment_list = Model('payment')->getPaymentOpenList();
  53. Tpl::output('payment_list',$payment_list);
  54. Tpl::output('order_list',$order_list);
  55. Tpl::output('show_page',$model_vr_order->showpage());
  56. Tpl::showpage('vr_order.index');
  57. }
  58. /**
  59. * 平台订单状态操作
  60. *
  61. */
  62. public function change_stateOp() {
  63. $model_vr_order = Model('vr_order');
  64. $condition = array();
  65. $condition['order_id'] = intval($_GET['order_id']);
  66. $order_info = $model_vr_order->getOrderInfo($condition);
  67. if ($_GET['state_type'] == 'cancel') {
  68. $result = $this->_order_cancel($order_info);
  69. } elseif ($_GET['state_type'] == 'receive_pay') {
  70. $result = $this->_order_receive_pay($order_info,$_POST);
  71. }
  72. if(!$result['state']) {
  73. showMessage($result['msg'],$_POST['ref_url'],'html','error');
  74. } else {
  75. showMessage($result['msg'],$_POST['ref_url']);
  76. }
  77. }
  78. /**
  79. * 系统取消订单
  80. * @param unknown $order_info
  81. */
  82. private function _order_cancel($order_info) {
  83. $model_vr_order = Model('vr_order');
  84. $logic_vr_order = Logic('vr_order');
  85. $if_allow = $model_vr_order->getOrderOperateState('system_cancel',$order_info);
  86. if (!$if_allow) {
  87. return callback(false,'无权操作');
  88. }
  89. $this->log('关闭了虚拟订单,'.L('order_number').':'.$order_info['order_sn'],1);
  90. return $logic_vr_order->changeOrderStateCancel($order_info,'store', '管理员关闭虚拟订单');
  91. }
  92. /**
  93. * 系统收到货款
  94. * @param unknown $order_info
  95. * @throws Exception
  96. */
  97. private function _order_receive_pay($order_info,$post) {
  98. $model_vr_order = Model('vr_order');
  99. $logic_vr_order = Logic('vr_order');
  100. $if_allow = $model_vr_order->getOrderOperateState('system_receive_pay',$order_info);
  101. if (!$if_allow) {
  102. return callback(false,'无权操作');
  103. }
  104. if (!chksubmit()) {
  105. Tpl::output('order_info',$order_info);
  106. //显示支付接口
  107. $payment_list = Model('payment')->getPaymentOpenList();
  108. //去掉预存款和货到付款
  109. foreach ($payment_list as $key => $value){
  110. if ($value['payment_code'] == 'predeposit' || $value['payment_code'] == 'offline') {
  111. unset($payment_list[$key]);
  112. }
  113. }
  114. Tpl::output('payment_list',$payment_list);
  115. Tpl::showpage('order.receive_pay');
  116. exit();
  117. } else {
  118. $this->log('将虚拟订单改为已收款状态,'.L('order_number').':'.$order_info['order_sn'],1);
  119. return $logic_vr_order->changeOrderStatePay($order_info,'system', $post);
  120. }
  121. }
  122. /**
  123. * 查看订单
  124. *
  125. */
  126. public function show_orderOp(){
  127. $order_id = intval($_GET['order_id']);
  128. if($order_id <= 0 ){
  129. showMessage(L('miss_order_number'));
  130. }
  131. $model_vr_order = Model('vr_order');
  132. $order_info = $model_vr_order->getOrderInfo(array('order_id'=>$order_id));
  133. if (empty($order_info)) {
  134. showMessage('订单不存在','','html','error');
  135. }
  136. //取兑换码列表
  137. $vr_code_list = $model_vr_order->getOrderCodeList(array('order_id' => $order_info['order_id']));
  138. $order_info['extend_vr_order_code'] = $vr_code_list;
  139. //显示取消订单
  140. $order_info['if_cancel'] = $model_vr_order->getOrderOperateState('buyer_cancel',$order_info);
  141. //显示订单进行步骤
  142. $order_info['step_list'] = $model_vr_order->getOrderStep($order_info);
  143. //显示系统自动取消订单日期
  144. if ($order_info['order_state'] == ORDER_STATE_NEW) {
  145. //$order_info['order_cancel_day'] = $order_info['add_time'] + ORDER_AUTO_CANCEL_DAY * 24 * 3600;
  146. // by abc.com
  147. $order_info['order_cancel_day'] = $order_info['add_time'] + ORDER_AUTO_CANCEL_DAY + 3 * 24 * 3600;
  148. }
  149. Tpl::output('order_info',$order_info);
  150. Tpl::showpage('vr_order.view');
  151. }
  152. /**
  153. * 导出
  154. *
  155. */
  156. public function export_step1Op(){
  157. $lang = Language::getLangContent();
  158. $model_vr_order = Model('vr_order');
  159. $condition = array();
  160. if($_GET['order_sn']) {
  161. $condition['order_sn'] = $_GET['order_sn'];
  162. }
  163. if($_GET['store_name']) {
  164. $condition['store_name'] = $_GET['store_name'];
  165. }
  166. if(in_array($_GET['order_state'],array('0','10','20','30','40'))){
  167. $condition['order_state'] = $_GET['order_state'];
  168. }
  169. if($_GET['payment_code']) {
  170. $condition['payment_code'] = $_GET['payment_code'];
  171. }
  172. if($_GET['buyer_name']) {
  173. $condition['buyer_name'] = $_GET['buyer_name'];
  174. }
  175. $if_start_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['query_start_time']);
  176. $if_end_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['query_end_time']);
  177. $start_unixtime = $if_start_time ? strtotime($_GET['query_start_time']) : null;
  178. $end_unixtime = $if_end_time ? strtotime($_GET['query_end_time']): null;
  179. if ($start_unixtime || $end_unixtime) {
  180. $condition['add_time'] = array('time',array($start_unixtime,$end_unixtime));
  181. }
  182. if (!is_numeric($_GET['curpage'])){
  183. $count = $model_vr_order->getOrderCount($condition);
  184. $array = array();
  185. if ($count > self::EXPORT_SIZE ){ //显示下载链接
  186. $page = ceil($count/self::EXPORT_SIZE);
  187. for ($i=1;$i<=$page;$i++){
  188. $limit1 = ($i-1)*self::EXPORT_SIZE + 1;
  189. $limit2 = $i*self::EXPORT_SIZE > $count ? $count : $i*self::EXPORT_SIZE;
  190. $array[$i] = $limit1.' ~ '.$limit2 ;
  191. }
  192. Tpl::output('list',$array);
  193. Tpl::output('murl','index.php?act=vr_order&op=index');
  194. Tpl::showpage('export.excel');
  195. }else{ //如果数量小,直接下载
  196. $data = $model_vr_order->getOrderList($condition,'','*','order_id desc',self::EXPORT_SIZE);
  197. $this->createExcel($data);
  198. }
  199. }else{ //下载
  200. $limit1 = ($_GET['curpage']-1) * self::EXPORT_SIZE;
  201. $limit2 = self::EXPORT_SIZE;
  202. $data = $model_vr_order->getOrderList($condition,'','*','order_id desc',"{$limit1},{$limit2}");
  203. $this->createExcel($data);
  204. }
  205. }
  206. /**
  207. * 生成excel
  208. *
  209. * @param array $data
  210. */
  211. private function createExcel($data = array()){
  212. Language::read('export');
  213. import('libraries.excel');
  214. $excel_obj = new Excel();
  215. $excel_data = array();
  216. //设置样式
  217. $excel_obj->setStyle(array('id'=>'s_title','Font'=>array('FontName'=>'宋体','Size'=>'12','Bold'=>'1')));
  218. //header
  219. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_od_no'));
  220. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_od_store'));
  221. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_od_buyer'));
  222. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_od_xtimd'));
  223. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_od_count'));
  224. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_od_paytype'));
  225. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_od_state'));
  226. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_od_storeid'));
  227. $excel_data[0][] = array('styleid'=>'s_title','data'=>L('exp_od_buyerid'));
  228. $excel_data[0][] = array('styleid'=>'s_title','data'=>'接收手机');
  229. //data
  230. foreach ((array)$data as $k=>$v){
  231. $tmp = array();
  232. $tmp[] = array('data'=>'NC'.$v['order_sn']);
  233. $tmp[] = array('data'=>$v['store_name']);
  234. $tmp[] = array('data'=>$v['buyer_name']);
  235. $tmp[] = array('data'=>date('Y-m-d H:i:s',$v['add_time']));
  236. $tmp[] = array('format'=>'Number','data'=>ncPriceFormat($v['order_amount']));
  237. $tmp[] = array('data'=>orderPaymentName($v['payment_code']));
  238. $tmp[] = array('data'=>$v['state_desc']);
  239. $tmp[] = array('data'=>$v['store_id']);
  240. $tmp[] = array('data'=>$v['buyer_id']);
  241. $tmp[] = array('data'=>$v['buyer_phone']);
  242. $excel_data[] = $tmp;
  243. }
  244. $excel_data = $excel_obj->charset($excel_data,CHARSET);
  245. $excel_obj->addArray($excel_data);
  246. $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'),CHARSET));
  247. $excel_obj->generateXML($excel_obj->charset(L('exp_od_order'),CHARSET).$_GET['curpage'].'-'.date('Y-m-d-H',time()));
  248. }
  249. }