diff --git a/common/models/ProductOrder.php b/common/models/ProductOrder.php index bf897f0..b5b6e5d 100644 --- a/common/models/ProductOrder.php +++ b/common/models/ProductOrder.php @@ -42,6 +42,12 @@ class ProductOrder extends \common\modelsgii\ProductOrder return $this->hasOne(DoctorInfo::class, ['su_id' => 'su_id']); } + //关联医生 + public function getDoctorId() + { + return $this->hasOne(DoctorInfo::class, ['id' => 'su_id']); + } + //关联快递单号 public function getExpressNos() { @@ -85,7 +91,7 @@ class ProductOrder extends \common\modelsgii\ProductOrder //导出 public static function inventory($params,$store_id) { - + if($store_id){ $where['store_id'] = $store_id; } @@ -110,50 +116,30 @@ class ProductOrder extends \common\modelsgii\ProductOrder // return $data; //查询数据 - $list = ProductOrder::find()->where($where)->andWhere($andWhere)->with(['prescription', 'doctor','store'])->asArray()->all(); + $list = ProductOrder::find()->where($where)->andWhere($andWhere)->with(['prescription', 'doctor', 'doctorId','store'])->asArray()->all(); //把结果按照显示顺序存到返回的数组中 if (!empty($list)) { foreach ($list as $key => $value) { - $ProductOrder=self::getSHH($value['order_no']); - if (!empty($ProductOrder)) { - $inventory[$key]['epl_order_no'] = "\t".$ProductOrder['transaction_id']??'暂无';//易票联订单号 - } else { - $inventory[$key]['epl_order_no'] = "\t".'暂无';//易票联订单号 - } + try { - $inventory[$key]['order_no'] = "\t" . $value['order_no'];//订单号 - $inventory[$key]['store'] = "\t" . $value['store']['name'];//诊所名称 - $content = $value['prescription']; - $item = []; - if ($content['prescription_type']==1 ||$content['prescription_type']==3){//中药 配方颗粒 + $ProductOrder=self::getSHH($value['order_no']); - $repice = json_decode($content['content'], true)['repice']; - foreach ($repice as $val) { - if (!isset($item['drug_name'])) { - $item['drug_name'] = ''; - } - if (!isset($item['specification'])) { - $item['specification'] = ''; - } - if (!isset($item['source'])) { - $item['source'] = ''; - } - if (!isset($item['unit_price'])) { - $item['unit_price'] = ''; - } - foreach (json_decode($val['content'], true) as $vv) { - $item['drug_name'] .= array_key_exists('drug_name', $vv)? $vv['drug_name'] . '|': '获取失败' . '|'; - $item['specification'] .= array_key_exists('specification', $vv)? $vv['specification'] . '|' : '无' . '|'; - $item['source'] .= array_key_exists('source', $vv)? $vv['source'] . '|' : '无' . '|'; - $item['unit_price'] .= $val['total_price'] . '|' ?? '无' . '|'; - } + if (!empty($ProductOrder)) { + $inventory[$key]['epl_order_no'] = "\t".$ProductOrder['transaction_id']??'暂无';//易票联订单号 + } else { + $inventory[$key]['epl_order_no'] = "\t".'暂无';//易票联订单号 } - } else {//西药 - $repice = json_decode($content['content'], true)['repice']; - if(!empty($repice)){ + $inventory[$key]['order_no'] = "\t" . $value['order_no'];//订单号 + $inventory[$key]['store'] = "\t" . $value['store']['name'];//诊所名称 + $content = $value['prescription']; + $item = []; + $prescriptionType = $content['prescription_type']?? 0; + if ($prescriptionType==1 ||$prescriptionType==3){//中药 配方颗粒 + + $repice = json_decode($content['content'], true)['repice']; foreach ($repice as $val) { if (!isset($item['drug_name'])) { $item['drug_name'] = ''; @@ -167,55 +153,91 @@ class ProductOrder extends \common\modelsgii\ProductOrder if (!isset($item['unit_price'])) { $item['unit_price'] = ''; } - - $contentItem = json_decode($val['content'], true); - $item['drug_name'] .= array_key_exists('drug_name', $contentItem)? $contentItem['drug_name'] . '|': '获取失败' . '|'; - $item['specification'] .= array_key_exists('specification', $contentItem)? $contentItem['specification'] . '|' : '无' . '|'; - $item['source'] .= array_key_exists('source', $contentItem)? $contentItem['source'] . '|' : '无' . '|'; - $item['unit_price'] .= $val['total_price'] . '|' ?? '无' . '|'; + foreach (json_decode($val['content'], true) as $vv) { + $item['drug_name'] .= array_key_exists('drug_name', $vv)? $vv['drug_name'] . '|': '获取失败' . '|'; + $item['specification'] .= array_key_exists('specification', $vv)? $vv['specification'] . '|' : '无' . '|'; + $item['source'] .= array_key_exists('source', $vv)? $vv['source'] . '|' : '无' . '|'; + $item['unit_price'] .= $val['total_price'] . '|' ?? '无' . '|'; + } } + } else {//西药 + + if (isset($content['content'])) { + $repice = json_decode($content['content'], true)['repice']?? []; + } else { + $repice = []; + } + if(!empty($repice)){ + foreach ($repice as $val) { + if (!isset($item['drug_name'])) { + $item['drug_name'] = ''; + } + if (!isset($item['specification'])) { + $item['specification'] = ''; + } + if (!isset($item['source'])) { + $item['source'] = ''; + } + if (!isset($item['unit_price'])) { + $item['unit_price'] = ''; + } + + $contentItem = json_decode($val['content'], true); + $item['drug_name'] .= array_key_exists('drug_name', $contentItem)? $contentItem['drug_name'] . '|': '获取失败' . '|'; + $item['specification'] .= array_key_exists('specification', $contentItem)? $contentItem['specification'] . '|' : '无' . '|'; + $item['source'] .= array_key_exists('source', $contentItem)? $contentItem['source'] . '|' : '无' . '|'; + $item['unit_price'] .= $val['total_price'] . '|' ?? '无' . '|'; + } + } + } - - } - $inventory[$key]['drug_name'] = $item['drug_name']; - $inventory[$key]['specification'] = $item['specification'];//规格 - $inventory[$key]['source'] = $item['source'];//厂家 - $inventory[$key]['unit_price'] = $item['unit_price'];//单价 + $inventory[$key]['drug_name'] = $item['drug_name']?? ''; + $inventory[$key]['specification'] = $item['specification']?? '';//规格 + $inventory[$key]['source'] = $item['source']?? '';//厂家 + $inventory[$key]['unit_price'] = $item['unit_price']?? '';//单价 - $inventory[$key]['process_price'] = $value['process_price']; - $inventory[$key]['treatement_price'] = $value['treatement_price']; - $inventory[$key]['items_price'] = $value['items_price']; - $inventory[$key]['market_price'] = $value['market_price']; - $inventory[$key]['total_price'] = $value['total_pay_price']; - $inventory[$key]['trans_expenses'] = $value['trans_expenses']; + $inventory[$key]['process_price'] = $value['process_price']?? ''; + $inventory[$key]['treatement_price'] = $value['treatement_price']?? ''; + $inventory[$key]['items_price'] = $value['items_price']?? ''; + $inventory[$key]['market_price'] = $value['market_price']?? ''; + $inventory[$key]['total_price'] = $value['total_pay_price']?? ''; + $inventory[$key]['trans_expenses'] = $value['trans_expenses']?? ''; // $inventory[$key]['drugstore'] = $value['drugStore']['name']; - $inventory[$key]['doctor'] = $value['doctor']['name']; +// $inventory[$key]['doctor'] = $value['doctor']['name']?? '无'. '-'. $value['su_id']; + $inventory[$key]['doctor'] = $value['doctor']['name']?? $value['doctorId']['name']?? '该医生已被删除'. $value['su_id']; - //订单状态 - if ($value['status'] == 0) $inventory[$key]['status'] = '未支付'; - if ($value['status'] == 1) $inventory[$key]['status'] = '待发货'; - if ($value['status'] == 2) $inventory[$key]['status'] = '待收货'; - if ($value['status'] == 4) $inventory[$key]['status'] = '已退款'; - if ($value['status'] == 5) $inventory[$key]['status'] = '退款中'; - if ($value['status'] == 3 || $value['status'] == 6 || $value['status'] == 7) $inventory[$key]['status'] = '已完成'; - if ($value['status'] == 9) $inventory[$key]['status'] = '已取消'; - //售后 - if ($value['refund_status'] == 0) $inventory[$key]['after_status'] = '暂无'; - if ($value['refund_status'] == 1) $inventory[$key]['after_status'] = '申请退款'; - if ($value['refund_status'] == 2) $inventory[$key]['after_status'] = '同意退款'; - if ($value['refund_status'] == 3) $inventory[$key]['after_status'] = '已退款'; - if ($value['refund_status'] == 9) $inventory[$key]['after_status'] = '取消退款'; + //订单状态 + if ($value['status'] == 0) $inventory[$key]['status'] = '未支付'; + if ($value['status'] == 1) $inventory[$key]['status'] = '待发货'; + if ($value['status'] == 2) $inventory[$key]['status'] = '待收货'; + if ($value['status'] == 4) $inventory[$key]['status'] = '已退款'; + if ($value['status'] == 5) $inventory[$key]['status'] = '退款中'; + if ($value['status'] == 3 || $value['status'] == 6 || $value['status'] == 7) $inventory[$key]['status'] = '已完成'; + if ($value['status'] == 9) $inventory[$key]['status'] = '已取消'; + //售后 + if ($value['refund_status'] == 0) $inventory[$key]['after_status'] = '暂无'; + if ($value['refund_status'] == 1) $inventory[$key]['after_status'] = '申请退款'; + if ($value['refund_status'] == 2) $inventory[$key]['after_status'] = '同意退款'; + if ($value['refund_status'] == 3) $inventory[$key]['after_status'] = '已退款'; + if ($value['refund_status'] == 9) $inventory[$key]['after_status'] = '取消退款'; - $inventory[$key]['created_at'] = date('Y-m-d H:i:s', $value['created_at']);//下单时间 - $inventory[$key]['accept_name'] = $value['express_name'];// json_decode($value['address'])->name; - $inventory[$key]['accept_tel'] = $value['express_mobile'];//json_decode($value['address'])->mobile; - $inventory[$key]['accept_address'] = $value['express_region'] . $value['express_address'];//json_decode($value['address'])->region; - //支付时间 - if ($value['pay_time']==0){ - $inventory[$key]['pay_time'] = '暂无'; - }else{ - $inventory[$key]['pay_time'] = date('Y-m-d H:i:s', $value['pay_time']); + $inventory[$key]['created_at'] = date('Y-m-d H:i:s', $value['created_at']);//下单时间 + $inventory[$key]['accept_name'] = $value['express_name'];// json_decode($value['address'])->name; + $inventory[$key]['accept_tel'] = $value['express_mobile'];//json_decode($value['address'])->mobile; + $inventory[$key]['accept_address'] = $value['express_region'] . $value['express_address'];//json_decode($value['address'])->region; + //支付时间 + if ($value['pay_time']==0){ + $inventory[$key]['pay_time'] = '暂无'; + }else{ + $inventory[$key]['pay_time'] = date('Y-m-d H:i:s', $value['pay_time']); + } + } catch (\Exception $e) { + ds([ + 'msg' => $e->getMessage(), + 'line' => $e->getLine(), + 'data' => $value + ]); } } } else {