diff --git a/common/libs/MyLib.php b/common/libs/MyLib.php index 2683be1..023675f 100644 --- a/common/libs/MyLib.php +++ b/common/libs/MyLib.php @@ -8,6 +8,8 @@ namespace common\libs; +use common\models\PriceT; + /** * Description of MyLib * @@ -279,4 +281,114 @@ class MyLib { return $result; } + /** + * 批量处理信息 + * @param $type + * @param $data1 + * @param null $data2 + * @return array + */ + public static function GetInfosResponse($type, $data1, $data2 = null) + { + switch ($type){ + case 'car': // $data1=>$car_info + $funcname = 'GetCarInfoResponse';break; + case 'order': // $data1=>$orders_info + $funcname = 'GetOrderInfoResponse';break; + case 'insurer_type': // $data1=>$insurer_types_info, $data2=>$order_id + $funcname = 'GetInsurerTypeInfoResponse';break; + case 'gift': // $data1=>$order_gifts_info + $funcname = 'GetGiftInfoResponse';break; + case 'history': // $data1=>$car_log_info + $funcname = 'GetCarLogResponse';break; + } + $infos = []; + foreach ($data1 as $item){ + $infos[] = self::$funcname($item,$data2); + } + return $infos; + } + + /** + * 处理车辆信息(将id字段转换为对应文本) + * @param $car_info @结果集 + * @return array + */ + public static function GetCarInfoResponse($car_info) + { + $car_info_arr = $car_info->toArray(); + $car_info_arr['brand_txt'] = $car_info->brand ? $car_info->brand->name : ''; + $car_info_arr['car_type_txt'] = $car_info->carType ? $car_info->carType->name : ''; + $car_info_arr['car_use_txt'] = $car_info->carUse ? $car_info->carUse->name : ''; + $car_info_arr['car_use_txt'] = $car_info->carUse ? $car_info->carUse->name : ''; + $car_info_arr['series_txt'] = $car_info->series ? $car_info->series->name : ''; + $car_info_arr['displacement_txt'] = $car_info->displacement ? $car_info->displacement->name : ''; + $car_info_arr['location_txt'] = $car_info->location == 3 ? '本区' : ($car_info->location == 6 ? '外区' : '未知'); + return $car_info_arr; + } + + /** + * 处理订单信息(将id字段转换为对应文本) + * @param $order_info @结果集 + * @return array + */ + public static function GetOrderInfoResponse($order_info) + { + $order_info_arr = $order_info->toArray(); + $order_info_arr['business_group_name'] = $order_info->businessGroup ? $order_info->businessGroup->name : ''; + $order_info_arr['company_name'] = $order_info->company ? $order_info->company->name : ''; + $order_info_arr['pay_type_txt'] = ($order_info->shoufei_id?MyLib::zhifufs($order_info->shoufei_id).'-':'').($order_info->payType?$order_info->payType->name:''); + $order_info_arr['payee_name'] = $order_info->payee_id?$order_info->payee->name:''; + $order_info_arr['payer_name'] = $order_info->payer? MyLib::payers($order_info->payer):''; + $order_info_arr['payment_name'] = $order_info->payment_id?$order_info->payment->name:''; + $order_info_arr['receiver_addr_txt'] = $order_info->receiver_province. + $order_info->receiver_city. + $order_info->receiver_county. + $order_info->receiver_address; + return $order_info_arr; + } + + /** + * 处理险种信息 + * @param $insurer_type_info + * @param $order_id + * @return array + */ + public static function GetInsurerTypeInfoResponse($insurer_type_info,$order_id) + { + $price_info = PriceT::find() + ->where('order_id='.$order_id.' and type_id='.$insurer_type_info->id) + ->one(); + $insurer_type_info_arr = $insurer_type_info->toArray(); + $insurer_type_info_arr['show_name'] = $insurer_type_info->name.'('.$insurer_type_info->code.')'; + $insurer_type_info_arr['show_content'] = $price_info->val; + $insurer_type_info_arr['is_nopay_txt'] = $price_info->is_nopay==1?'是': '否'; + return $insurer_type_info_arr; + } + + /** + * 处理礼品信息 + * @param $order_gift + * @return array + */ + public static function GetGiftInfoResponse($order_gift) + { + $gift_info = $order_gift->toArray(); + $gift_info['gift_name'] = $order_gift->gift->name; + $gift_info['group_name'] = $order_gift->group->name; + return $gift_info; + } + + /** + * 处理操作记录 + * @param $log + * @return array + */ + public static function GetCarLogResponse($log) + { + $log_info = $log->toArray(); + $log_info['op_time_txt'] = date('Y-m-d H:i:s',$log->op_time); + return $log_info; + } + } diff --git a/frontend/controllers/CarController.php b/frontend/controllers/CarController.php index d74f4a0..3833710 100644 --- a/frontend/controllers/CarController.php +++ b/frontend/controllers/CarController.php @@ -2694,6 +2694,34 @@ class CarController extends BaseController $result['html'] = $html; return $result; } + + public function actionAjaxHistoryIndexJson() + { + Yii::$app->response->format = Response::FORMAT_JSON; + $request = Yii::$app->request; + $car_id = $request->get('car_id'); + $offset = $request->get('offset',0); + $limit = $request->get('limit', 10); + + $result = array(); + $result['success'] = false; + $result['msg'] = '读取失败'; + + $query = CarLogT::find() + ->where(['car_id'=>$car_id,'type'=>1]) + ->andWhere('op_time>='.strtotime("-6 months")) + ->orderBy('op_time DESC'); + + $total = $query->count(); + + $query = $query->offset($offset)->limit($limit); + $items = $query->all(); + + $result['success'] = true; + $result['msg'] = '读取成功'; + $result['data'] = MyLib::GetInfosResponse('history',$items); + return $result; + } public function actionAjaxHistoryIndexXubao() { Yii::$app->response->format = Response::FORMAT_JSON; diff --git a/frontend/controllers/InsurerController.php b/frontend/controllers/InsurerController.php index 1e78c75..b060730 100644 --- a/frontend/controllers/InsurerController.php +++ b/frontend/controllers/InsurerController.php @@ -181,77 +181,39 @@ class InsurerController extends BaseController return $this->render('info'); } - public function actionInfJson() + public function actionInfoJson() { Yii::$app->response->format = Response::FORMAT_JSON; $request = Yii::$app->request; $id = $request->get('id',0); $order_info = OrderT::findOne(['id'=>$id]); - $car_info = $order_info->car; - + $nonitems=null; if($order_info->non_id){ $nonitems=NonAutoInsurance::findOne(['id'=>$order_info->non_id]); } -// dd($order_info->non_id); - //快递 -// dd($car_info->id); -// $ems_items = EmsT::find() -// ->where(['car_id'=>$car_info->id,'order_id'=>$order_info->id]) -// ->orderBy('id ASC') -// ->all(); -// $ems_items1=(object)array(); -// if(!$ems_items){ -// $ems_items1 = ExpressT::find() -// ->where(['car_id'=>$car_info->id,'order_id'=>$order_info->id]) -// ->orderBy('id ASC') -// ->all(); -// } - //礼品 - $gift_free_group_items = GiftGroupT::find() - ->where('is_free=1') - ->all(); - $gift_group_items = GiftGroupT::find() - ->where('is_free=0') - ->all(); + //获取礼品数据 - $sel_gifts = array(); - $tmp_items = OrderGiftT::find() + $order_gifts = OrderGiftT::find() ->where('order_id='.$order_info->id) ->all(); - foreach($tmp_items as $item) { - $sel_gifts[$item->group_id] = $item; - } - $insurer_type_items = InsurerTypeT::find() - ->all(); + $insurer_type_items = InsurerTypeT::find()->all(); //登陆用户ID $uid = $this->my->id; $order_caiwu = OrderCaiwuT::findOne(['order_id'=>$order_info->id]); - $money_man=''; - $money_no=''; - $money_bank=''; - if($order_caiwu){ - $money_man=$order_caiwu->money_man; - $money_no= $order_caiwu->money_no; - $money_bank=$order_caiwu->money_bank; - } - return $this->render('info',[ - 'order_info'=>$order_info, - 'car_info'=>$car_info, -// 'ems_items' => $ems_items, -// 'ems_items1' => $ems_items1, - 'money_man' => $money_man, - 'money_no' => $money_no, - 'money_bank' => $money_bank, - 'gift_free_group_items' => $gift_free_group_items, - 'gift_group_items' => $gift_group_items, - 'sel_gifts' => $sel_gifts, + + return MyLib::ok3([ + 'order_info'=>MyLib::GetOrderInfoResponse($order_info), + 'car_info'=>MyLib::GetCarInfoResponse($order_info->car), + 'insurer_type_info' => MyLib::GetInfosResponse('insurer_type',$insurer_type_items,$order_info->id), + 'gift_info' => MyLib::GetInfosResponse('gift',$order_gifts), + 'order_insurer_info' => $order_caiwu, 'uid' => $uid, - 'insurer_type_items' => $insurer_type_items, 'nonitems' => $nonitems ]); } + public function actionSave() { Yii::$app->response->format = Response::FORMAT_JSON; diff --git a/frontend/views/insurer/info.php b/frontend/views/insurer/info.php index 7efd747..4c157c6 100644 --- a/frontend/views/insurer/info.php +++ b/frontend/views/insurer/info.php @@ -89,7 +89,7 @@ use \common\libs\MyLib;