gorden 5 месяцев назад
Родитель
Сommit
3b92135d13

+ 10 - 0
app/admin/controller/customer/IndexController.php

@@ -168,6 +168,15 @@ class IndexController extends Curd
                 'member_addtimes' => time()
             ];
             $member['member_extend_json'] = json_encode(['come_from'=>'CUSTOMER']);
+            
+            // 归属门店
+            $user = SysUser::where('user_id',$customer->creator)->first();
+            $belong = [
+                'user_id'=>$customer->creator,
+                'premises' => $user->join_user_dept_id ?? '',
+            ];
+            $member['member_extend_json'] = json_encode(['belong'=>$belong]);
+
             Member::insert($member);
 
             // cert
@@ -211,6 +220,7 @@ class IndexController extends Curd
             // 现金/余额账户
             MemberAccount::insert($accountData);
 
+
             Db::commit();
 
             return json_success("转正式用户成功");

+ 74 - 31
app/admin/controller/order/WholeController.php

@@ -66,8 +66,8 @@ class WholeController extends Curd
         $order = $request->get('order', 'desc');
         $field = $field ?? 'order_addtimes';
 
-        if (in_array($where['order_status_system'],['WAITING','SENDING','RECVING','SIGNED','CONFIRM'])){
-            // $where['order_is_complete'] = 'N';
+        if (!empty($where['order_status_system']) && in_array($where['order_status_system'],['PENDING','WAITING','SENDING','RECVING','SIGNED','CONFIRM'])){
+            $where['order_is_complete'] = 'N';
         }
 
         if (!empty($where['order_status_system']) && $where['order_status_system'] == 'RETURN') {
@@ -96,7 +96,7 @@ class WholeController extends Curd
                 $query->select('orders_return_id','join_return_order_id', 'order_return_status');
             },
             'express' => function($query){
-                $query->select('orders_return_id','join_return_order_id', 'order_return_status');
+                $query->select('join_express_order_id','order_express_type');
             }
         ]);
         foreach ($where as $column => $value) {
@@ -179,13 +179,17 @@ class WholeController extends Curd
             ->toArray();
 
         $express = OrderExpress::where('join_express_order_id', $orderId)->first();
-        if (!empty($express->order_express_code)){
-            $expressCode = explode(':',$express->order_express_code);
-            if(count($expressCode) == 2){
-                $express->order_express_company = $expressCode[0];
-                $express->order_express_code = $expressCode[1];
-            }
+        $premises = '';
+        if($express->order_express_type == '自提'){
+            $premises = $express->order_express_company;
         }
+        // if (!empty($express->order_express_code)){
+        //     $expressCode = explode(':',$express->order_express_code);
+        //     if(count($expressCode) == 2){
+        //         $express->order_express_company = $expressCode[0];
+        //         $express->order_express_code = $expressCode[1];
+        //     }
+        // }
         foreach ($orderSheet as &$item) {
             $item['goods']['goods_cover'] = getenv('STORAGE_DOMAIN') . $item['goods']['goods_cover'];
             if (!empty($item['goods']) && $item['goods']['goods_classify'] == 'PACKAGE') {
@@ -316,14 +320,15 @@ class WholeController extends Curd
             if(isset($orderConfigJson['table'])){
                 $order->table = $orderConfigJson['table'];
             }
-            if(isset($orderConfigJson['express'])){
-                $order->express = $orderConfigJson['express'];
-            }
-            if(isset($orderConfigJson['premises'])){
-                $order->premises = $orderConfigJson['premises'];
-            }
+            // if(isset($orderConfigJson['express'])){
+            //     $order->express = $orderConfigJson['express'];
+            // }
+            // if(isset($orderConfigJson['premises'])){
+            //     $order->premises = $orderConfigJson['premises'];
+            // }
         }
 
+        $order->premises = $premises;
         $data = [
             'order' => $order,
             'sheet' => $orderSheet,
@@ -342,7 +347,10 @@ class WholeController extends Curd
             Db::beginTransaction();
 
             // 修改主订单
-            $this->updateMain($params);
+            // $this->updateMain($params);
+
+            // 修改物流
+            $this->updateExpress($params);
 
             Db::commit();
 
@@ -353,6 +361,40 @@ class WholeController extends Curd
         }
     }
 
+    public function updateExpress($params){
+        $express = OrderExpress::where('join_express_order_id',$params['order_id'])->first();
+        if(!$express){
+            throw new BusinessException('物流信息异常');
+        }
+        if($params['delivery'] == 'PICKUP'){
+            $premises = SysDept::where('dept_category','营业场所')->where('dept_name',$params['dept_premises_id'])->first();
+            $express->order_express_type = '自提';
+            $express->order_express_city = str_replace(',',' ',$premises->dept_city);
+            $express->order_express_address = $premises->dept_address;
+            $express->order_express_mobile = '';
+            $express->order_express_person = '';
+            $express->order_express_telephone = $premises->dept_telephone ?? '';
+            $express->order_express_company = $params['dept_premises_id'];
+        }else if($params['delivery'] == 'LOGISTICS'){
+            $express->order_express_type = '配送';
+            $express->order_express_city = $params['order_express_city'] ?? '';
+            $express->order_express_address = $params['order_express_address'] ?? '';
+            $express->order_express_mobile = $params['order_express_mobile'] ?? '';
+            $express->order_express_person = $params['order_express_person'] ?? '';
+            $express->order_express_telephone = '';
+            $express->order_express_company = '';
+        }
+
+        try{
+            if(($params['delivery'] == 'PICKUP') || ($params['delivery'] == 'LOGISTICS')){
+                $express->save();
+            }
+        }catch(\Exception $e){
+            dump($e->getTrace());
+            throw new BusinessException('修改配送方式失败');
+        }
+    }
+
     public function delete(Request $request): Response
     {
         $params = $request->post();
@@ -448,16 +490,16 @@ class WholeController extends Curd
             $params['benefitId'] = 'BF' . date('YmdHis') . random_string(6, 'up');
 
             // 配送方式
-            if ($params['delivery'] == 'PICKUP') { // 自提
-                $params['order_config_json'] = json_encode([
-                    // 'express' => 'S',
-                    'premises' => $params['dept_premises_id']
-                ]);
-            } else if ($params['delivery'] == 'LOGISTICS') {
-                // $params['order_express_json'] = json_encode([
-                //     'express' => 'Y',
-                // ]);
-            }
+            // if ($params['delivery'] == 'PICKUP') { // 自提
+            //     // $params['order_config_json'] = json_encode([
+            //     //     // 'express' => 'S',
+            //     //     'premises' => $params['dept_premises_id']
+            //     // ]);
+            // } else if ($params['delivery'] == 'LOGISTICS') {
+            //     // $params['order_express_json'] = json_encode([
+            //     //     'express' => 'Y',
+            //     // ]);
+            // }
 
             // 写入主订单
             $this->insertMain($params);
@@ -717,7 +759,7 @@ class WholeController extends Curd
         if ($params['delivery'] == 'PICKUP') { // 自提
             $params['order_config_json'] = json_encode([
                 // 'express' => 'S',
-                'premises' => $params['dept_premises_id']
+                // 'premises' => $params['dept_premises_id']
             ]);
         } else if ($params['delivery'] == 'LOGISTICS') {
             // $params['order_express_json'] = json_encode([
@@ -806,11 +848,11 @@ class WholeController extends Curd
             if (isset($params['order_express_goods'])) {
                 $model->order_express_goods = $params['order_express_goods'];
             }
-            // if (isset($params['order_express_type'])) {
-            //     $model->order_express_type = $params['order_express_type'];
-            // }
+            if (isset($params['order_express_company'])) {
+                $model->order_express_company = $params['order_express_company'];
+            }
             if (isset($params['order_express_code'])) {
-                $model->order_express_code = $params['order_express_company'].':'.$params['order_express_code'];
+                $model->order_express_code = $params['order_express_code'];
             }
             if (isset($params['order_express_city'])) {
                 $model->order_express_city = $params['order_express_city'];
@@ -1042,6 +1084,7 @@ class WholeController extends Curd
             $express->order_express_mobile = $params['order_express_mobile'] ?? '';
             $express->order_express_telephone = $params['order_express_telephone'] ?? '';
             $express->order_express_person = $params['order_express_person'] ?? '';
+            $express->order_express_company = $params['dept_premises_id'] ?? '';
             $express->order_express_addtimes = time();
             $express->save();
         } catch (\Exception $e) {

+ 4 - 0
app/model/Order.php

@@ -47,4 +47,8 @@ class Order extends Model
     {
         return $this->hasOne(OrderReturn::class, 'join_return_order_id', 'order_id');
     }
+
+    public function express(){
+        return $this->hasOne(OrderExpress::class, 'join_express_order_id','order_id');
+    }
 }