123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- namespace app\store\controller;
- use EasyWeChat\Factory;
- use library\Controller;
- use think\Db;
- /**
- * 商城订单退款
- * Class Order
- * @package app\store\controller
- */
- class OrderReturn extends Controller
- {
- protected $table = 'OrderRefund';
- /**
- * 订单列表
- * @auth true
- * @menu true
- */
- public function index()
- {
- $query = $this->_query($this->table);
- $this->sh_status_desc = ['待审核','审核通过','审核拒绝'];
- $this->refund_state_desc = ['未退款','待退款','已退款','退款失败'];
- $where = [];
- if($this->request->request('tel'))$where[]= ['u.phone','like','%'.$this->request->request('tel').'%'];
- if($this->request->request('user_name'))$where[]= ['u.name','like','%'.$this->request->request('user_name').'%'];
- if($this->request->request('order_no')) $where[]= ['o.order_no','like','%'.$this->request->request('order_no').'%'];
- $this->sel_ck_status = $this->request->request('sel_ck_status',-1);
- $this->refund_state = $this->request->request('refund_state',-1);
- if($this->sel_ck_status > -1 ) $where[]= ['r.ck_status','=',$this->request->request('sel_ck_status')];
- if($this->refund_state > -1 ) $where[]= ['r.refund_state','=',$this->request->request('refund_state')];
- $query->alias('r')
- ->field('r.* , u.name as user_name ,u.phone,o.price_total,o.price_express,o.order_no')
- ->join('store_member u',' r.uid = u.id ','LEFT')
- ->join('store_order o',' o.id = r.order_id ','LEFT');
- if(!empty($where)) $query->where($where);
- $query ->order('r.id desc')->page();
- }
- /**
- * 订单详情
- * @auth true
- * @menu true
- */
- public function detail()
- {
- $this->title = '订单详情';
- $order_id = input('id');
- $refund_reason = Db::table('order_refund_cause')
- ->field('id,title')
- ->where(['status'=>1])
- ->order('sort desc , id asc')
- ->select();
- $detail = Db::table('order_refund')
- ->alias('r')
- ->field('r.* , u.name as user_name ,u.phone,o.price_total,o.price_express,o.order_no,o.pro_info')
- ->join('store_member u',' r.uid = u.id ','LEFT')
- ->join('store_order o',' o.id = r.order_id ','LEFT')
- ->where('r.id',$order_id)
- ->find();
- $this->assign('detail',$detail);
- $this->assign('refund_reason',array_column($refund_reason,null,'id'));
- $this->fetch('detail');
- }
- /**
- * 订单发货
- * @auth true
- * @menu true
- */
- public function deliver()
- {
- $this->title = '发货';
- $this->express_company = Db::table('store_express_company')->field('id,express_title')->select();
- $this->_form($this->table,'deliver');
- }
- /**
- * 表单数据处理
- * @auth true
- * @menu true
- * @param array $data
- */
- protected function _form_filter(&$data)
- {
- if ($this->request->isPost() && $this->request->action() == 'deliver') {
- $express_company = Db::table('store_express_company')->field('id,express_title')->find($data['express_company_id']);
- $data['express_company_title'] = $express_company['express_title'] ? $express_company['express_title'] : '';
- $data['express_send_at'] = date("Y-m-d H:i:s");
- $data['express_state'] = 1;
- }
- }
- public function aduit()
- {
- $id = input('post.id');
- $ck_status = input('post.ck_status',0);
- $refund_money = input('post.refund_money');
- $ck_remark = input('post.ck_remark');
- if ($ck_status == 1 && (!is_numeric($refund_money) || $refund_money < 0)) {
- echo 0;die();
- }
- Db::table('order_refund')->where(['id' => $id])->update(['ck_status' => $ck_status, 'refund_money' => $refund_money, 'ck_remark' => $ck_remark, 'ck_time' => date('Y-m-d H:i:s')]);
- echo 1;
- die();
- }
- public function refund()
- {
- $id = input('post.id');
- $refund_info = Db::table('order_refund')->find($id);
- $order_info = Db::table('store_order')->find($refund_info['order_id']);
- if ($order_info['price_total'] < $refund_info['apply_money']) $this->error('退款金额错误');
- $rufund_success = 0;
- Db::startTrans();
- try {
- $app = Factory::payment(config('app.wx_pay'));
- $result = $app->refund->byOutTradeNumber($order_info['pay_no'], $order_info['refund_no'], $order_info['price_total']*100, $refund_info['amount']*100, [
- 'refund_desc' => '订单退款',
- ]);
- if($result['return_result']=='SUCCESS' && $result['result_code']=='SUCCESS') $rufund_success = 1;
- $return_json=json_encode($result);
- if ($rufund_success == 1) {
- Db::commit();
- $this->success('退款成功!');
- } else {
- Db::rollback();// 回滚事务
- $this->error('退款失败1');
- }
- }catch (\UnexpectedValueException $e) {
- Db::rollback();// 回滚事务
- $this->error('退款失败');
- }
- }
- }
|