zhangguidong 2 years ago
parent
commit
56b7abf6c1

+ 49 - 6
application/admin/controller/Orders.php

@@ -109,20 +109,63 @@ class Orders extends Backend
 
             $data=input('row/a');
             $this->validate($data,[
-                'address_id|发货地'=>['require',],
-                'com_id|物流公司'=>['require',],
+                'address_id|发货地'=>['require',],
+                'province|发货方式'=>['require',],
                 'remark|备注'=>['max:100'],
             ]);
-            Db::startTrans();
-            $address=\app\admin\model\Address::lock(true)->find($data['address_id']);
+
+            $address=\app\admin\model\Address::lock(true)->find($data['address_id'])->toArray();
             if(!$address){
-                $this->error('地址不存在');
+                $this->error('发货地址不存在');
             }
-            $order->makeSendSelf($address,$data['remark']??'',$data['com_id']);
+            $kuayue = [1=>'次日达',2=>'隔日达',3=>'陆运件',4=>'省内次日',5=>'同城次日'];
+            $debangkuaidi = [6=>'大件快递360',7=>'重包入户'];
+            $shunfeng = [8=>'顺丰标快',9=>'顺丰特快'];
+            $kuaidi = [23=>'跨越速运','15'=>'德邦快递','1'=>'顺丰速运'];
+            if(in_array($data['province'],$kuayue)){
+
+            }
+
+
+            Db::startTrans();
+
+            $order->makeSendSelf($address,$data['remark']??'',$data['province']);
             Db::commit();
             $this->success();
         }
     }
+
+    /**
+     * 判断是否是同城
+     **/
+    public function is_same_city(){
+        $address_id = $this->request->request("address_id");
+        $order_id = $this->request->request("order_id");
+
+        $address = \app\admin\model\Address::lock(true)->find($address_id)->toArray();
+        if(!$address){
+            $this->error('发货地址不存在');
+        }
+        $order_address = \app\common\model\OrderAddress::where(['order_id'=>$order_id])->find()->toArray();
+        if(!$order_address){
+            $this->error('订单地址不存在');
+        }
+        $cityId = explode(',',$order_address['area']);
+        $to_city = \app\common\model\Area::where(['id'=>$cityId[1]])->value('name');
+        if(!$to_city){
+            $this->error('未获取订单地址');
+        }
+        $from_city = explode("/",$address['area']);
+        if(isset($from_city[1])){
+            $type = '0';
+            if($to_city == $from_city[1]){
+                $type = '1';
+            }
+            $this->success('获取成功','',['type'=>$type]);
+        }
+        $this->error('发货地址格式错误');
+    }
+
     #详情
     public function detail($ids){
         $voucher=input('voucher');

+ 28 - 25
application/admin/view/orders/send.html

@@ -1,6 +1,8 @@
 <form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <input id="order_id" class="form-control" name="" type="hidden" value="{$row.id}">
     <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('发货地')}:</label>
+        <label class="control-label col-xs-12 col-sm-2">{:__('发货地')}:</label>
         <div class="col-xs-12 col-sm-8">
             <input
                     id="c-name"
@@ -10,37 +12,38 @@
                     data-source="{:url('/address')}"
                     name="row[address_id]"
                     data-multiple="false"
-                    type="text"
                     data-pagination="false"
+                    data-order-by="id desc"
+                    type="text"
                     value=""
             >
         </div>
     </div>
-<!--    <div class="form-group">-->
-<!--        <label class="control-label col-xs-12 col-sm-2">{:__('发货方式')}:</label>-->
-<!--        <div class="col-xs-12 col-sm-8">-->
+    <div class="form-group" style="display: none;" id="province1">
+        <label class="control-label col-xs-12 col-sm-2">{:__('发货方式')}:</label>
+        <div class="col-xs-12 col-sm-8">
 
-<!--            <select class="form-control" name="province" >-->
-<!--                <option value="1" >次日达</option>-->
-<!--                <option value="2" >隔日达</option>-->
-<!--                <option value="3" >陆运件</option>-->
-<!--                <option value="4" >省内次日</option>-->
-<!--                <option value="5" >同城次日</option>-->
-<!--            </select>-->
-<!--        </div>-->
-<!--    </div>-->
-<!--    <div class="form-group">-->
-<!--        <label class="control-label col-xs-12 col-sm-2">{:__('发货方式')}:</label>-->
-<!--        <div class="col-xs-12 col-sm-8">-->
+            <select class="form-control" name="province" >
+                <option value="1" >次日达</option>
+                <option value="2" >隔日达</option>
+                <option value="3" >陆运件</option>
+                <option value="4" >省内次日</option>
+                <option value="5" >同城次日</option>
+            </select>
+        </div>
+    </div>
+    <div class="form-group" style="display: none;" id="province2">
+        <label class="control-label col-xs-12 col-sm-2">{:__('发货方式')}:</label>
+        <div class="col-xs-12 col-sm-8">
 
-<!--            <select class="form-control" name="province" >-->
-<!--                <option value="6" selected>德邦快递-大件快递360</option>-->
-<!--                <option value="7" selected>德邦快递-重包入户</option>-->
-<!--                <option value="8" selected>顺丰速运-顺丰标快</option>-->
-<!--                <option value="9" selected>顺丰速运-顺丰特快</option>-->
-<!--            </select>-->
-<!--        </div>-->
-<!--    </div>-->
+            <select class="form-control" name="province" >
+                <option value="6" selected>德邦快递-大件快递360</option>
+                <option value="7" selected>德邦快递-重包入户</option>
+                <option value="8" selected>顺丰速运-顺丰标快</option>
+                <option value="9" selected>顺丰速运-顺丰特快</option>
+            </select>
+        </div>
+    </div>
 
 <!--    <div class="form-group">-->
 <!--        <label class="control-label col-xs-12 col-sm-2">{:__('物流公司')}:</label>-->

+ 6 - 8
application/common/model/Orders.php

@@ -258,7 +258,6 @@ class Orders extends Model
     }
     public function makeSendSelf(Address $address,$remark,$comId){
         $com=LogisticsCompany::where('id','=',$comId)->find();
-        $orderAddress = OrderAddress::where(['order_id'=>$this->id])->find()->toArray();
         $newData=[
             'com_id'=>$comId,
             'remark'=>$remark,
@@ -270,14 +269,13 @@ class Orders extends Model
             //'trans_no'=>$data['kuaidinum'],
         ];
         $newData = array_filter($newData);
-        $cityId = explode(',',$orderAddress['area']);
-        $toCity = Area::where(['id'=>$cityId[1]])->value('name');
-        $fromCitys = Address::where(['id'=>$address->id])->value('area');
-        $fromCity = explode("/",$fromCitys);
+
+
+
+
         $expType = '';
-        if($toCity == $fromCity[1]){
-            $expType = '同城次日';
-        }
+        $expType = '同城次日';
+
 
         $logistics=$this->logistics()->save($newData);
 

+ 31 - 0
public/assets/js/backend/orders.js

@@ -190,6 +190,37 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
         },
         send: function () {
             Controller.api.bindevent();
+            $(document).on("change", "#c-name", function(){
+                //后续操作
+
+                var address_id = $(this).val();
+                if(!address_id){
+                    $('#province1').fadeOut();
+                    $('#province2').fadeOut();
+                    return false;
+                }
+                $.ajax({
+                    url: 'orders/is_same_city',
+                    data: {address_id: $(this).val(),order_id:$('#order_id').val()},
+                    dataType: 'json',
+                    cache: false,
+                    success: function (row) {
+                        if(!row.code){
+                            Toastr.error(row.msg);
+                        }
+                        if(row.data.type == 1){
+                            $('#province1').fadeIn();
+                            $('#province2').fadeOut();
+                        }
+                        if(row.data.type == 0){
+                            $('#province1').fadeOut();
+                            $('#province2').fadeIn();
+                        }
+                    }, error: function () {
+                        Toastr.error(__('Network error'));
+                    }
+                });
+            });
         },
         tax: function () {
             Controller.api.bindevent();