# @Date: 2022-05-22T07:27:54+08:00 # @Email: fm453@lukegzs.com # @Last modified by: fm453 # @Last modified time: 2022-05-22T07:27:54+08:00 # @Copyright: www.hiluker.cn namespace backend\controllers; use Yii; use yii\data\Pagination; use yii\helpers\Url; use addons\models\AcCar; use addons\models\AcAlbums; use addons\models\AcAlbumPics; use addons\models\AcAlbumVersion; class AlbumsController extends Common { //主界面 public function actionIndex() { global $_HI,$_FM; return $this->render('../layouts/dev', []); } //相册列表 public function actionList() { return $this->render('../layouts/dev'); global $_HI,$_FM; $pid = Yii::$app->session->get('pid'); $session = Yii::$app->session; $model = new AcAlbums(); $where = []; $where[]='and'; $where[] = ['=','pid',$pid]; $post = Yii::$app->request->post(); $get = Yii::$app->request->get(); $searchSession = 'acalbums::search'; if (isset($post['search'])) { $search = $post['search']; $session->set($searchSession, $search); } elseif ($session->get($searchSession)) { $search = $session->get($searchSession); } $search['car_id'] = isset($search['car_id']) ? (int)$search['car_id'] : ''; $CarModel = new AcCar(); if (empty($search['car_id'])) { $search['car_id'] = isset($get['car_id']) ? (int)$get['car_id'] : 0; } if (!empty($search['car_id'])) { $where[] = ['=','car_id',$search['car_id']]; $car = $CarModel->findOne($search['car_id']); $search['car_title'] = isset($car->title) ? $car->title : ''; } $search['phone'] = isset($search['phone']) ? trim($search['phone']) : ''; if (!empty($search['phone'])) { $where[] = ['or',['LIKE','phone1_1',$search['phone']],['LIKE','phone1_2',$search['phone']],['LIKE','phone2_1',$search['phone']],['LIKE','phone2_2',$search['phone']]]; } $deleted = 0; if (isset($_GET['deleted'])) { $deleted = isset($_GET['deleted']) ? ((int)$_GET['deleted']>=0 ? 1 : 0) : 0; } $where[]=['=','deleted',$deleted]; $data = $model->find()->where($where); $pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']); $res = $data->offset($pages->offset)->limit($pages->limit)->indexBy('id')->all(); $status = Yii::$app->params['AlbumStatus']; $orders = []; foreach ($res as $s) { $s = $s->toArray(); $orders[$s['id']] = $s; } return $this->render('list', [ 'orders' => $orders, 'pager' => $pages, 'status'=>$status, 'search'=>$search ]); } //验新车 public function actionNewcar() { return $this->render('../layouts/dev'); $status = Yii::$app->params['AlbumStatus']; $AcAlbum = new AcAlbums(); $AcAlbum->status_code = 0; $detail = $AcAlbum->toArray(); return $this->render('modify', ['status'=>$status,'detail'=>$detail]); } /*编辑相册*/ public function actionEdit() { return $this->render('../layouts/dev'); $pid = Yii::$app->session->get('pid'); $status = Yii::$app->params['OrderStatus']; $post = Yii::$app->request->post(); $id = Yii::$app->request->get('id'); $AcOrder = new AcOrder(); $order = $AcOrder->findOne($id); $detail = $order->toArray(); $detail['thumbs'] = json_decode($detail['thumbs']); $model = new AcStore(); $store = $model->findOne($detail['store_id']); if ($store) { $detail['store_title'] = $store->title; } $model = new AcEmployee(); $employee = $model->findOne($detail['employee_id']); if ($employee) { $detail['employee_title'] = $employee->name; } $detail['car_owner_id']=$detail['car_brand_id']=$detail['car_series_id']=0; $model = new AcCar(); $car = $model->findOne($detail['car_id']); if ($car) { $detail['car_owner_id'] = $car->owner_id; $detail['car_brand_id'] = $car->brand_id; $detail['car_series_id'] = $car->series_id; $detail['car_number'] = $car->num_p.$car->num_area.$car->num_left; $detail['car_number'] = $detail['car_number'] ? $detail['car_number'] : $car->num_frame; } $model = new User(); $user = $model->findOne($detail['from_mid']); $model = new AcUserExt(); $exts = []; $_exts = $model->find()->where(['mid'=>$detail['from_mid'],'pid'=>$pid,'deleted'=>0])->indexBy('id')->all(); foreach ($_exts as $ext) { $ext = $ext->toArray(); if (isset($users[$s['id']])) { if ($ext['mobile']==$user->mobile) { $exts[$ext['mid']][$ext['key']] = $ext['value']; } } } $AcCarOwner = new AcCarOwner(); $owner = $AcCarOwner->findOne($detail['car_owner_id']); if ($owner) { $_owner = User::findOne($detail['car_owner_id']); $detail['car_owner'] = $_owner->username.'【'.$_owner->mobile.'】'; } $AcCarBrand = new AcCarBrand(); $brand = $AcCarBrand->findOne($detail['car_brand_id']); if ($brand) { $detail['car_title'] = $brand->title; } $AcCarSeries = new AcCarSeries(); $where = []; $series= $AcCarSeries->findOne($detail['car_series_id']); if ($series) { $detail['car_title'] .= $series->title; } $op = Yii::$app->request->get('op'); $tpl = 'modify'; if ($op=='print') { $tpl = 'print'; $sn = '00000000000'; //11位 $sn = substr($sn, 0, 11-strlen($id)); $sn .=$id; $detail['sn'] = $sn; } return $this->render( $tpl, [ 'status'=>$status, 'detail'=>$detail, 'store'=>$store, 'employee'=>$employee, 'id'=>$id ] ); } /*相册详情*/ public function actionDetail() { $pid = Yii::$app->session->get('pid'); $status = Yii::$app->params['OrderStatus']; $post = Yii::$app->request->post(); $id = Yii::$app->request->get('id'); $AcOrder = new AcOrder(); $order = $AcOrder->findOne($id); $detail = $order->toArray(); $detail['thumbs'] = json_decode($detail['thumbs']); $model = new AcStore(); $store = $model->findOne($detail['store_id']); if ($store) { $detail['store_title'] = $store->title; } $model = new AcEmployee(); $employee = $model->findOne($detail['employee_id']); if ($employee) { $detail['employee_title'] = $employee->name; } $detail['car_owner_id']=$detail['car_brand_id']=$detail['car_series_id']=0; $model = new AcCar(); $car = $model->findOne($detail['car_id']); if ($car) { $detail['car_owner_id'] = $car->owner_id; $detail['car_brand_id'] = $car->brand_id; $detail['car_series_id'] = $car->series_id; $detail['car_number'] = $car->num_p.$car->num_area.$car->num_left; $detail['car_number'] = $detail['car_number'] ? $detail['car_number'] : $car->num_frame; } $model = new User(); $user = $model->findOne($detail['from_mid']); $model = new AcUserExt(); $exts = []; $_exts = $model->find()->where(['mid'=>$detail['from_mid'],'pid'=>$pid,'deleted'=>0])->indexBy('id')->all(); foreach ($_exts as $ext) { $ext = $ext->toArray(); if (isset($users[$s['id']])) { if ($ext['mobile']==$user->mobile) { $exts[$ext['mid']][$ext['key']] = $ext['value']; } } } $AcCarOwner = new AcCarOwner(); $owner = $AcCarOwner->findOne($detail['car_owner_id']); if ($owner) { $_owner = User::findOne($detail['car_owner_id']); $detail['car_owner'] = $_owner->username.'【'.$_owner->mobile.'】'; } $AcCarBrand = new AcCarBrand(); $brand = $AcCarBrand->findOne($detail['car_brand_id']); if ($brand) { $detail['car_title'] = $brand->title; } $AcCarSeries = new AcCarSeries(); $where = []; $series= $AcCarSeries->findOne($detail['car_series_id']); if ($series) { $detail['car_title'] .= $series->title; } $sn = '00000000000'; //11位 $sn = substr($sn, 0, 11-strlen($id)); $sn .=$id; $detail['sn'] = $sn; return $this->render( 'detail', [ 'status'=>$status, 'detail'=>$detail, 'store'=>$store, 'employee'=>$employee, 'id'=>$id ] ); } //站点验车 public function actionOrder() { return $this->render('../layouts/dev'); $post = Yii::$app->request->post(); $id = (int)$post['id']; $pid = Yii::$app->session->get('pid'); $AcOrder = new AcOrder(); if ($id) { $order = $AcOrder->findOne($id); if ($order->create_by != Yii::$app->user->identity->id) { //不允许修改非本人操作的表单 $return['msg'] = '您不是该运单的制单人,不允许进行修改!'; $return['errorcode'] = 404; exit(json_encode($return, JSON_UNESCAPED_UNICODE)); } } //格式化数据 为空的项则不修改 //目标键=》POST键 $cols = ['start_province'=>'start_province','start_city'=>'start_city','aim_province'=>'aim_province','aim_city'=>'aim_city','signer'=>'signer','sender_name'=>'sender_name','sender_idcard'=>'sender_idcard','sender_mobiles'=>'sender_mobiles','receiver_name'=>'receiver_name','receiver_idcard'=>'receiver_idcard','receiver_mobiles'=>'receiver_mobiles','aim_address'=>'aim_address','thumb_f'=>'thumb_f','thumb_b'=>'thumb_b','thumb_l'=>'thumb_l','thumb_r'=>'thumb_r','car_extra'=>'car_extra','bind'=>'bind','driving_lisence'=>'driving_lisence']; foreach ($cols as $col=>$key) { if (isset($post[$key]) && $post[$key] !='') { $data[$col] = trim($post[$key]); } // $data[$col] = isset($post[$key]) ? trim($post[$key]) : ''; } $cols = ['car_id'=>'car_id','employee_id'=>'employee_id','car_value'=>'car_value','fee_insurance'=>'fee_insurance','fee_truck'=>'fee_truck','fee_deliver'=>'fee_deliver','fee_pickup'=>'fee_pickup','fee_urgent'=>'fee_urgent','fee_extra'=>'fee_extra','fee_total'=>'fee_total','pay_send'=>'pay_send','pay_receive'=>'pay_receive','is_checked'=>'is_checked','no_driving_lisence'=>'no_driving_lisence','start_km'=>'start_km','not_insurance'=>'not_insurance']; foreach ($cols as $col=>$key) { if (isset($post[$key]) && $post[$key] !='') { $data[$col] = (int)$post[$key]; } // $data[$col] = isset($post[$key]) ? (int)$post[$key] : 0; } //图片组处理 $cols = ['thumbs'=>'thumbs']; foreach ($cols as $col=>$key) { if (isset($post[$key]) && !empty($post[$key])) { $imgs = $post[$key]; //数组格式 $imgs = array_unique($imgs); $imgs = json_encode($imgs); $data[$col] = $imgs; } } $cols = ['remark'=>'editor']; foreach ($cols as $col=>$key) { if (isset($post[$key]) && $post[$key] !='') { $data[$col] = htmlspecialchars($post[$key]); } // $data[$col] = isset($post[$key]) ? htmlspecialchars($post[$key]) : ''; } $sign_date = isset($post['sign_date']) ? strtotime($post['sign_date']) : ''; if (!$id) { $data['create_by'] = Yii::$app->user->identity->id; $data['sign_date'] = $sign_date ? $sign_date : time(); } //部分规则校验 $has_err = false; $data['is_cwqr'] = 0; //修改财务确认状态为待确认 if (!$id) { $data['status_code'] = 1; } /*不投保的,保额不超过20W,保费为0*/ if ($data['not_insurance']) { if ($data['fee_insurance']) { $data['fee_insurance']=0; \Yii::$app->getSession()->setFlash('warning', '勾选了不投保,已强制修改保费为0!'); } if ($data['car_value']>Yii::$app->params['DefaultCarInsuranceValueMax']) { $has_err = true; $data['car_value'] = Yii::$app->params['DefaultCarInsuranceValueMax']; \Yii::$app->getSession()->setFlash('danger', '勾选了不投保,默认最高赠送的运输险保额不超过'.Yii::$app->params['DefaultCarInsuranceValueMax'].'万元,已自动强制校正'); } } $fee_total = $data['fee_truck']+$data['fee_insurance']+$data['fee_deliver']+$data['fee_pickup']+$data['fee_urgent']+$data['fee_extra']; $fee_pay = $data['pay_send']+$data['pay_receive']; if (!$data['fee_truck']) { $has_err = true; \Yii::$app->getSession()->setFlash('danger', '请注意,运费未正确填写!'); } if (!$data['pay_send']&&!$data['pay_receive']) { $has_err = true; \Yii::$app->getSession()->setFlash('danger', '请注意,到收运费及起运地预收运费均未填写!'); } if ($fee_total !=$data['fee_total']) { $has_err = true; \Yii::$app->getSession()->setFlash('danger', '请注意,所填运费、保费、提车费、送车费、额外费用、加急费等各项费用汇总的值与所填写的总费用不一致,请检查并更新'); } if ($fee_pay !=$data['fee_total']) { $has_err = true; \Yii::$app->getSession()->setFlash('danger', '请注意,所填起运地预付运费、到收运费的汇总值与所填写的总费用不一致,请检查并更新'); } $data['create_at'] = time(); $data['update_at'] = $data['create_at']; $data['pid'] = $pid; $model = new AcEmployee(); $employee = $model->findOne($data['employee_id']); if ($employee) { $data['store_id'] = $employee->store_id; } //保存资料 if ($id) { unset($data['create_at']); $res = $AcOrder->updateAll($data, ['id'=>$id]); } else { foreach ($data as $key=>$val) { $AcOrder->$key = $val; } $res = $AcOrder->save(); $id = $AcOrder->attributes['id']; //获取插入后id } if ($res) { if ($has_err) { \Yii::$app->getSession()->setFlash('success', '订单保存成功,但有价格数据录入错误,请根据情况检查更新!'); } else { \Yii::$app->getSession()->setFlash('success', '订单保存成功!'); } return $this->redirect(['edit','id'=>$id]); } else { \Yii::$app->getSession()->setFlash('warning', '订单保存失败!'); return $this->goBack(); } } }