12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace App\Imports\Order;
- 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 Maatwebsite\Excel\Concerns\ToCollection;
- class phoneOrder implements ToCollection
- {
- /**
- * @param Collection $collection
- */
- 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 getValue($model,$where,$field)
- {
- return $model->where($where)->value($field);
- }
- }
|