qifengquan 2 سال پیش
والد
کامیت
9163264092
2فایلهای تغییر یافته به همراه180 افزوده شده و 1 حذف شده
  1. 1 1
      app/data/controller/shop/Order.php
  2. 179 0
      app/data/controller/shop/refund.php

+ 1 - 1
app/data/controller/shop/Order.php

@@ -69,7 +69,7 @@ class Order extends Controller
             $admin_id['admin_id']=AdminService::getUserId();
         }
         // 状态数据统计
-        $this->total = ['t0' => 0, 't1' => 0, 't2' => 0, 't3' => 0, 't4' => 0, 't5' => 0, 't6' => 0, 'ta' => 0];
+        $this->total = ['t0' => 0, 't1' => 0, 't2' => 0, 't3' => 0, 't4' => 0, 't5' => 0, 't6' => 0, 't7' => 0, 'ta' => 0];
         foreach (ShopOrder::mk()->where($admin_id)->field('status,count(1) total')->group('status')->cursor() as $vo) {
             [$this->total["t{$vo['status']}"] = $vo['total'], $this->total["ta"] += $vo['total']];
         }

+ 179 - 0
app/data/controller/shop/refund.php

@@ -0,0 +1,179 @@
+<?php
+
+namespace app\data\controller\shop;
+
+use app\data\model\DataUser;
+use app\data\model\ShopGoods;
+use app\data\model\ShopOrder;
+use app\data\model\ShopOrderPay;
+use app\data\model\ShopOrderSend;
+use app\data\service\OrderService;
+use app\data\service\PaymentService;
+use app\data\service\UserAdminService;
+use app\data\controller\api\business\order;
+use think\admin\Controller;
+use think\admin\service\AdminService;
+
+class refund extends Controller
+{
+    /**
+     * 支付方式
+     * @var array
+     */
+    protected $payments = [];
+
+    /**
+     * 控制器初始化
+     */
+    protected function initialize()
+    {
+        parent::initialize();
+        //$this->payments = PaymentService::getTypeAll();
+        $this->payments = [
+            [
+                'name'=>'支付宝支付'
+            ],
+            [
+                'name'=>'微信支付'
+            ]
+        ];
+//        // 读取支付通道配置
+//        $query = BaseUserPayment::mk()->where(['status' => 1, 'deleted' => 0]);
+//        //$query->whereIn('code', str2arr($payments))->whereIn('type', PaymentService::getTypeApi($this->type));
+//        $result = $query->order('sort desc,id desc')->column('type,code,name,cover,content,remark', 'code');
+//        foreach ($result as &$vo) $vo['content'] = ['voucher_qrcode' => json_decode($vo['content'])->voucher_qrcode ?? ''];
+//        $this->payments2 = array_values($result);
+//        dump($this->payments2);
+    }
+    /**
+     * 商品数据管理
+     * @auth true
+     * @menu true
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function index()
+    {
+        $this->title = '商品退款中';
+        if(AdminService::getUserId()==10000){
+            $admin_id = [];
+        }
+        else{
+            $admin_id['admin_id']=AdminService::getUserId();
+        }
+
+        $where = [
+            'admin_id' => $admin_id,
+            'deleted_status' => 0,
+            'status' => 7
+        ];
+
+        $query = ShopOrder::mQuery()->where($where);
+
+        //用户名账号查询
+        $db = DataUser::mQuery()->like('phone|nickname#user_keys')->db();
+//        print_r($db->getOptions('where'));
+//        exit;
+        if ($db->getOptions('where')) $query->whereRaw("uuid in {$db->field('id')->buildSql()}");
+        //支付方式查询
+        $query->like('order_no');
+        $query->equal('payment_type');
+
+        $query->order('id desc')->page();
+
+    }
+    /**
+     * 订单列表处理
+     * @param array $data
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    protected function _index_page_filter(array &$data)
+    {
+        UserAdminService::buildByUid($data);
+        UserAdminService::buildByUid($data, 'puid1', 'from');
+        OrderService::buildData($data);
+        foreach ($data as &$vo) {
+            if (!is_null($vo['payment_type']) and '' != $vo['payment_type']) {
+                $vo['payment_name'] = PaymentService::name($vo['payment_type']);
+            }
+        }
+    }
+    /**
+     * 退款
+     */
+    public function refund(){
+//      print_r($this->_vali([
+//            'refund_status.require' => '状态值为空!',
+//            'id.require' => '状态值为空!',
+//            'type.require' => '状态值为空!'
+//        ]));
+        $this->refuse_dispose($this->_vali([
+            'refund_status.require' => '状态值为空!',
+            'id.require' => '状态值为空!',
+            'type.require' => '状态值为空!'
+        ]));
+
+        exit;
+//        Order::examine_refund($type,$order_id,$type);
+    }
+    /**
+     * 拒绝退款原因
+     */
+    public function refuse()
+    {
+        ShopOrder::mForm('refuse_form', 'id');
+    }
+    /**
+     * 拒绝退款处理
+     */
+    protected function _refuse_form_filter(array &$vo)
+    {
+        if ($this->request->isPost()) {
+
+            $this->refuse_dispose($vo);
+
+        }
+    }
+    /**
+     * 退款处理
+     */
+    public function refuse_dispose($data){
+        $admin_id['admin_id']=AdminService::getUserId();
+        $info = ShopOrder::mk()->where(['id'=>$data['id'],'admin_id'=>$admin_id['admin_id'],'status'=>7])->find();
+        $pay_money  = ShopOrderPay::mk()->where(['status' => 2, 'pay_no'=>$info['payment_trade']])->value('money');
+
+        if(empty($info)){
+            $this->error('订单信息有误');
+        }
+        else{
+            // 退款操作
+            if($data['type']==1){
+                //同意退款
+                if($info['payment_type']=='支付宝支付') {
+                    $result = json_decode(order::refund_order($info['payment_trade'], $info['refund_money']), true);
+                }
+                if($info['payment_type']=='微信支付') {
+                    $result = json_decode(order::wxrefund_order($info['payment_trade'], $info['refund_money'],$pay_money), true);
+                }
+                if($result) {
+                    ShopOrder::mk()->where(['id' => $data['id'], 'admin_id' => $admin_id['admin_id']])->save(['status' => 8, 'refund_status' => 2, 'dk_time' => date('Y-m-d H:i:s')]);
+                    $this->success('已同意退款,支付金额原路退回');
+                }
+                else{
+                    $this->error('金额未退回查看支付账户');
+                }
+            }
+            //统一退货
+            else {
+                ShopOrder::mk()->where(['id'=>$data['id'],'admin_id'=>$admin_id['admin_id']])->save(['status' => 4,'refund_status'=>3,'refuse_reason'=>$data['refuse_reason'],'dk_time'=>date('Y-m-d H:i:s')]);
+                //不同意退款
+                $this->success('已拒绝退款');
+            }
+
+        }
+    }
+
+}