grouporder.inc.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. global $_GPC, $_W;
  3. $GLOBALS['frames'] = $this->getMainMenu();
  4. $pageindex = max(1, intval($_GPC['page']));
  5. $pagesize=10;
  6. $type=isset($_GPC['type'])?$_GPC['type']:'all';
  7. $type2=isset($_GPC['type2'])?$_GPC['type2']:'today';
  8. $where=" where a.uniacid=:uniacid ";
  9. $data[':uniacid']=$_W['uniacid'];
  10. if(isset($_GPC['keywords'])){
  11. $where.=" and (a.goods_name LIKE concat('%', :name,'%') || a.order_num LIKE concat('%', :name,'%') || b.name LIKE concat('%', :name,'%') || c.store_name LIKE concat('%', :name,'%'))";
  12. $data[':name']=$_GPC['keywords'];
  13. $type='all';
  14. }
  15. if($_GPC['time']){
  16. $start=strtotime($_GPC['time']['start']);
  17. $end=strtotime($_GPC['time']['end']);
  18. $where.=" and a.time >='{$start}' and a.time<='{$end}'";
  19. $type='all';
  20. }else{
  21. if($type=='wait'){
  22. $where.=" and a.state=1";
  23. }
  24. if($type=='pay'){
  25. $where.=" and a.state=2";
  26. }
  27. if($type=='complete'){
  28. $where.=" and a.state=3";
  29. }
  30. if($type=='close'){
  31. $where.=" and a.state=4";
  32. }
  33. if($type=='invalid'){
  34. $where.=" and a.state=5";
  35. }
  36. }
  37. $sql="SELECT a.*,b.name as nick_name,c.store_name FROM ".tablename('zhtc_grouporder'). " a" . " left join " . tablename("zhtc_user") . " b on a.user_id=b.id left join " . tablename("zhtc_store") . " c on a.store_id=c.id " .$where." ORDER BY a.id DESC";
  38. $total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zhtc_grouporder'). " a" . " left join " . tablename("zhtc_user") . " b on a.user_id=b.id left join " . tablename("zhtc_store") . " c on a.store_id=c.id " .$where,$data);
  39. $select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  40. $list=pdo_fetchall($select_sql,$data);
  41. $pager = pagination($total, $pageindex, $pagesize);
  42. if($_GPC['op']=='delete'){
  43. $res=pdo_delete('zhtc_grouporder',array('id'=>$_GPC['id']));
  44. if($res){
  45. message('删除成功!', $this->createWebUrl('grouporder'), 'success');
  46. }else{
  47. message('删除失败!','','error');
  48. }
  49. }
  50. //拼团失败,退款
  51. $ids=pdo_getall('zhtc_group',array('dq_time <='=>time(),'state'=>1,'uniacid'=>$_W['uniacid']),'id');
  52. //var_dump($ids);die;
  53. if($ids){
  54. $uids = array_map('array_shift', $ids);
  55. $orders=pdo_getall('zhtc_grouporder',array('group_id'=>$uids,'state'=>2,'pay_type'=>1),'id');
  56. foreach ($orders as $key => $value) {
  57. include_once IA_ROOT . '/addons/zh_tcwq/cert/WxPay.Api.php';
  58. load()->model('account');
  59. load()->func('communication');
  60. $refund_order =pdo_get('zhtc_grouporder',array('id'=>$value));
  61. $WxPayApi = new WxPayApi();
  62. $input = new WxPayRefund();
  63. $path_cert = IA_ROOT . "/addons/zh_tcwq/cert/".'apiclient_cert_' .$_W['uniacid'] . '.pem';
  64. $path_key = IA_ROOT . "/addons/zh_tcwq/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
  65. $account_info = $_W['account'];
  66. $system=pdo_get('zhtc_system',array('uniacid'=>$_W['uniacid']));
  67. $appid=$system['appid'];
  68. $key=$system['wxkey'];
  69. $mchid=$system['mchid'];
  70. $out_trade_no=$refund_order['code'];
  71. $fee = $refund_order['money'] * 100;
  72. $input->SetAppid($appid);
  73. $input->SetMch_id($mchid);
  74. $input->SetOp_user_id($mchid);
  75. $input->SetRefund_fee($fee);
  76. $input->SetTotal_fee($fee);
  77. // $input->SetTransaction_id($refundid);
  78. $input->SetOut_refund_no($refund_order['order_num']);
  79. $input->SetOut_trade_no($out_trade_no);
  80. $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);
  81. ////////////////////////////////////
  82. if ($result['result_code'] == 'SUCCESS') {//退款成功
  83. //更改订单操作
  84. pdo_update('zhtc_grouporder',array('state'=>4),array('id'=>$value));
  85. }
  86. }
  87. $group=pdo_update('zhtc_group',array('state'=>3),array('id'=>$uids));
  88. }
  89. include $this->template('web/grouporder');