chenyunyun 2 years ago
parent
commit
e4924d4874

+ 41 - 15
application/admin/controller/Cannelorder.php

@@ -2,9 +2,12 @@
 
 namespace app\admin\controller;
 
+use app\admin\model\User;
+use app\admin\model\UserRelations;
 use app\common\controller\Backend;
 use fast\Random;
 use think\Db;
+use think\Exception;
 
 /**
  * 店铺注销订单
@@ -115,21 +118,20 @@ class Cannelorder extends Backend
      */
     public function confirm_amount($ids)
     {
-
         $row = $this->model->get(['id' => $ids]);
         if (!$row) {
             $this->error(__('No Results were found'));
         }
 
         if ($this->request->isPost()) {
-            $refund_money = $this->request->post('refund_money');
-            $param = [
-                'refund_money' => $refund_money,
-                'status' => 3,
-                'id' => $ids,
-            ];
-
-            $this->model->allowField(true)->isUpdate(true)->save($param);
+            $params = $this->request->post('row/a');
+            if (empty($params)) {
+                $this->error(__('Parameter %s can not be empty', ''));
+            }
+            $params = $this->preExcludeFields($params);
+            $params['status'] = 3;
+
+            $this->model->allowField(true)->isUpdate(true)->save($params);
             $this->success("成功", null, ['id' => $ids]);
         }
         $this->view->assign("row", $row->toArray());
@@ -146,14 +148,38 @@ class Cannelorder extends Backend
             $this->error(__('No Results were found'));
         }
         if ($this->request->isAjax()) {
-            $param = [
-                'status' => 4,
-                'id' => $ids,
-            ];
 
-            $this->model->allowField(true)->isUpdate(true)->save($param);
+            Db::startTrans();
+            try {
+                // 修改 注销订单状态
+                $param = [
+                    'status' => 4,
+                    'id' => $ids,
+                ];
+                $this->model->allowField(true)->isUpdate(true)->save($param);
+
+                // 修改商户信息
+                $user_param = [
+                    'cancel_shop' => 1,
+                    'id' => $row['c_user_id'],
+                ];
+                $user_model = new User();
+                $user_model->allowField(true)->isUpdate(true)->save($user_param);
+
+                // 修改b端 - c端 关系
+                $user_re_param = ['status' => 2];
+                $user_re_model = new UserRelations();
+                $user_re_model->allowField(true)->isUpdate(true)->where('c_user_id', $row['c_user_id'])->save($user_re_param);
+
+                Db::commit();
+                $this->success("成功", null, ['id' => $ids]);
+                return;
+            } catch (Exception $e) {
+                Db::rollback();
+                $this->error('失败');
+                return;
+            }
 
-            $this->success("成功", null, ['id' => $ids]);
         }
     }
 

+ 9 - 15
application/admin/view/cannelorder/confirm_amount.html

@@ -1,21 +1,15 @@
 <form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
     {:token()}
     <input type="hidden" name="row[id]" value="{$row.id}">
-    <table class="table table-striped">
-        <tbody>
 
-        {if $Think.get.dialog}
-        <tr>
-            <td>应退金额</td>
-            <td>
-                <div class="input-group">
-                    <input name="refund_money" class="form-control" value=""/>
-                </div>
-            </td>
-        </tr>
-        {/if}
-        </tbody>
-    </table>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Refund_money')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-refund_money" data-rule="required,diy_refund_money" class="form-control" name="row[refund_money]" type="text" value="{if $row.refund_money!='0.00'}{$row.refund_money|htmlentities}{/if}">
+        </div>
+    </div>
+
     <div class="hide layer-footer">
         <label class="control-label col-xs-12 col-sm-2"></label>
         <div class="col-xs-12 col-sm-8">
@@ -26,5 +20,5 @@
             </button>
         </div>
     </div>
+</form>
 
-</form>

+ 13 - 0
public/assets/js/backend/cannelorder.js

@@ -99,6 +99,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                 {
                                     name: 'confirm_amount',
                                     title: __('确认清点金额'),
+                                    extend:'data-area=["660px","350px"]',
                                     classname: 'btn btn-xs btn-primary btn-dialog',
                                     icon: 'fa fa-leaf',
                                     url: 'cannelorder/confirm_amount',
@@ -265,6 +266,18 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
         },
         confirm_amount: function () {
             Controller.api.bindevent();
+            $.validator.config({
+                rules: {
+                    diy_refund_money: function (element) {
+                        //如果直接返回文本,则表示失败的提示文字
+                        //如果返回true表示成功
+                        //如果返回Ajax对象则表示远程验证
+                        if (!element.value.toString().match(/(^[0-9]+$)|(^[0-9]+[\.]{1}[0-9]{1,2}$)/)) {
+                            return '请输入正确的金额';
+                        }
+                    }
+                }
+            });
         },
         confirm_refund: function () {
             Controller.api.bindevent();