Quellcode durchsuchen

图文,电话订单数据修复

wanghaijun vor 4 Jahren
Ursprung
Commit
be0fed4ee4

+ 1 - 0
app/Community/Controllers/DocterChatController.php

xqd
@@ -71,6 +71,7 @@ class DocterChatController extends AdminController
         $grid->filter(function (Grid\Filter $filter){
             $filter->disableIdFilter();
             $filter->column(1/2, function ($filter) {
+                $filter->like('order_sn','订单号');
                 $filter->like('patient.phone','电话');
                 $filter->like('patient.name','患者名称');
                 $filter->equal('order_status','订单状态')->select(Order::$_order_status);

+ 25 - 59
app/Imports/Order/chatOrder.php

xqd xqd xqd
@@ -8,6 +8,7 @@ use App\Models\Order;
 use App\Models\OrderPatient;
 use App\Models\Organization;
 use App\Models\Patient;
+use App\Models\UserBalanceLog;
 use App\User;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Log;
@@ -29,34 +30,7 @@ class chatOrder implements ToCollection,WithBatchInserts,WithChunkReading
 
         foreach ($collection as $row) {
             if ($row[0] == '订单编号') continue;
-            //检查是否有该订单
-            $isHave = $this->getValue(new Order(), ['order_sn' => $row[0]], 'id');
-            if ($isHave) continue;
 
-            $user_id = $this->getValue(new User(), ['phone' => $row[3]], 'id');
-            if (empty($user_id)) {
-                echo $row[3] . '用户缺失' . PHP_EOL;
-                continue;
-            }
-            //患者信息
-            $patientInfo = Patient::where(['name' => $row[2]])->first();
-            if (empty($patientInfo)) {
-//                $pp = Patient::where('user_id',$user_id)->get()->toArray();
-                echo $row[2] . '患者缺失' . PHP_EOL;
-                continue;
-            }
-            $org_name = substr($row[6],18);
-            $org_id = $this->getValue(new Organization(), ['name' => $org_name], 'id');
-            if (empty($org_id)) {
-                echo $row[6] . '机构缺失' . PHP_EOL;
-                continue;
-            }
-
-            //如果没有用户不导入该订单
-            if (empty($user_id)) {
-                Log::info('订单没有用户信息,订单编号: ' . $row[0] . PHP_EOL);
-                continue;
-            }
 
             //订单状态
             $status = Order::getStatus();
@@ -68,43 +42,35 @@ class chatOrder implements ToCollection,WithBatchInserts,WithChunkReading
             if($row[18] == '未付款' || empty($row[18])) $pay_status = 1;
 
 
-            $docter_id = $this->getValue(new Docter(), ['name' => $row[4]], 'id');
-            $evaluate = $row[10] == '已评价' ? 1 : 0;
             $pay_types = [1 => '微信支付', 2 => '余额支付', 3 => '服务包支付'];
             //支付方式
             $payType = array_search($row[16], $pay_types) + 1;
             if ($payType == 1) $payType = 2;
+            $order = Order::where('order_sn',$row[0])->first();
+            if(!empty($order)){
+                $orderInfo = [
+                    'order_sn' => $row[0],
+                    'order_status' => $order_status,
+                    'order_notes' => '',
+                    'payment_status'=>$pay_status,
+                ];
+                $old_order_status = intval($order->order_status);
+                $old_notice = intval($order->order_notes);
+                if($old_order_status == 5 && ($old_notice == '医生超时未接单自动取消'  || $old_notice == '医生超时未接单自动取消') ){
+                    $log = UserBalanceLog::where(['relation_id'=>$order->id])->first();
+                    if(!empty($log)){
+                        $user = \App\Models\User::where('id',$order->user_id)->first();
+                        if($user->balance >0){
+                            User::where('id',$order->user_id)->decrement('balance',$log->change_balance);
+                            UserBalanceLog::where('id',$log->id)->delete();
+                        }
+                    }
+                    Order::where('id',$order->id)->update($orderInfo);
+                }
+            }  else {
+                continue;
+            }
 
-            $orderInfo = [
-                'order_sn' => $row[0],
-                'patient_id' => $patientInfo->id,
-                'user_id' => $user_id,
-                'docter_id' => $docter_id,
-                'order_status' => $order_status,
-                'organization_id' => $org_id,
-                'is_evaluate' => $evaluate,
-                'is_discount' => $row[11],
-                'total_amount' => $row[12] * 100,
-                'discount_amount' => $row[13] * 100,
-                'payment_amount' => $row[15] * 100,
-                'payment_type' => $payType,
-                'payment_status' => $pay_status,
-                'product_type' => 2,
-                'created_at' => $row[19],
-            ];
-            $order = Order::create($orderInfo);
-            $orderId = $order['id'];
-
-            $orderPatient = [
-                'patient_id' => $patientInfo->id,
-                'name' => $row[0],
-                'order_id' => $orderId,
-                'patient_id' => $patientInfo->id,
-                'address' => $patientInfo->address,
-                'sex' => $patientInfo->sex,
-                'organization_id' => $org_id,
-            ];
-            OrderPatient::insert($orderPatient);
         }
         return null;
     }

+ 27 - 57
app/Imports/Order/phoneOrder.php

xqd xqd xqd
@@ -7,6 +7,7 @@ use App\Models\Order;
 use App\Models\OrderPatient;
 use App\Models\Organization;
 use App\Models\Patient;
+use App\Models\UserBalanceLog;
 use App\User;
 use Illuminate\Support\Collection;
 use Maatwebsite\Excel\Concerns\ToCollection;
@@ -21,28 +22,6 @@ class phoneOrder implements ToCollection
         foreach ($collection as $row){
             if ($row[0] == '订单编号') continue;
 
-            //检查是否有该订单
-            $isHave = $this->getValue(new Order(), ['order_sn' => $row[0]], 'id');
-            if ($isHave) continue;
-            //支付状态(1.待付款 2.已付款 3.退款中 4.已退款 5.待退款)
-            //如果没有用户不导入该订单
-            $user_id = $this->getValue(new User(), ['phone' => $row[3]], 'id');
-            if (empty($user_id)) {
-                echo $row[3] . '用户缺失' . PHP_EOL;
-                continue;
-            }
-            //患者信息
-            $patientInfo = Patient::where(['name' => $row[2]])->first();
-            if (empty($patientInfo)) {
-                echo $row[2] . '患者缺失' . PHP_EOL;
-                continue;
-            }
-            $org_name = substr($row[6],18);
-            $org_id = $this->getValue(new Organization(), ['name' => $org_name], 'id');
-            if (empty($org_id)) {
-                echo $row[6] . '机构缺失' . PHP_EOL;
-                continue;
-            }
 
             //订单状态
             $status = Order::getStatus();
@@ -50,47 +29,38 @@ class phoneOrder implements ToCollection
             $paystatus = Order::getPayStatus();
             $pay_status = array_search($row[18], $paystatus);
             $order_status = array_search($row[9], $status);
-
-            if( $row[18] == '已退款') $pay_status = 4;
             if($row[9] == '已过期') $order_status = 6;
+            if($row[18] == '未付款' || empty($row[18])) $pay_status = 1;
+
 
-            $docter_id = $this->getValue(new Docter(), ['name' => $row[4]], 'id');
-            $evaluate = $row[10] == '已评价' ? 1 : 0;
             $pay_types = [1 => '微信支付', 2 => '余额支付', 3 => '服务包支付'];
             //支付方式
             $payType = array_search($row[16], $pay_types) + 1;
             if ($payType == 1) $payType = 2;
-
-            $orderInfo = [
-                'order_sn' => $row[0],
-                'patient_id' => $patientInfo->id,
-                'user_id' => $user_id,
-                'docter_id' => $docter_id,
-                'order_status' => $order_status,
-                'organization_id' => $org_id,
-                'is_evaluate' => $evaluate,
-                'is_discount' => $row[11],
-                'total_amount' => intval($row[12]) * 100,
-                'discount_amount' => intval($row[13]) * 100,
-                'payment_amount' => intval($row[15]) * 100,
-                'payment_type' => $payType,
-                'payment_status' => $pay_status,
-                'product_type' => 1,
-                'created_at' => $row[19],
-            ];
-            $order = Order::create($orderInfo);
-            $orderId = $order['id'];
-
-            $orderPatient = [
-                'patient_id' => $patientInfo->id,
-                'name' => $row[2],
-                'order_id' => $orderId,
-                'patient_id' => $patientInfo->id,
-                'address' => $patientInfo->address,
-                'sex' => $patientInfo->sex,
-                'organization_id' => $org_id,
-            ];
-            OrderPatient::insert($orderPatient);
+            $order = Order::where('order_sn',$row[0])->first();
+            if(!empty($order)){
+                $orderInfo = [
+                    'order_sn' => $row[0],
+                    'order_status' => $order_status,
+                    'order_notes' => '',
+                    'payment_status'=>$pay_status,
+                ];
+                $old_order_status = intval($order->order_status);
+                $old_notice = intval($order->order_notes);
+                if($old_order_status == 5 && ($old_notice == '医生超时未接单自动取消'  || $old_notice == '医生超时未接单自动取消') ){
+                    $log = UserBalanceLog::where(['relation_id'=>$order->id])->first();
+                    if(!empty($log)){
+                        $user = \App\Models\User::where('id',$order->user_id)->first();
+                        if($user->balance >0){
+                            User::where('id',$order->user_id)->decrement('balance',$log->change_balance);
+                            UserBalanceLog::where('id',$log->id)->delete();
+                        }
+                    }
+                    Order::where('id',$order->id)->update($orderInfo);
+                }
+            }  else {
+                continue;
+            }
         }
         return null;
     }