544782275@qq.com il y a 3 ans
Parent
commit
bc6c250b18

+ 47 - 0
application/store/controller/Order.php

@@ -324,4 +324,51 @@ class Order extends Controller
         }
 
     }
+    /**
+     * 立即退款
+     * @auth true
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function order_refund()
+    {
+        $id = $this->app->request->get('id');
+        $this->assign('id', $id);
+        $post = $this->app->request->post();
+        if (isset($post['id']) && $post['id']) {
+            $order_info = Db::name($this->table)->where('id', $post['id'])->find();
+            if($post['amount'] < 0 || $post['amount'] > $order_info['price_total']){
+                $this->error('退款金额错误');
+            }
+            $refund_success = 0;
+            if($order_info['pay_type'] == 1){    //微信退款
+                $app = Factory::payment(config('app.wx_pay'));
+                $result = $app->refund->byOutTradeNumber($order_info['pay_no'], get_order_sn(),$order_info['price_total']*100, $post['amount']*100, [
+                    // 可在此处传入其他参数,详细参数见微信支付文档
+                    'refund_desc' => '',
+                ]);
+                if($result['return_code']=='SUCCESS' && $result['result_code']=='SUCCESS'){
+                    $refund_success = 1;
+                }
+            }elseif($order_info['pay_type'] == 2){
+                $result = Alipay::ali_refund($order_info['pay_no'],$post['amount']);
+                if($result){
+                    $refund_success = 1;
+                }
+            }
+            if($refund_success == 1){
+                //更改退款状态
+                Db::name('store_order')->where('id',$id)->update(array('refund_at'=>date('Y-m-d H:i:s'),'status'=>4,'refund_price'=>$post['amount']));
+                $this->success('退款成功');
+            }else{
+                $this->error('退款失败');
+            }
+        } else {
+            $this->_form($this->table, 'order_rufund');
+        }
+
+    }
 }

+ 3 - 0
application/store/view/order/index.html

@@ -121,6 +121,9 @@
                 {if isset($a.engineer_id) && $a.engineer_id > 0 && $vo.status == 0 && $vo.is_self_build == 1 && $vo.worker_id == $a.engineer_id}
                 <a data-title="修改金额" class="layui-btn layui-btn-sm layui-bg-red " data-modal='{:url("edit_order")}?id={$vo.id}'>修改金额</a>
                 {/if}
+                {if isset($a.engineer_id) && $a.engineer_id > 0 && ($vo.status == 1 || $vo.status == 2) && $vo.worker_id == $a.engineer_id}
+                <a data-title="立即退款" class="layui-btn layui-btn-sm layui-bg-orange" data-modal='{:url("order_refund")}?id={$vo.id}'>立即退款</a>
+                {/if}
             </td>
         </tr>
         {/foreach}

+ 59 - 0
application/store/view/order/order_rufund.html

@@ -0,0 +1,59 @@
+<div style="padding: 20px; background-color: #F2F2F2;">
+    <div class="layui-row layui-col-space15">
+        <div class="layui-col-md12">
+            <div class="layui-card" style="height: 160px;">
+                <div class="layui-card-header">退款信息</div>
+                <div class="layui-card-body">
+                    <div class="layui-col-md6">支付金额:{$data.price_total}</div>
+                    <div class="layui-col-md6">申请退还金额:{$data.refund.amount}</div><hr />
+                    {if $data.refund.user_images}
+                    <div class="layui-col-md6">雇主端举证图片:
+                        {foreach $data.refund.user_images as $v}
+                        <img data-tips-image style="width:20px;height:20px" src="{$v|default=''}" class="margin-right-5 text-top">
+                        {/foreach}
+                    </div>
+                    <div class="layui-col-md6">雇主端举证文字:{$data.refund.user_wordage}</div><hr />
+                    {/if}
+                    {if $data.refund.worker_images}
+                    <div class="layui-col-md6">服务商举证图片:
+                        {foreach $data.refund.worker_images as $v}
+                        <img data-tips-image style="width:20px;height:20px" src="{$v|default=''}" class="margin-right-5 text-top">
+                        {/foreach}
+                    </div>
+                    <div class="layui-col-md6">服务商举证文字:{$data.refund.worker_wordage}</div>
+                    {/if}
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+
+<form onsubmit="return false;" action="{:request()->url()}" data-auto="true" method="post" class='layui-form layui-card' autocomplete="off" style="padding: 0 20px;">
+
+    <div class="layui-card-body">
+        <div class="layui-row margin-bottom-15">
+            <label class="layui-col-xs2 think-form-label">退款单号</label>
+            <label class="layui-col-xs10">
+                <input name="order_no" required readonly value='{$data.order_no}' placeholder="请输入退款单号" class="layui-input">
+            </label>
+        </div>
+        <div class="layui-row margin-bottom-15">
+            <label class="layui-col-xs2 think-form-label">退款金额</label>
+            <label class="layui-col-xs10">
+                <input name="amount" required value='{$data.refund.amount}' placeholder="请输入退款金额" lay-verify="number" class="layui-input">
+            </label>
+        </div>
+        <div class="layui-row margin-bottom-15">
+            <label class="layui-col-xs2 think-form-label">同意退款理由</label>
+            <label class="layui-col-xs10">
+                <input name="intervene_remark" required value='{$data.refund.intervene_remark}' placeholder="请输入同意退款理由" class="layui-input">
+            </label>
+        </div>
+    </div>
+    <div class="hr-line-dashed"></div>
+    <div class="layui-form-item text-center">
+        <input type='hidden' value='{$id}' name='id'>
+        <button class="layui-btn" type='submit'>立即退款</button>
+        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消吗?" data-close>取消退款</button>
+    </div>
+</form>