ddgl.inc.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. global $_GPC, $_W;
  3. // $action = 'ad';
  4. // $title = $this->actions_titles[$action];
  5. $GLOBALS['frames'] = $this->getMainMenu();
  6. $operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
  7. $type = isset($_GPC['type']) ? $_GPC['type'] : 'all';
  8. $status = $_GPC['status'];
  9. load()->func('tpl');
  10. $pageindex = max(1, intval($_GPC['page']));
  11. $pagesize = 10;
  12. $where = ' WHERE a.uniacid=:uniacid ';
  13. if ($_GPC['keywords']) {
  14. $op = $_GPC['keywords'];
  15. $where .= " and (a.order_num LIKE concat('%', :order_no,'%') or a.user_name LIKE concat('%', :order_no,'%'))";
  16. $data[':order_no'] = $op;
  17. }
  18. if ($status) {
  19. $op = $_GPC['keywords'];
  20. $where .= " and a.state=$status";
  21. }
  22. if ($_GPC['time']) {
  23. $start = strtotime($_GPC['time']['start']);
  24. $end = strtotime($_GPC['time']['end']);
  25. $where .= " and a.time >={$start} and a.time<={$end}";
  26. }
  27. $sql = "SELECT a.*,b.store_name as seller_name FROM " . tablename('zhtc_order') . " a" . " left join " . tablename("zhtc_store") . " b on a.store_id=b.id" . $where . " ORDER BY a.time DESC";
  28. $data[':uniacid'] = $_W['uniacid'];
  29. $total = pdo_fetchcolumn("SELECT count(*) FROM " . tablename('zhtc_order') . " a" . " left join " . tablename("zhtc_store") . " b on a.store_id=b.id" . $where . " ORDER BY a.time DESC", $data);
  30. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  31. $list = pdo_fetchall($select_sql, $data);
  32. $pager = pagination($total, $pageindex, $pagesize);
  33. if ($operation == 'delete') {
  34. $res = pdo_delete('zhtc_order', array('id' => $_GPC['id']));
  35. //$res=pdo_update('zhtc_order',array('is_delete'=>1),array('id'=>$_GPC['id']));
  36. if ($res) {
  37. message('删除成功', $this->createWebUrl('ddgl', array()), 'success');
  38. } else {
  39. message('删除失败', '', 'error');
  40. }
  41. }
  42. if ($operation == 'delivery') {
  43. $res = pdo_update('zhtc_order', array('state' => 3, 'fh_time' => time()), array('id' => $_GPC['id']));
  44. if ($res) {
  45. message('操作成功', $this->createWebUrl('ddgl', array()), 'success');
  46. } else {
  47. message('操作失败', '', 'error');
  48. }
  49. }
  50. if ($operation == 'receipt') {
  51. $order = pdo_get('zhtc_order', array('id' => $_GPC['id']));
  52. $res = pdo_update('zhtc_order', array('state' => 4, 'complete_time' => time()), array('id' => $_GPC['id']));
  53. if ($res) {
  54. pdo_update('zhtc_store', array('wallet +=' => $order['money']), array('id' => $order['store_id']));
  55. $data3['store_id'] = $order['store_id'];
  56. $data3['money'] = $order['money'];
  57. $data3['note'] = '商品订单';
  58. $data3['type'] = 1;
  59. $data3['time'] = date("Y-m-d H:i:s");
  60. pdo_insert('zhtc_store_wallet', $data3);
  61. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  62. if ($system['good_jf'] > 0) {
  63. pdo_update('zhtc_user', array('total_score +=' => $system['good_jf']), array('id' => $order['user_id']));
  64. $data2['score'] = $system['good_jf'];
  65. $data2['user_id'] = $order['user_id'];
  66. $data2['tid'] = $order['id'];
  67. $data2['note'] = '商品订单';
  68. $data2['type'] = 1;
  69. $data2['cerated_time'] = date('Y-m-d H:i:s');
  70. $data2['uniacid'] = $_W['uniacid']; //小程序id
  71. pdo_insert('zhtc_integral', $data2); //添加积分明细
  72. }
  73. // ///////////////////////////城市佣金
  74. // include IA_ROOT.'/addons/zh_tcwq/yj.php';
  75. // $cityname=Yj::getStoreCity($order['store_id']);
  76. // $yjset=Yj::getYjSet($_W['uniacid']);
  77. // if($yjset['type']==1){
  78. // $money=$_GPC['money']*$yjset['typer']/100;
  79. // }else{
  80. // $money=$_GPC['money']*$yjset['sjper']/100;
  81. // }
  82. // pdo_update('zhtc_account',array('money +='=>$money),array('cityname'=>$cityname));
  83. // /////////////////分销/////////////////
  84. // $set=pdo_get('zhtc_fxset',array('uniacid'=>$_W['uniacid']));
  85. // $order=pdo_get('zhtc_order',array('id'=>$_GPC['id']));
  86. // if($set['is_open']==1){
  87. // if($set['is_ej']==2){//不开启二级分销
  88. // $user=pdo_get('zhtc_fxuser',array('fx_user'=>$order['user_id']));
  89. // if($user){
  90. // $userid=$user['user_id'];//上线id
  91. // $money=$order['money']*($set['commission']/100);//一级佣金
  92. // pdo_update('zhtc_user',array('commission +='=>$money),array('id'=>$userid));
  93. // $data6['user_id']=$userid;//上线id
  94. // $data6['son_id']=$order['user_id'];//下线id
  95. // $data6['money']=$money;//金额
  96. // $data6['time']=time();//时间
  97. // $data6['uniacid']=$_W['uniacid'];
  98. // pdo_insert('zhtc_earnings',$data6);
  99. // }
  100. // }else{//开启二级
  101. // $user=pdo_get('zhtc_fxuser',array('fx_user'=>$order['user_id']));
  102. // $user2=pdo_get('zhtc_fxuser',array('fx_user'=>$user['user_id']));//上线的上线
  103. // if($user){
  104. // $userid=$user['user_id'];//上线id
  105. // $money=$order['money']*($set['commission']/100);//一级佣金
  106. // pdo_update('zhtc_user',array('commission +='=>$money),array('id'=>$userid));
  107. // $data6['user_id']=$userid;//上线id
  108. // $data6['son_id']=$order['user_id'];//下线id
  109. // $data6['money']=$money;//金额
  110. // $data6['time']=time();//时间
  111. // $data6['uniacid']=$_W['uniacid'];
  112. // pdo_insert('zhtc_earnings',$data6);
  113. // }
  114. // if($user2){
  115. // $userid2=$user2['user_id'];//上线的上线id
  116. // $money=$order['money']*($set['commission2']/100);//二级佣金
  117. // pdo_update('zhtc_user',array('commission +='=>$money),array('id'=>$userid2));
  118. // $data7['user_id']=$userid2;//上线id
  119. // $data7['son_id']=$order['user_id'];//下线id
  120. // $data7['money']=$money;//金额
  121. // $data7['time']=time();//时间
  122. // $data7['uniacid']=$_W['uniacid'];
  123. // pdo_insert('zhtc_earnings',$data7);
  124. // }
  125. // }
  126. // }
  127. // /////////////////分销/////////////////
  128. message('操作成功', $this->createWebUrl('ddgl', array()), 'success');
  129. } else {
  130. message('操作失败', '', 'error');
  131. }
  132. }
  133. if ($operation == 'refund') {
  134. $id = $_GPC['id'];
  135. include_once IA_ROOT . '/addons/zh_tcwq/cert/WxPay.Api.php';
  136. load()->model('account');
  137. load()->func('communication');
  138. $WxPayApi = new WxPayApi();
  139. $input = new WxPayRefund();
  140. $path_cert = IA_ROOT . "/addons/zh_tcwq/cert/" . 'apiclient_cert_' . $_W['uniacid'] . '.pem';
  141. $path_key = IA_ROOT . "/addons/zh_tcwq/cert/" . 'apiclient_key_' . $_W['uniacid'] . '.pem';
  142. $account_info = $_W['account'];
  143. $refund_order = pdo_get('zhtc_order', array('id' => $id));
  144. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  145. $appid = $res['appid'];
  146. $key = $res['wxkey'];
  147. $mchid = $res['mchid'];
  148. $out_trade_no = $refund_order['out_trade_no'];
  149. $fee = $refund_order['money'] * 100;
  150. $input->SetAppid($appid);
  151. $input->SetMch_id($mchid);
  152. $input->SetOp_user_id($mchid);
  153. $input->SetRefund_fee($fee);
  154. $input->SetTotal_fee($fee);
  155. // $input->SetTransaction_id($refundid);
  156. $input->SetOut_refund_no($id);
  157. $input->SetOut_trade_no($out_trade_no);
  158. $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);
  159. if ($result['result_code'] == 'SUCCESS') {
  160. //退款成功
  161. //更改订单操作
  162. pdo_update('zhtc_order', array('state' => 6), array('id' => $id));
  163. message('退款成功', $this->createWebUrl('ddgl', array()), 'success');
  164. } else {
  165. message($result['return_msg'], '', 'error');
  166. }
  167. }
  168. if ($operation == 'jj') {
  169. $id = $_GPC['id'];
  170. $res = pdo_update('zhtc_order', array('state' => 7), array('id' => $id));
  171. if ($res) {
  172. message('拒绝成功', $this->createWebUrl('ddgl', array()), 'success');
  173. } else {
  174. message('拒绝失败', '', 'error');
  175. }
  176. }
  177. include $this->template('web/ddgl');