You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
simple-yewu/frontend/controllers/CarController_bak.php

1412 lines
51 KiB

5 years ago
<?php
namespace frontend\controllers;
use common\libs\MyLib;
use common\models\AppointmentHistoryT;
use common\models\AppointmentT;
use common\models\BrandT;
use common\models\CarBT;
use common\models\CarCT;
use common\models\CarDT;
use common\models\CarGiftT;
use common\models\CarInvalidT;
use common\models\CarLogT;
use common\models\CarT;
use common\models\CarTypeT;
use common\models\CarUseT;
use common\models\CityT;
use common\models\DirectionT;
use common\models\DisplacementT;
use common\models\DistrictT;
use common\models\GiftT;
use common\models\InsurerCompanyT;
use common\models\InsurerTypeT;
use common\models\InvalidT;
use common\models\LinkmanT;
use common\models\OrderT;
use common\models\PayTypeT;
use common\models\PriceT;
use common\models\RangeT;
use common\models\SeriesT;
use common\models\UserT;
use Yii;
use yii\data\Pagination;
use yii\web\Response;
class CarController extends BaseController
{
public function actionIndex()
{
return $this->renderPartial('index');
}
public function actionMycars()
{
$user_id = $this->my->id;
return $this->renderPartial('mycars',[
'user_id' => $user_id
]);
}
public function actionJsonData()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$result = array();
$user_id = $request->get('user_id',0);
$car_man = $request->get('car_man','');
$car_no = $request->get('car_no','');
$engine_no = $request->get('engine_no','');
$car_frame_no = $request->get('car_frame_no','');
$register_begin = $request->get('register_begin','');
$register_end = $request->get('register_end','');
$resurer_begin = $request->get('resurer_begin','');
$resurer_end = $request->get('resurer_end','');
$sort = $request->get('sort','id');
$order = $request->get('order','asc');
$page = $request->get('page',1);
$limit = $request->get('rows',20);
$start = ($page-1)*$limit;
$query = CarT::find();
if($user_id > 0) {
$user_items = $this->my->getChildren();
$user_ids = array();
if($user_items != null) {
foreach($user_items as $user_item) {
$user_ids[] = $user_item->id;
}
}
$user_ids[] = $this->my->id;
$query = $query->andWhere(['in','user_id',$user_ids]);
}
if($car_man != '') {
$query = $query->andWhere('car_man="'.$car_man.'"');
}
if($car_no != '') {
$query = $query->andWhere('car_no="'.$car_no.'"');
}
if($engine_no != '') {
$query = $query->andWhere('engine_no="'.$engine_no.'"');
}
if($car_frame_no != '') {
$query = $query->andWhere('car_frame_no="'.$car_frame_no.'"');
}
if($register_begin != '') {
$query = $query->andWhere('register_date>="'.$register_begin.'"');
}
if($register_end != '') {
$query = $query->andWhere('register_date<="'.$register_end.'"');
}
$query = $query->orderBy($sort.' '.$order);
$total = $query->count();
$query = $query->offset($start)->limit($limit);
$items = $query->all();
$data = array();
foreach($items as $item) {
$row = array();
$row['id'] = $item->id;
$row['car_no'] = $item->car_no;
$row['car_man'] = $item->car_man;
$row['phone'] = $item->phone;
$row['engine_no'] = $item->engine_no;
$row['car_frame_no'] = $item->car_frame_no;
$row['seats'] = $item->seats;
$row['register_date'] = $item->register_date;
$row['user'] = $item->user?$item->user->getShowName():'';
$row['created_at'] = $item->created_at;
$data[] = $row;
}
$result['total'] = $total;
$result['rows'] = $data;
return $result;
}
public function actionEdit()
{
$request = Yii::$app->request;
$id = $request->get('id',0);
$back_params = $request->get('back_params');
$user_id = $request->get('user_id',0);
if($id > 0) {
$info = CarT::findOne(['id'=>$id]);
} else {
$info = new CarT();
}
$car_use_items = CarUseT::find()->all();
$car_type_items = CarTypeT::find()->all();
$brand_items = BrandT::find()->all();
$series_items = SeriesT::find()
->where('brand_id='.intval($info->brand_id))
->all();
$displacement_items = DisplacementT::find()
->where('series_id='.intval($info->series_id))
->all();
return $this->render('edit',[
'user_id' => $user_id,
'info' => $info,
'car_use_items' => $car_use_items,
'car_type_items' => $car_type_items,
'brand_items' => $brand_items,
'series_items' => $series_items,
'displacement_items' => $displacement_items,
'back_params' => $back_params
]);
}
public function actionSave()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$result = array();
$result['success'] = false;
$result['msg'] = '保存失败';
if($request->isPost) {
$id = $request->post('id',0);
$car_no = $request->post('car_no');
$engine_no = $request->post('engine_no');
$car_frame_no = $request->post('car_frame_no');
$factory_model = $request->post('factory_model');
$seats = $request->post('seats');
$car_type_id = $request->post('car_type_id');
$car_use_id = $request->post('car_use_id');
$register_date = $request->post('register_date');
$displacement_id = $request->post('displacement_id',0);
$car_year = $request->post('car_year');
$brand_id = $request->post('brand_id',0);
$series_id = $request->post('series_id',0);
$car_man = $request->post('car_man');
$phone = $request->post('phone');
$car_man_number = $request->post('car_man_number');
$remark = $request->post('remark');
if($car_no == '') {
$result['msg'] = '请输入车牌号码!';
return $result;
}
$row = null;
if($id > 0) {
$row = CarT::findOne(['id'=>$id]);
} else {
$row = new CarT();
$row->user_id = 0;
$row->location = 1;
}
$row->car_no = $car_no;
$row->engine_no = $engine_no;
$row->car_frame_no = $car_frame_no;
$row->factory_model = $factory_model;
$row->car_model = $factory_model;
$row->seats = $seats;
$row->car_type_id = $car_type_id;
$row->car_use_id = $car_use_id;
$row->register_date = $register_date;
$row->displacement_id = $displacement_id;
$row->car_year = $car_year;
$row->brand_id = $brand_id;
$row->series_id = $series_id;
$row->car_man = $car_man;
$row->phone = $phone;
$row->car_man_number = $car_man_number;
$row->remark = $remark;
$row->save();
$result['success'] = true;
$result['msg'] = '保存成功';
}
return $result;
}
public function actionDelete()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$result = array();
$result['success'] = false;
$result['msg'] = '删除失败';
if($request->isPost) {
$id = $request->post('id',0);
$tran = CarT::getDb()->beginTransaction();
try {
$ids = $request->post('ids',array());
if($id > 0) {
$car_info = CarT::findOne(['id'=>$id]);
//删除预约信息
AppointmentT::deleteAll('car_id='.$id);
AppointmentHistoryT::deleteAll('car_id='.$id);
//删除保单信息
$items = OrderT::find()
->where('car_id='.$id)
->all();
foreach ($items as $item) {
PriceT::deleteAll(['order_id'=>$item->id]);
$item->delete();
}
//删除B、C、D库数据
if($car_info->location == 2)
CarBT::deleteAll('id='.$car_info->id);
if($car_info->location == 3)
CarCT::deleteAll('id='.$car_info->id);
if($car_info->location == 4)
CarDT::deleteAll('id='.$car_info->id);
$car_info->delete();
//清除操作记录
$this->removeLog($id);
}
$tran->commit();
$result['success'] = true;
$result['msg'] = '删除成功';
} catch(\Exception $e) {
$tran->rollBack();
throw $e;
}
}
return $result;
}
public function actionDeleteAll()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$result = array();
$result['success'] = false;
$result['msg'] = '删除失败';
if($request->isPost) {
$tran = CarT::getDb()->beginTransaction();
try {
$ids = $request->post('ids',array());
foreach($ids as $id) {
if($id > 0) {
$row = CarT::findOne(['id'=>$id]);
AppointmentT::deleteAll('car_id='.$id);
AppointmentHistoryT::deleteAll('car_id='.$id);
$items = OrderT::find()
->where('car_id='.$id)
->all();
foreach ($items as $item) {
PriceT::deleteAll(['order_id'=>$item->id]);
$item->delete();
}
$row->delete();
}
}
$tran->commit();
$result['success'] = true;
$result['msg'] = '删除成功';
} catch(\Exception $e) {
$tran->rollBack();
throw $e;
}
}
return $result;
}
public function actionAppointment()
{
$request = Yii::$app->request;
$car_id = $request->get('car_id');
return $this->renderPartial('appointment',[
'car_id' => $car_id
]);
}
public function actionAppointmentJsonData()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$result = array();
$car_id = $request->get('car_id');
$car_info = CarT::findOne(['id'=>$car_id]);
$page = $request->get('page',1);
$limit = $request->get('rows',20);
$start = ($page-1)*$limit;
$query = $car_info->getAppointments()
->orderBy('pdate DESC,ptime ASC,id DESC');
$total = $query->count();
$query = $query->offset($start)->limit($limit);
$items = $query->all();
$data = array();
foreach($items as $item) {
$row = array();
$row['id'] = $item->id;
$row['pdate'] = $item->pdate;
$row['ptime'] = $item->ptime;
$row['remark'] = $item->remark;
$row['user'] = $item->user?$item->user->getShowName():'';
$data[] = $row;
}
$result['total'] = $total;
$result['rows'] = $data;
return $result;
}
public function actionInsurer()
{
$request = Yii::$app->request;
$car_id = $request->get('car_id');
return $this->renderPartial('insurer',[
'car_id' => $car_id
]);
}
public function actionInfo()
{
$request = Yii::$app->request;
$id = $request->get('id',0);
$type = $request->get('type',0);
$car_man = $request->get('car_man');
$phone = $request->get('phone');
$car_no = $request->get('car_no');
$page = $request->get('page',1);
$sort_key = $request->get('sort_key','appointment_t.pdate');
$sort_value = $request->get('sort_value','ASC');
$next_index = $request->get('next_index',0);
$back_params = $request->get('back_params');
$car_info = CarT::findOne(['id'=>$id]);
$order_info = $car_info->getOrders()->orderBy('id DESC')->one();
if(!$order_info) {
$user_id = 0;
if($car_info->location == 2) {
$b_info = CarBT::findOne(['id'=>$car_info->id]);
$user_id = $b_info->user_id;
}
if($car_info->location == 3) {
$c_info = CarCT::findOne(['id'=>$car_info->id]);
$user_id = $c_info->user_id;
}
if($car_info->location == 4) {
$d_info = CarDT::findOne(['id'=>$car_info->id]);
$user_id = $d_info->user_id;
}
$order_info = new OrderT();
$order_info->car_id = $car_info->id;
$order_info->car_no = $car_info->car_no;
$order_info->engine_no = $car_info->engine_no;
$order_info->car_frame_no = $car_info->car_frame_no;
$order_info->car_man = $car_info->car_man;
$order_info->user_id = $user_id;
$order_info->status_id = 1;
$order_info->id_man = $car_info->car_man;
$order_info->link_man = $car_info->car_man;
$order_info->link_phone = $car_info->phone;
$order_info->save();
}
$insurer_type_items = InsurerTypeT::find()->all();
$insurer_company_items = InsurerCompanyT::find()->all();
$pay_type_items = PayTypeT::find()->all();
$car_use_items = CarUseT::find()->all();
$car_type_items = CarTypeT::find()->all();
$brand_items = BrandT::find()->all();
$series_items = SeriesT::find()
->where('brand_id='.intval($car_info->brand_id))
->all();
$displacement_items = DisplacementT::find()
->where('series_id='.intval($car_info->series_id))
->all();
$direction_items = DirectionT::find()
->all();
$range_items = RangeT::find()
->all();
$city_items = CityT::find()
->all();
$district_items = DistrictT::find()
->orderBy('order_id ASC')
->all();
$gift_items = GiftT::find()
->where('type_id=1')
->all();
$success_items = InvalidT::getTree(1);
$failure_items = InvalidT::getTree(2);
//下一辆
$next_id = 0;
if($type == 1) {
$query = AppointmentT::find()
->leftJoin('car_t','`car_t`.`id`=`appointment_t`.`car_id`')
->where('appointment_t.is_first=1 and car_t.is_track=0')
->andWhere('appointment_t.pdate<="'.date('Y-m-d').'"');
$user_ids = $this->getChildrenUserIDs();
$query = $query->andWhere(['in','appointment_t.user_id',$user_ids]);
if($car_man != '') {
$query = $query->andWhere('car_t.car_man like "'.$car_man.'"');
}
if($phone != '') {
$query = $query->andWhere('car_t.phone="'.$phone.'"');
}
if($car_no != '') {
$query = $query->andWhere('car_t.car_no like "'.$car_no.'"');
}
if($sort_key != '') {
$query = $query->orderBy($sort_key.' '.$sort_value);
}
$next_item = $query->offset($next_index)->one();
if($next_item) {
$next_id = $next_item->car_id;
}
$next_index++;
}
if($type == 2) {
$query = AppointmentT::find()
->leftJoin('car_t','`car_t`.`id`=`appointment_t`.`car_id`')
->where('appointment_t.is_first=0 and car_t.is_track=0')
->andWhere('appointment_t.pdate<="'.date('Y-m-d').'"');
$user_ids = $this->getChildrenUserIDs();
$query = $query->andWhere(['in','appointment_t.user_id',$user_ids]);
if($car_man != '') {
$query = $query->andWhere('car_t.car_man like "'.$car_man.'"');
}
if($phone != '') {
$query = $query->andWhere('car_t.phone="'.$phone.'"');
}
if($car_no != '') {
$query = $query->andWhere('car_t.car_no like "'.$car_no.'"');
}
if($sort_key != '') {
$query = $query->orderBy($sort_key.' '.$sort_value);
}
$next_item = $query->offset($next_index)->one();
if($next_item) {
$next_id = $next_item->car_id;
}
$next_index++;
}
if($type == 3) {
$query = AppointmentT::find()
->leftJoin('car_t','`car_t`.`id`=`appointment_t`.`car_id`')
->where('appointment_t.is_first=0 and car_t.is_track=0');
$user_ids = $this->getChildrenUserIDs();
$query = $query->andWhere(['in','appointment_t.user_id',$user_ids]);
if($car_man != '') {
$query = $query->andWhere('car_t.car_man like "'.$car_man.'"');
}
if($phone != '') {
$query = $query->andWhere('car_t.phone="'.$phone.'"');
}
if($car_no != '') {
$query = $query->andWhere('car_t.car_no like "'.$car_no.'"');
}
if($sort_key != '') {
$query = $query->orderBy($sort_key.' '.$sort_value);
}
$next_item = $query->offset($next_index)->one();
if($next_item) {
$next_id = $next_item->car_id;
}
$next_index++;
}
if($type == 4) {
$query = OrderT::find()
->where('status_id=1 and return_status_id>0')
->orderBy('submit_date DESC, id DESC');
$user_items = $this->my->getChildren();
$user_ids[] = $this->my->id;
if($user_items) {
foreach($user_items as $user_item) {
$user_ids[] = $user_item->id;
}
}
$query = $query->andWhere(['in','user_id',$user_ids]);
if($car_man != '') {
$query = $query->andWhere('car_man="'.$car_man.'"');
}
if($phone != '') {
$query = $query->andWhere('link_phone="'.$phone.'"');
}
if($car_no != '') {
$query = $query->andWhere('car_no="'.$car_no.'"');
}
$next_item = $query->offset($next_index)->one();
if($next_item) {
$next_id = $next_item->car_id;
}
$next_index++;
}
return $this->render('info',[
'type' => $type,
'car_info' => $car_info,
'insurer_type_items' => $insurer_type_items,
'order_info' => $order_info,
'insurer_company_items' => $insurer_company_items,
'pay_type_items' => $pay_type_items,
'car_use_items' => $car_use_items,
'car_type_items' => $car_type_items,
'brand_items' => $brand_items,
'series_items' => $series_items,
'displacement_items' => $displacement_items,
'direction_items' => $direction_items,
'range_items' => $range_items,
'city_items' => $city_items,
'district_items' => $district_items,
'gift_items' => $gift_items,
'success_items' => $success_items,
'failure_items' => $failure_items,
'next_id' => $next_id,
'next_index' => $next_index,
'car_man' => $car_man,
'car_no' => $car_no,
'phone' => $phone,
'page' => $page,
'sort_key' => $sort_key,
'sort_value' => $sort_value,
'back_params' => $back_params
]);
}
public function actionInfoView()
{
$request = Yii::$app->request;
$id = $request->get('id',0);
$type = $request->get('type',0);
$car_man = $request->get('car_man');
$phone = $request->get('phone');
$car_no = $request->get('car_no');
$page = $request->get('page',1);
$sort_key = $request->get('sort_key','appointment_t.pdate');
$sort_value = $request->get('sort_value','ASC');
$next_index = $request->get('next_index',0);
$car_info = CarT::findOne(['id'=>$id]);
$failure_items = InvalidT::getTree(2);
//礼品
$gift_items = CarGiftT::find()
->where('car_id='.$car_info->id)
->orderBy('strategy_id DESC')
->all();
//下一辆
$next_id = 0;
if($type == 1) {
$query = AppointmentT::find()
->leftJoin('car_t','`car_t`.`id`=`appointment_t`.`car_id`')
->where('appointment_t.is_first=1 and car_t.is_track=1')
->andWhere('appointment_t.pdate<="'.date('Y-m-d').'"');
$user_ids = $this->getChildrenUserIDs();
$query = $query->andWhere(['in','appointment_t.user_id',$user_ids]);
if($car_man != '') {
$query = $query->andWhere('car_t.car_man like "'.$car_man.'"');
}
if($phone != '') {
$query = $query->andWhere('car_t.phone="'.$phone.'"');
}
if($car_no != '') {
$query = $query->andWhere('car_t.car_no like "'.$car_no.'"');
}
if($sort_key != '') {
$query = $query->orderBy($sort_key.' '.$sort_value);
}
$next_item = $query->offset($next_index)->one();
if($next_item) {
$next_id = $next_item->car_id;
}
$next_index++;
}
if($type == 2) {
$query = AppointmentT::find()
->leftJoin('car_t','`car_t`.`id`=`appointment_t`.`car_id`')
->where('appointment_t.is_first=0 and car_t.is_track=1')
->andWhere('appointment_t.pdate<="'.date('Y-m-d').'"');
$user_ids = $this->getChildrenUserIDs();
$query = $query->andWhere(['in','appointment_t.user_id',$user_ids]);
if($car_man != '') {
$query = $query->andWhere('car_t.car_man like "'.$car_man.'"');
}
if($phone != '') {
$query = $query->andWhere('car_t.phone="'.$phone.'"');
}
if($car_no != '') {
$query = $query->andWhere('car_t.car_no like "'.$car_no.'"');
}
if($sort_key != '') {
$query = $query->orderBy($sort_key.' '.$sort_value);
}
$next_item = $query->offset($next_index)->one();
if($next_item) {
$next_id = $next_item->car_id;
}
$next_index++;
}
if($type == 3) {
$query = AppointmentT::find()
->leftJoin('car_t','`car_t`.`id`=`appointment_t`.`car_id`')
->where('appointment_t.is_first=0 and car_t.is_track=1');
$user_ids = $this->getChildrenUserIDs();
$query = $query->andWhere(['in','appointment_t.user_id',$user_ids]);
if($car_man != '') {
$query = $query->andWhere('car_t.car_man like "'.$car_man.'"');
}
if($phone != '') {
$query = $query->andWhere('car_t.phone="'.$phone.'"');
}
if($car_no != '') {
$query = $query->andWhere('car_t.car_no like "'.$car_no.'"');
}
if($sort_key != '') {
$query = $query->orderBy($sort_key.' '.$sort_value);
}
$next_item = $query->offset($next_index)->one();
if($next_item) {
$next_id = $next_item->car_id;
}
$next_index++;
}
return $this->render('info-view',[
'type' => $type,
'car_info' => $car_info,
'failure_items' => $failure_items,
'next_id' => $next_id,
'next_index' => $next_index,
'car_man' => $car_man,
'car_no' => $car_no,
'phone' => $phone,
'page' => $page,
'sort_key' => $sort_key,
'sort_value' => $sort_value,
'gift_items' => $gift_items
]);
}
public function actionInfoTrack()
{
$request = Yii::$app->request;
$id = $request->get('id',0);
$type = $request->get('type',0);
$car_man = $request->get('car_man');
$phone = $request->get('phone');
$car_no = $request->get('car_no');
$page = $request->get('page',1);
$sort_key = $request->get('sort_key','appointment_t.pdate');
$sort_value = $request->get('sort_value','ASC');
$next_index = $request->get('next_index',0);
$back_params = $request->get('back_params');
$car_info = CarT::findOne(['id'=>$id]);
$car_use_items = CarUseT::find()->all();
$car_type_items = CarTypeT::find()->all();
$brand_items = BrandT::find()->all();
$series_items = SeriesT::find()
->where('brand_id='.intval($car_info->brand_id))
->all();
$displacement_items = DisplacementT::find()
->where('series_id='.intval($car_info->series_id))
->all();
$failure_items = InvalidT::getTree(2);
//礼品
$gift_items = CarGiftT::find()
->where('car_id='.$car_info->id)
->orderBy('strategy_id DESC')
->all();
//下一辆
$next_id = 0;
if($type == 1) {
$query = AppointmentT::find()
->leftJoin('car_t','`car_t`.`id`=`appointment_t`.`car_id`')
->where('appointment_t.is_first=1 and car_t.is_track=1')
->andWhere('appointment_t.pdate<="'.date('Y-m-d').'"');
$user_ids = $this->getChildrenUserIDs();
$query = $query->andWhere(['in','appointment_t.user_id',$user_ids]);
if($car_man != '') {
$query = $query->andWhere('car_t.car_man like "'.$car_man.'"');
}
if($phone != '') {
$query = $query->andWhere('car_t.phone="'.$phone.'"');
}
if($car_no != '') {
$query = $query->andWhere('car_t.car_no like "'.$car_no.'"');
}
if($sort_key != '') {
$query = $query->orderBy($sort_key.' '.$sort_value);
}
$next_item = $query->offset($next_index)->one();
if($next_item) {
$next_id = $next_item->car_id;
}
$next_index++;
}
if($type == 2) {
$query = AppointmentT::find()
->leftJoin('car_t','`car_t`.`id`=`appointment_t`.`car_id`')
->where('appointment_t.is_first=0 and car_t.is_track=1')
->andWhere('appointment_t.pdate<="'.date('Y-m-d').'"');
$user_ids = $this->getChildrenUserIDs();
$query = $query->andWhere(['in','appointment_t.user_id',$user_ids]);
if($car_man != '') {
$query = $query->andWhere('car_t.car_man like "'.$car_man.'"');
}
if($phone != '') {
$query = $query->andWhere('car_t.phone="'.$phone.'"');
}
if($car_no != '') {
$query = $query->andWhere('car_t.car_no like "'.$car_no.'"');
}
if($sort_key != '') {
$query = $query->orderBy($sort_key.' '.$sort_value);
}
$next_item = $query->offset($next_index)->one();
if($next_item) {
$next_id = $next_item->car_id;
}
$next_index++;
}
if($type == 3) {
$query = AppointmentT::find()
->leftJoin('car_t','`car_t`.`id`=`appointment_t`.`car_id`')
->where('appointment_t.is_first=0 and car_t.is_track=1');
$user_ids = $this->getChildrenUserIDs();
$query = $query->andWhere(['in','appointment_t.user_id',$user_ids]);
if($car_man != '') {
$query = $query->andWhere('car_t.car_man like "'.$car_man.'"');
}
if($phone != '') {
$query = $query->andWhere('car_t.phone="'.$phone.'"');
}
if($car_no != '') {
$query = $query->andWhere('car_t.car_no like "'.$car_no.'"');
}
if($sort_key != '') {
$query = $query->orderBy($sort_key.' '.$sort_value);
}
$next_item = $query->offset($next_index)->one();
if($next_item) {
$next_id = $next_item->car_id;
}
$next_index++;
}
return $this->render('info-track',[
'type' => $type,
'car_info' => $car_info,
'failure_items' => $failure_items,
'next_id' => $next_id,
'next_index' => $next_index,
'car_man' => $car_man,
'car_no' => $car_no,
'phone' => $phone,
'page' => $page,
'sort_key' => $sort_key,
'sort_value' => $sort_value,
'gift_items' => $gift_items,
'car_use_items' => $car_use_items,
'car_type_items' => $car_type_items,
'brand_items' => $brand_items,
'series_items' => $series_items,
'displacement_items' => $displacement_items,
'back_params' => $back_params
]);
}
public function actionInfoEdit()
{
$request = Yii::$app->request;
$id = $request->get('id',0);
$info = CarT::findOne(['id'=>$id]);
$car_use_items = CarUseT::find()->all();
$car_type_items = CarTypeT::find()->all();
$brand_items = BrandT::find()->all();
$series_items = SeriesT::find()
->where('brand_id='.intval($info->brand_id))
->all();
$displacement_items = DisplacementT::find()
->where('series_id='.intval($info->series_id))
->all();
return $this->render('info-edit',[
'info' => $info,
'car_use_items' => $car_use_items,
'car_type_items' => $car_type_items,
'brand_items' => $brand_items,
'series_items' => $series_items,
'displacement_items' => $displacement_items
]);
}
public function actionSeries()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$result = array();
$brand_id = $request->get('brand_id',0);
$query = SeriesT::find()
->where('brand_id='.$brand_id);
$items = $query->all();
$html = '<option value="0">---请选择---</option>';
foreach($items as $item) {
$html .= '<option value='.$item->id.'>'.$item->name.'</option>';
}
$result['success'] = true;
$result['html'] = $html;
return $result;
}
public function actionDisplacement()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$result = array();
$series_id = $request->get('series_id',0);
$query = DisplacementT::find()
->where('series_id='.$series_id);
$items = $query->all();
$html = '<option value="0">---请选择---</option>';
foreach($items as $item) {
$html .= '<option value='.$item->id.'>'.$item->name.'</option>';
}
$result['success'] = true;
$result['html'] = $html;
return $result;
}
//保单信息保存
public function actionOrderSave()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$result = array();
$result['success'] = false;
$result['msg'] = '保存失败';
if($request->isPost) {
//状态
$status_id = $request->post('status_id',1);
//车辆信息
$car_id = $request->post('car_id',0);
$car_no = $request->post('car_no');
$seats = (int)$request->post('seats');
$register_date = $request->post('register_date');
$car_man = $request->post('car_man');
$car_man_number = $request->post('car_man_number');
//保单信息
$order_id = $request->post('order_id',0);
$id_man = $request->post('id_man');
$id_number = $request->post('id_number');
$link_man = $request->post('link_man');
$link_phone = $request->post('link_phone');
$send_date = $request->post('send_date');
$company_id = $request->post('company_id');
$pay_type_id = $request->post('pay_type_id');
$email = $request->post('email');
$insurer1_begin_date = $request->post('insurer1_begin_date');
$insurer2_begin_date = $request->post('insurer2_begin_date');
$order_remark = $request->post('order_remark');
$direction1_id = $request->post('direction1_id');
$range1_id = $request->post('range1_id');
$city1_id = $request->post('city1_id');
$district1_id = $request->post('district1_id');
$send_address1 = $request->post('send_address1');
$send_address2 = $request->post('send_address2');
$success_id = $request->post('success_id');
//报价信息
$total1_clear = $request->post('total1_clear');
$total1 = $request->post('total1');
$total1_real = $request->post('total1_real');
$total1_dis = $request->post('total1_dis');
$total1_percent = $request->post('total1_percent');
$total2_clear = $request->post('total2_clear');
$total2 = $request->post('total2');
$total3 = $request->post('total3');
$total_all = $request->post('total_all');
$total_real = $request->post('total_real');
$price_remark = $request->post('price_remark');
//报价明细
$types = $request->post('types',array());
$nopays = $request->post('nopays', array());
//礼品
$gifts = $request->post('gifts',array());
if($car_no == '') {
$result['msg'] = '请输入车牌号码!';
return $result;
}
$tran = CarT::getDb()->beginTransaction();
try {
$order_info = OrderT::findOne(['id'=>$order_id]);
$car_info = $order_info->car;
//车辆信息
$car_info->car_no = $car_no;
$car_info->seats = $seats;
$car_info->register_date = $register_date;
$car_info->car_man = $car_man;
$car_info->car_man_number = $car_man_number;
$car_info->save();
//保单信息
$order_info->car_no = $car_no;
$order_info->engine_no = $car_info->engine_no;
$order_info->car_frame_no = $car_info->car_frame_no;
$order_info->car_man = $car_man;
$order_info->company_id = $company_id;
$order_info->success_id = $success_id;
$order_info->status_id = $status_id;
if($status_id > 1) {
$order_info->return_status_id = 0;
$order_info->return_remark = '';
$order_info->return_time = 0;
}
$order_info->submit_date = date('Y-m-d');
$order_info->id_man = $id_man;
$order_info->id_number = $id_number;
$order_info->link_man = $link_man;
$order_info->link_phone = $link_phone;
$order_info->insurer1_begin_date = $insurer1_begin_date;
$insurer1_end_date = '';
if($insurer1_begin_date)
$insurer1_end_date = date('Y-m-d',strtotime(date('Y-m-d',strtotime($insurer1_begin_date."+1 year")).'-1 day'));
$order_info->insurer1_end_date = $insurer1_end_date;
$order_info->insurer2_begin_date = $insurer2_begin_date;
$insurer2_begin_date = '';
if($insurer2_begin_date != '')
$insurer2_begin_date = date('Y-m-d',strtotime(date('Y-m-d',strtotime($insurer2_begin_date."+1 year")).'-1 day'));
$order_info->insurer2_end_date = $insurer2_begin_date;
$order_info->send_date = $send_date;
$order_info->direction1_id = $direction1_id;
$order_info->range1_id = $range1_id;
$order_info->city1_id = $city1_id;
$order_info->district1_id = $district1_id;
$order_info->send_address1 = $send_address1;
$order_info->send_address2 = $send_address2;
$order_info->pay_type_id = $pay_type_id;
$order_info->email = $email;
$order_info->remark = $order_remark;
$order_info->total1_clear = $total1_clear;
$order_info->total1 = $total1;
$order_info->total1_real = $total1_real;
$order_info->total1_dis = $total1_dis;
$order_info->total1_percent = $total1_percent;
$order_info->total2_clear = $total2_clear;
$order_info->total2 = $total2;
$order_info->total3 = $total3;
$order_info->total_all = $total_all;
$order_info->total_real = $total_real;
$order_info->price_remark = $price_remark;
$order_info->save();
//险种明细
foreach($types as $id=>$val) {
$price_row = PriceT::find()
->where('order_id='.$order_info->id.' and type_id='.$id)
->one();
if(empty($price_row)) {
$price_row = new PriceT();
$price_row->order_id = $order_info->id;
$price_row->type_id = $id;
}
$price_row->val = $val;
if(!empty($nopays[$id]))
$price_row->is_nopay = 1;
else
$price_row->is_nopay = 0;
$price_row->save();
}
//处理预约
if($status_id > 1) {
$tmp_row = AppointmentT::findOne(['car_id'=>$car_info->id]);
if(!empty($tmp_row)) {
$tmp_row->delete();
}
$this->addLog($car_info->id,'提交内勤,进入核保管理',1);
}
//处理公司礼品
//清除原公司礼品
CarGiftT::deleteAll('user_id='.$this->my->id.' and car_id='.$car_info->id.' and order_id='.$order_info->id.' and type=1 and status=0');
foreach($gifts as $id_str) {
$gift_ids = explode('-',$id_str);
if(count($gift_ids) != 2) continue;
$strategy_id = $gift_ids[0];
$gift_id = $gift_ids[1];
$car_gift_info = CarGiftT::find()
->where('strategy_id='.$strategy_id.' and order_id='.$order_info->id.' and gift_id='.$gift_id)
->one();
if(!$car_gift_info && $gift_id > 0) {
$car_gift_info = new CarGiftT();
$car_gift_info->user_id = $this->my->id;
$car_gift_info->car_id = $car_info->id;
$car_gift_info->order_id = $order_info->id;
$car_gift_info->strategy_id = $strategy_id;
$car_gift_info->gift_id = $gift_id;
$car_gift_info->submit_time = time();
$car_gift_info->status = 0;
$car_gift_info->type = 1;
$car_gift_info->save();
}
}
//处理自费礼品
$gift_items = CarGiftT::find()
->where('car_id='.$car_info->id.' and order_id=0')
->all();
foreach($gift_items as $item) {
$item->order_id = $order_info->id;
$item->save();
}
$result['success'] = true;
$result['msg'] = '保存成功';
$tran->commit();
} catch (\Exception $e) {
$tran->rollBack();
throw $e;
}
}
return $result;
}
public function actionAjaxHistoryIndex()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$car_id = $request->get('car_id');
$page = $request->get('page',1);
$result = array();
$result['success'] = false;
$result['msg'] = '读取失败';
$query = CarLogT::find()
->where(['car_id'=>$car_id,'type'=>1])
->orderBy('id DESC');
$total = $query->count();
$pagination = new Pagination(['totalCount' => $total,'pageSize'=>20]);
$pagination->setPage($page-1);
$query = $query->offset($pagination->offset)->limit($pagination->limit);
$items = $query->all();
$page_info = MyLib::getAjaxPageInfo($pagination,'car_history_list');
$html = $this->renderPartial('ajax-history-index',[
'car_id' => $car_id,
'items' => $items,
'page' => $page,
'page_info' => $page_info
]);
$result['success'] = true;
$result['html'] = $html;
return $result;
}
public function actionInvalid()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$result = array();
$result['success'] = false;
$result['msg'] = '操作失败';
if($request->isPost) {
$car_id = $request->post('car_id');
$invalid_id = $request->post('invalid_id',0);
$tran = CarT::getDb()->beginTransaction();
try {
$car_info = CarT::findOne(['id'=>$car_id]);
$car_info->location = 5;
$car_info->save();
CarInvalidT::deleteAll('id='.$car_info->id);
$invalid_info = new CarInvalidT();
$invalid_info->id = $car_info->id;
$invalid_info->invalid_id = $invalid_id;
$invalid_info->user_id = $this->my->id;
$invalid_info->save();
CarBT::deleteAll(['id'=>$car_info->id]);
CarCT::deleteAll(['id'=>$car_info->id]);
CarDT::deleteAll(['id'=>$car_info->id]);
//删除预约
AppointmentT::deleteAll('car_id='.$car_info->id);
//删除保单
OrderT::deleteAll('car_id='.$car_info->id.' and status_id<2');
$this->addLog($car_info->id,'无效车辆数据:'.$invalid_info->invalid->name,1);
$result['success'] = true;
$result['msg'] = '操作成功';
$tran->commit();
} catch (\Exception $e) {
$tran->rollBack();
throw $e;
}
}
return $result;
}
public function actionSearch()
{
$request = Yii::$app->request;
$car_man = $request->get('car_man');
$phone = $request->get('phone');
$car_no = $request->get('car_no');
$car_model = $request->get('car_model');
$register_date = $request->get('register_date');
$insurer_date = $request->get('insurer_date');
$id_man = $request->get('id_man');
$op = $request->get('op',1);
$page = $request->get('page',1);
if($page < 1) $page = 1;
$query = CarT::find()
->leftJoin('order_t','`order_t`.`car_id`=`car_t`.`id`');
if($op==0) {
$query = $query->andWhere('car_t.id=-1');
}
if($car_man != '') {
$query = $query->andWhere('car_t.car_man like "'.$car_man.'"');
}
if($phone != '') {
$linkman_items = LinkmanT::find()
->where('phone like "'.$phone.'"')
->all();
$car_ids = array();
foreach($linkman_items as $linkman_info) {
$car_ids[] = $linkman_info->car_id;
}
$car_ids_str = join(',',$car_ids);
if($car_ids_str == '')
$car_ids_str = '0';
$query = $query->andWhere('(car_t.phone like "'.$phone.'" or car_t.id in ('.$car_ids_str.'))');
}
if($car_no != '') {
$query = $query->andWhere('car_t.car_no like "'.$car_no.'"');
}
if($car_model != '') {
$query = $query->andWhere('car_t.car_model="'.$car_model.'"');
}
if($register_date != '') {
$query = $query->andWhere('car_t.register_date='.$register_date);
}
if($insurer_date != '') {
$query = $query->andWhere('car_t.insurer1_date="'.$insurer_date.'" or car_t.insurer2_date="'.$insurer_date.'"');
}
if($id_man != '') {
$query = $query->andWhere('order_t.id_man="'.$id_man.'"');
}
$total = $query->count();
$pagination = new Pagination(['totalCount' => $total,'pageSize'=>20]);
$pagination->setPage($page-1);
$query = $query->offset($pagination->offset)->limit($pagination->limit);
$items = $query->all();
$page_info = MyLib::getPageInfo($pagination);
return $this->render('search',[
'items' => $items,
'car_man' => $car_man,
'phone' => $phone,
'car_no' => $car_no,
'car_model' => $car_model,
'register_date' => $register_date,
'insurer_date' => $insurer_date,
'id_man' => $id_man,
'page' => $page,
'page_info' => $page_info
]);
}
public function actionSmsMake()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$result = array();
$result['success'] = false;
$result['msg'] = '生成失败';
$order_id = $request->post('order_id');
$order_info = OrderT::findOne(['id'=>$order_id]);
$car_info = $order_info->car;
$total1 = $request->post('total1');
$total2 = $request->post('total2');
$total3 = $request->post('total3');
$total_all = $request->post('total_all');
$types = $request->post('types');
$nopays = $request->post('nopays');
$insurer_type_items = InsurerTypeT::find()->all();
$msg = '尊敬的'.$car_info->car_no.'客户您好,人保车险'.$this->my->name.'为您报价!';
$msg .= '交强险'.$total2.'元,';
$msg .= '商业险'.$total1.'元,';
$msg .= '其中包含';
$bj = '';
foreach($insurer_type_items as $item) {
if($item->id == 10 || $item->id == 11) continue;
if($types[$item->id] != '' && $types[$item->id] != '否' && $types[$item->id] != '无') {
$msg .= $item->name;
if($types[$item->id] != '是')
$msg .= $types[$item->id];
$msg .= '、';
if(isset($nopays[$item->id]) && ($nopays[$item->id] == 1))
$bj .= $item->code;
}
}
if($total3 > 0) {
$msg .= '车船税'.$total3.'元,';
}
$msg .= '总计'.$total_all.'元,';
if($bj != '') {
$msg .= '不计免赔覆盖'.$bj.'。';
}
$msg .= '以上价格仅供参考,价格可能受您的历史理赔情况等的影响,最终价格以出单为准。详情请咨询010-53778188,回复TD拒收。';
$result['success'] = true;
$result['msg'] = $msg;
return $result;
}
public function actionSmsSend()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$MessageContent = $request->post('msg');
$UserNumber = $request->post('tel');
$url = 'http://api.ums86.com:8899/sms/Api/Send.do';
$params['SpCode'] = '230525';
$params['LoginName'] = 'sr_ys';
$params['Password'] = 'chbj123456';
$params['UserNumber'] = $UserNumber;
$params['MessageContent'] = mb_convert_encoding($MessageContent,'gbk','utf8');
$params['SerialNumber'] = date('YmdHis').rand(100,999);
$params['ScheduleTime'] = '';
$params['f'] = 1;
$post_url = http_build_query($params);
$msg = MyLib::Get($url.'?'.$post_url);
$msg = mb_convert_encoding($msg,'UTF8','GBK');
parse_str($msg,$obj);
$result = array();
$result['success'] = true;
$result['msg'] = '发送成功';
if($obj['result'] != 0) {
$result['msg'] = $obj['description'];
}
return $result;
}
public function actionLinkmanSave()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$result = array();
$result['success'] = false;
$result['msg'] = '保存失败';
if($request->isPost) {
$car_id = $request->post('car_id',0);
$name = $request->post('name');
$phone = $request->post('phone');
$id_number = $request->post('id_number');
$type = $request->post('type');
if($name == '' || $phone == '') {
$result['msg'] = '请输入姓名和联系电话!';
return $result;
}
$row = null;
$linkman_info = new LinkmanT();
$linkman_info->car_id = $car_id;
$linkman_info->name = $name;
$linkman_info->phone = $phone;
$linkman_info->type = $type;
$linkman_info->id_number = $id_number;
if(!$linkman_info->save()) {
var_dump($linkman_info->errors);
}
$result['success'] = true;
$result['msg'] = '保存成功';
}
return $result;
}
public function actionAjaxLinkmanIndex()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$car_id = $request->get('car_id');
$result = array();
$result['success'] = false;
$result['msg'] = '读取失败';
$query = LinkmanT::find()
->where(['car_id'=>$car_id])
->orderBy('id ASC');
$items = $query->all();
$html = $this->renderPartial('ajax-linkman-index',[
'items' => $items
]);
$result['success'] = true;
$result['html'] = $html;
return $result;
}
}