123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace App\Imports\Order;
- use AlibabaCloud\Gpdb\V20160503\DeleteDatabase;
- use App\Models\Docter;
- 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;
- use Maatwebsite\Excel\Concerns\ToCollection;
- use Maatwebsite\Excel\Concerns\WithHeadingRow;
- use Maatwebsite\Excel\Concerns\WithBatchInserts;
- use Maatwebsite\Excel\Concerns\WithChunkReading;
- use Maatwebsite\Excel\Concerns\WithProgressBar;
- class chatOrder implements ToCollection,WithBatchInserts,WithChunkReading
- {
- /**
- * @param array $row
- *
- * @return \Illuminate\Database\Eloquent\Model|null
- */
- public function collection(Collection $collection)
- {
- foreach ($collection as $row) {
- if ($row[0] == '订单编号') continue;
- //订单状态
- $status = Order::getStatus();
- //订单状态
- $paystatus = Order::getPayStatus();
- $pay_status = array_search($row[18], $paystatus);
- $order_status = array_search($row[9], $status);
- if($row[9] == '已过期') $order_status = 6;
- if($row[18] == '未付款' || empty($row[18])) $pay_status = 1;
- $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;
- }
- }
- return null;
- }
- public function startRow(): int
- {
- return 2;
- }
- public function batchSize(): int
- {
- return 1000;
- }
- public function chunkSize(): int
- {
- return 1000;
- }
- public function getValue($model,$where,$field)
- {
- return $model->where($where)->value($field);
- }
- }
|