优化ctms-api语法、修复已知BUG;
主要修复ctms-api、dacms对PHP新版本的支持问题
This commit is contained in:
+415
@@ -0,0 +1,415 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:27:54+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:17:02+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
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);
|
||||
} else if ($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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+604
@@ -0,0 +1,604 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:29:34+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:17:16+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcCar;
|
||||
use addons\models\AcCarOwner;
|
||||
use addons\models\AcCarBrand;
|
||||
use addons\models\AcCarSeries;
|
||||
use common\models\Member as User;
|
||||
use addons\models\AcUserExt;
|
||||
|
||||
class CarController extends Common
|
||||
{
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('../layouts/dev', []);
|
||||
}
|
||||
|
||||
//车辆列表
|
||||
public function actionList()
|
||||
{
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$session = Yii::$app->session;
|
||||
$AcCar = new AcCar();
|
||||
$where = $where2 = [];
|
||||
$where['pid'] = $pid;
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$searchSession = 'cars::search';
|
||||
if (isset($_GET['reset']) && $_GET['reset'] == 1) {
|
||||
$post['search'] = [];
|
||||
}
|
||||
if (isset($post['search'])) {
|
||||
$search = $post['search'];
|
||||
$session->set($searchSession, $search);
|
||||
// }elseif($session->get($searchSession)){
|
||||
// $search = $session->get($searchSession);
|
||||
}
|
||||
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = 'or';
|
||||
$where2[] = ['LIKE', 'num_left', $search['title']];
|
||||
$where2[] = ['LIKE', 'num_frame', $search['title']];
|
||||
}
|
||||
$search['brand'] = isset($search['brand_id']) ? trim(htmlspecialchars_decode($search['brand'])) : '';
|
||||
$search['brand_id'] = isset($search['brand_id']) ? (int)$search['brand_id'] : 0;
|
||||
if (!empty($search['brand_id'])) {
|
||||
$where['brand_id'] = $search['brand_id'];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $AcCar->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby('id DESC')->all();
|
||||
|
||||
$oids = $mids = $bids = $sids = [];
|
||||
if ($res) {
|
||||
foreach ($res as $r) {
|
||||
$oids[] = $r->owner_id;
|
||||
$mids[] = $r->mid;
|
||||
$bids[] = $r->brand_id;
|
||||
$sids[] = $r->series_id;
|
||||
}
|
||||
}
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$AcCarOwner = new AcCarOwner();
|
||||
$where = [];
|
||||
$where['pid'] = $pid;
|
||||
$_owners = $AcCarOwner->find()->where($where)->andwhere(['in', 'id', $oids])->all();
|
||||
$owners = [];
|
||||
foreach ($_owners as $s) {
|
||||
$owners[$s->id] = $s->toArray();
|
||||
}
|
||||
$User = new User();
|
||||
$where = [];
|
||||
$_users = $User->find()->where($where)->andwhere(['in', 'id', $mids])->all();
|
||||
$users = [];
|
||||
foreach ($_users as $s) {
|
||||
$users[$s->id] = $s->toArray();
|
||||
}
|
||||
$AcUserExt = new AcUserExt();
|
||||
$userExts = $AcUserExt->find()->where(['pid' => $pid, 'deleted' => 0])->andWhere(['in', 'mid', $mids])->all();
|
||||
$exts = [];
|
||||
if ($userExts) {
|
||||
foreach ($userExts as $v) {
|
||||
$exts[$v->mid][$v->key] = $v->value;
|
||||
}
|
||||
if ($exts) {
|
||||
foreach ($exts as $i => $ext) {
|
||||
$_owner = $users[$i] ? $users[$i] : [];
|
||||
if ($ext['title']) {
|
||||
$_owner['owner_title'] = $ext['title'];
|
||||
}
|
||||
if ($ext['nickname']) {
|
||||
$_owner['owner_title'] = $ext['nickname'];
|
||||
}
|
||||
if ($ext['realname']) {
|
||||
$_owner['owner_title'] = $ext['realname'];
|
||||
}
|
||||
$users[$i]['username'] = $_owner['owner_title'] . '【' . $users[$s->id]['mobile'] . '】';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$AcCarSeries = new AcCarSeries();
|
||||
$where = [];
|
||||
$series = [];
|
||||
$_series = $AcCarSeries->find()->where($where)->andwhere(['in', 'id', $sids])->all();
|
||||
if ($_series) {
|
||||
foreach ($_series as $r) {
|
||||
$series[$r->id] = $r->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
$AcCarBrand = new AcCarBrand();
|
||||
$where = [];
|
||||
$_brands = $AcCarBrand->find()->where($where)->andwhere(['in', 'id', $bids])->all();
|
||||
if ($_brands) {
|
||||
foreach ($_brands as $r) {
|
||||
$brands[$r->id] = $r->toArray();
|
||||
}
|
||||
}
|
||||
$cars = [];
|
||||
if ($res) {
|
||||
foreach ($res as $r) {
|
||||
$car = $r->toArray();
|
||||
$t = '';
|
||||
if (isset($series[$r->series_id]['title'])) {
|
||||
$t .= $brands[$r->brand_id]['title'];
|
||||
}
|
||||
$t .= '-';
|
||||
if (isset($series[$r->series_id]['title'])) {
|
||||
$t .= $series[$r->series_id]['title'];
|
||||
}
|
||||
$car['title2'] = $t;
|
||||
$car['numbers'] = $car['num_p'] . $car['num_area'] . $car['num_left'];
|
||||
$car['numbers'] = $car['numbers'] ? $car['numbers'] : $car['num_frame'];
|
||||
$cars[$r->id] = $car;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('list', [
|
||||
'cars' => $cars,
|
||||
'pager' => $pages,
|
||||
'owners' => $owners,
|
||||
'users' => $users,
|
||||
'status' => $status,
|
||||
'search' => $search
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionSelect()
|
||||
{
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$session = Yii::$app->session;
|
||||
$AcCar = new AcCar();
|
||||
$where = $where2 = [];
|
||||
$where['pid'] = $pid;
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$searchSession = 'cars::search';
|
||||
if (isset($_GET['reset']) && $_GET['reset'] == 1) {
|
||||
$post['search'] = [];
|
||||
}
|
||||
if (isset($post['search'])) {
|
||||
$search = $post['search'];
|
||||
$session->set($searchSession, $search);
|
||||
// }elseif($session->get($searchSession)){
|
||||
// $search = $session->get($searchSession);
|
||||
}
|
||||
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = 'or';
|
||||
$where2[] = ['LIKE', 'num_left', $search['title']];
|
||||
$where2[] = ['LIKE', 'num_frame', $search['title']];
|
||||
}
|
||||
$search['brand'] = isset($search['brand_id']) ? trim(htmlspecialchars_decode($search['brand'])) : '';
|
||||
$search['brand_id'] = isset($search['brand_id']) ? (int)$search['brand_id'] : 0;
|
||||
if (!empty($search['brand_id'])) {
|
||||
$where['brand_id'] = $search['brand_id'];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $AcCar->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andWhere($where2);
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby(' id DESC')->all();
|
||||
|
||||
$oids = $mids = $bids = $sids = [];
|
||||
if ($res) {
|
||||
foreach ($res as $r) {
|
||||
$oids[] = $r->owner_id;
|
||||
$mids[] = $r->mid;
|
||||
$bids[] = $r->brand_id;
|
||||
$sids[] = $r->series_id;
|
||||
}
|
||||
}
|
||||
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$AcCarOwner = new AcCarOwner();
|
||||
$where = [];
|
||||
$where['pid'] = $pid;
|
||||
$_owners = $AcCarOwner->find()->where($where)->andwhere(['in', 'id', $oids])->all();
|
||||
$owners = [];
|
||||
foreach ($_owners as $s) {
|
||||
$owners[$s->id] = $s->toArray();
|
||||
}
|
||||
$User = new User();
|
||||
$where = [];
|
||||
$_users = $User->find()->where($where)->andwhere(['in', 'id', $mids])->all();
|
||||
$users = [];
|
||||
foreach ($_users as $s) {
|
||||
$users[$s->id] = $s->toArray();
|
||||
}
|
||||
$AcUserExt = new AcUserExt();
|
||||
$userExts = $AcUserExt->find()->where(['pid' => $pid, 'deleted' => 0])->andWhere(['in', 'mid', $mids])->all();
|
||||
$exts = [];
|
||||
if ($userExts) {
|
||||
foreach ($userExts as $v) {
|
||||
$exts[$v->mid][$v->key] = $v->value;
|
||||
}
|
||||
foreach ($exts as $i => $ext) {
|
||||
$_owner = $users[$i] ? $users[$i] : [];
|
||||
if ($ext['title']) {
|
||||
$_owner['owner_title'] = $ext['title'];
|
||||
}
|
||||
if ($ext['nickname']) {
|
||||
$_owner['owner_title'] = $ext['nickname'];
|
||||
}
|
||||
if ($ext['realname']) {
|
||||
$_owner['owner_title'] = $ext['realname'];
|
||||
}
|
||||
$users[$i]['username'] = $_owner['owner_title'] . '【' . $users[$i]['mobile'] . '】';
|
||||
}
|
||||
}
|
||||
|
||||
$AcCarSeries = new AcCarSeries();
|
||||
$where = [];
|
||||
$series = [];
|
||||
$_series = $AcCarSeries->find()->where($where)->andwhere(['in', 'id', $sids])->all();
|
||||
if ($_series) {
|
||||
foreach ($_series as $r) {
|
||||
$series[$r->id] = $r->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
$AcCarBrand = new AcCarBrand();
|
||||
$where = [];
|
||||
$_brands = $AcCarBrand->find()->where($where)->andwhere(['in', 'id', $bids])->all();
|
||||
if ($_brands) {
|
||||
foreach ($_brands as $r) {
|
||||
$brands[$r->id] = $r->toArray();
|
||||
}
|
||||
}
|
||||
$cars = [];
|
||||
if ($res) {
|
||||
foreach ($res as $r) {
|
||||
$car = $r->toArray();
|
||||
$t = '';
|
||||
if (isset($series[$r->series_id]['title'])) {
|
||||
$t .= $brands[$r->brand_id]['title'];
|
||||
}
|
||||
$t .= '-';
|
||||
if (isset($series[$r->series_id]['title'])) {
|
||||
$t .= $series[$r->series_id]['title'];
|
||||
}
|
||||
$car['title2'] = $t;
|
||||
$car['numbers'] = $car['num_p'] . $car['num_area'] . $car['num_left'];
|
||||
$car['numbers'] = $car['numbers'] ? $car['numbers'] : $car['num_frame'];
|
||||
$cars[$r->id] = $car;
|
||||
}
|
||||
}
|
||||
|
||||
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'truck';
|
||||
return $this->render('select', [
|
||||
'cars' => $cars,
|
||||
'pager' => $pages,
|
||||
'owners' => $owners,
|
||||
'users' => $users,
|
||||
'status' => $status,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionNew()
|
||||
{
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$AcCar = new AcCar();
|
||||
$AcCar->status_code = 0;
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $AcCar]);
|
||||
}
|
||||
|
||||
//编辑客车资料
|
||||
public function actionEdit()
|
||||
{
|
||||
$model = new AcCar();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
}
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
|
||||
$AcCarOwner = new AcCarOwner();
|
||||
$owner = $AcCarOwner->find()->where(['id' => $res['owner_id']])->one();
|
||||
if ($owner) {
|
||||
$mid = $owner->mid;
|
||||
$User = new User();
|
||||
$user = $User->find()->where(['id' => $mid])->one();
|
||||
if ($user) {
|
||||
$res['owner_title'] = $user->username . '【' . $user->mobile . '】';
|
||||
}
|
||||
$AcUserExt = new AcUserExt();
|
||||
$userExt = $AcUserExt->find()->where(['pid' => $pid, 'mid' => $res['mid'], 'deleted' => 0])->all();
|
||||
$exts = [];
|
||||
if ($userExt) {
|
||||
foreach ($userExt as $v) {
|
||||
$exts[$v->key] = $v->value;
|
||||
}
|
||||
if ($exts['title']) {
|
||||
$res['owner_title'] = $exts['title'];
|
||||
}
|
||||
if ($exts['nickname']) {
|
||||
$res['owner_title'] = $exts['nickname'];
|
||||
}
|
||||
if ($exts['realname']) {
|
||||
$res['owner_title'] = $exts['realname'];
|
||||
}
|
||||
$res['owner_title'] = $res['owner_title'] . '【' . $user->mobile . '】';
|
||||
}
|
||||
}
|
||||
$AcCarSeries = new AcCarSeries();
|
||||
$series = $AcCarSeries->find()->where(['id' => $res['series_id']])->one();
|
||||
if ($series) {
|
||||
$res['series_title'] = $series->title;
|
||||
}
|
||||
$AcCarBrand = new AcCarBrand();
|
||||
$brand = $AcCarBrand->find()->where(['id' => $res['brand_id']])->one();
|
||||
if ($brand) {
|
||||
$res['brand_title'] = $brand->title;
|
||||
}
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $res]);
|
||||
}
|
||||
|
||||
//复制客车资料后新建
|
||||
public function actionCopy()
|
||||
{
|
||||
$model = new AcCar();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
}
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
|
||||
$AcCarSeries = new AcCarSeries();
|
||||
$series = $AcCarSeries->find()->where(['id' => $res['series_id']])->one();
|
||||
if ($series) {
|
||||
$res['series_title'] = $series->title;
|
||||
}
|
||||
$AcCarBrand = new AcCarBrand();
|
||||
$brand = $AcCarBrand->find()->where(['id' => $res['brand_id']])->one();
|
||||
if ($brand) {
|
||||
$res['brand_title'] = $brand->title;
|
||||
}
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$res['id'] = 0;
|
||||
$res['num_p'] = $res['num_area'] = $res['num_left'] = $res['num_frame'] = '';
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $res]);
|
||||
}
|
||||
|
||||
//浏览客车详情
|
||||
public function actionDetail()
|
||||
{
|
||||
$model = new AcCar();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
}
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
|
||||
$AcCarOwner = new AcCarOwner();
|
||||
$owner = $AcCarOwner->find()->where(['id' => $res['owner_id']])->one();
|
||||
$User = new User();
|
||||
$user = $User->find()->where(['id' => $res['mid']])->one();
|
||||
if ($user) {
|
||||
$res['owner_title'] = $user->username . '【' . $user->mobile . '】';
|
||||
}
|
||||
$AcUserExt = new AcUserExt();
|
||||
$userExt = $AcUserExt->find()->where(['pid' => $pid, 'mid' => $res['mid'], 'deleted' => 0])->all();
|
||||
$exts = [];
|
||||
if ($userExt) {
|
||||
foreach ($userExt as $v) {
|
||||
$exts[$v->key] = $v->value;
|
||||
}
|
||||
if ($exts['title']) {
|
||||
$res['owner_title'] = $exts['title'];
|
||||
}
|
||||
if ($exts['nickname']) {
|
||||
$res['owner_title'] = $exts['nickname'];
|
||||
}
|
||||
if ($exts['realname']) {
|
||||
$res['owner_title'] = $exts['realname'];
|
||||
}
|
||||
$res['owner_title'] = $res['owner_title'] . '【' . $user->mobile . '】';
|
||||
}
|
||||
$AcCarSeries = new AcCarSeries();
|
||||
$series = $AcCarSeries->find()->where(['id' => $res['series_id']])->one();
|
||||
if ($series) {
|
||||
$res['series_title'] = $series->title;
|
||||
}
|
||||
$AcCarBrand = new AcCarBrand();
|
||||
$brand = $AcCarBrand->find()->where(['id' => $res['brand_id']])->one();
|
||||
if ($brand) {
|
||||
$res['brand_title'] = $brand->title;
|
||||
}
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
return $this->render('detail', ['status' => $status, 'detail' => $res]);
|
||||
}
|
||||
|
||||
//保存车辆资料
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['title' => 'title', 'num_frame' => 'num_frame', 'num_p' => 'num_p', 'num_area' => 'num_area', 'num_left' => 'num_left'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
//查询车牌号是否在库
|
||||
$hasCar = FALSE;
|
||||
if (!$data['num_frame']) {
|
||||
$hasCar = AcCar::find()->where(['num_p' => $data['num_p'], 'num_area' => $data['num_area'], 'num_left' => $data['num_left']])->one();
|
||||
}
|
||||
|
||||
if ($hasCar) {
|
||||
if ($id && $id != $hasCar->id) {
|
||||
\Yii::$app->getSession()->setFlash('danger', '保存失败,该车牌号已在库!');
|
||||
return $this->goBack();
|
||||
} else {
|
||||
$id = $hasCar->id;
|
||||
}
|
||||
}
|
||||
|
||||
$cols = ['brand_id' => 'brand_id', 'series_id' => 'series_id', 'owner_id' => 'owner_id', 'status_code' => 'status_code', 'deleted' => 'deleted'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
$cols = ['remark' => 'editor'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? htmlspecialchars($post[$key]) : '';
|
||||
}
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
// $data['status_code'] = 1;
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//填补mid参数
|
||||
$AcCarOwner = new AcCarOwner();
|
||||
$owner = $AcCarOwner->findOne($data['owner_id']);
|
||||
if ($owner) {
|
||||
$data['mid'] = $owner->mid;
|
||||
}
|
||||
|
||||
//保存车辆资料
|
||||
$AcCar = new AcCar();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcCar->$key = $val;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$AcCar->id = $id;
|
||||
unset($data['create_at']);
|
||||
$res = $AcCar->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcCar->save();
|
||||
$id = $AcCar->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '车辆资料保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '车辆资料保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
}
|
||||
|
||||
//删除车辆
|
||||
public function actionDelete()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
|
||||
$model = new AcCar();
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
$return['url'] = Url::toRoute('car/list');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '车辆删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '车辆删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
|
||||
$model = new AcCar();
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
$return = [];
|
||||
$return['timeout'] = 1; //3秒后自动跳转
|
||||
// $return['status_code'] = 0;
|
||||
$return['ajax'] = 1;
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
} else {
|
||||
$return['msg'] = '车辆数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'hide':
|
||||
$data['status_code'] = 0;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '车辆隐藏标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'default'];
|
||||
} else {
|
||||
$return['msg'] = '车辆隐藏标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$data['status_code'] = 1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '车辆显示记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'primary'];
|
||||
} else {
|
||||
$return['msg'] = '车辆显示标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
+266
@@ -0,0 +1,266 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:28:54+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:17:11+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcCarBrand;
|
||||
|
||||
class CarbrandController extends Common
|
||||
{
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('../layouts/dev', []);
|
||||
}
|
||||
|
||||
//车品牌列表
|
||||
public function actionList()
|
||||
{
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$model = new AcCarBrand();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = $pid;
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'title', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$brands = [];
|
||||
foreach ($res as $s) {
|
||||
$s = $s->toArray();
|
||||
$brands[$s['id']] = $s;
|
||||
}
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
|
||||
return $this->render('list', [
|
||||
'brands' => $brands,
|
||||
'pager' => $pages,
|
||||
'status' => $status,
|
||||
'search' => $search
|
||||
]);
|
||||
}
|
||||
|
||||
//车品牌列表
|
||||
public function actionSelect()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$model = new AcCarBrand();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = $pid;
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'title', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$brands = [];
|
||||
foreach ($res as $s) {
|
||||
$s = $s->toArray();
|
||||
$brands[$s['id']] = $s;
|
||||
}
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'car';
|
||||
return $this->render('select', [
|
||||
'brands' => $brands,
|
||||
'pager' => $pages,
|
||||
'status' => $status,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
}
|
||||
|
||||
//新增车品牌
|
||||
public function actionNew()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$AcCarBrand = new AcCarBrand();
|
||||
$AcCarBrand->status_code = 0;
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $AcCarBrand->toArray()]);
|
||||
}
|
||||
|
||||
//更新车品牌
|
||||
public function actionEdit()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$model = new AcCarBrand();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
} else {
|
||||
$res = [];
|
||||
}
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
return $this->render('modify', [
|
||||
'detail' => $res,
|
||||
'status' => $status,
|
||||
'id' => $id,
|
||||
]);
|
||||
}
|
||||
|
||||
//保存车品牌资料
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
|
||||
//格式化数据
|
||||
$data = [];
|
||||
$data['title'] = trim($post['title']);
|
||||
//目标键=》POST键
|
||||
$cols = ['status_code' => 'status_code', 'deleted' => 'deleted'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//格式化资料
|
||||
$AcCarBrand = new AcCarBrand();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcCarBrand->$key = $val;
|
||||
}
|
||||
|
||||
//资料入库
|
||||
if ($id) {
|
||||
$AcCarBrand->id = $id;
|
||||
unset($data['create_at']);
|
||||
$res = $AcCarBrand->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcCarBrand->save();
|
||||
$id = $AcCarBrand->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '车主资料保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '车主资料保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
}
|
||||
|
||||
//删除用户
|
||||
public function actionDelete($id)
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
|
||||
$model = new AcCarBrand();
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
$return['url'] = Url::toRoute('carbrand/list');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
|
||||
$model = new AcCarBrand();
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
$return = [];
|
||||
$return['timeout'] = 1; //3秒后自动跳转
|
||||
$return['status_code'] = 0;
|
||||
$return['ajax'] = 1;
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
} else {
|
||||
$return['msg'] = '品牌数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'hide':
|
||||
$data['status_code'] = 0;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '品牌隐藏标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'info'];
|
||||
} else {
|
||||
$return['msg'] = '品牌隐藏标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$data['status_code'] = 1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '品牌显示标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'default'];
|
||||
} else {
|
||||
$return['msg'] = '品牌显示标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
+673
@@ -0,0 +1,673 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:29:55+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:17:22+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcCar;
|
||||
use addons\models\AcCarOwner;
|
||||
use addons\models\AcStore;
|
||||
use addons\models\AcEmployee;
|
||||
|
||||
use common\models\Member as User;
|
||||
use addons\models\AcUserExt;
|
||||
|
||||
use common\models\CSms;
|
||||
use common\models\CVcode;
|
||||
|
||||
use vendor\aliyun\dysms\Sms;
|
||||
|
||||
class CarownerController extends Common
|
||||
{
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
return $this->render('../layouts/dev', []);
|
||||
}
|
||||
|
||||
//车主用户列表
|
||||
public function actionList()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$model = new AcCarOwner();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = $pid;
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'name', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
// $data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->indexBy('mid')->all();
|
||||
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$gender = Yii::$app->params['gender'];
|
||||
|
||||
$model = new AcStore();
|
||||
$where = [];
|
||||
$where['pid'] = $pid;
|
||||
$_stores = $model->find()->where($where)->all();
|
||||
$stores = [];
|
||||
foreach ($_stores as $s) {
|
||||
$stores[$s->id] = $s->toArray();
|
||||
}
|
||||
|
||||
$eids = $mids = [];
|
||||
foreach ($res as $r) {
|
||||
$eids[$r['employee_id']] = $r['employee_id'];
|
||||
$mids[$r['mid']] = $r['mid'];
|
||||
}
|
||||
|
||||
$model = new AcEmployee();
|
||||
$employees = [];
|
||||
$_employees = $model->find()->where(['in', 'id', $eids])->indexBy('id')->all();
|
||||
foreach ($_employees as $s) {
|
||||
$employees[$s->id] = $s->toArray();
|
||||
}
|
||||
|
||||
$model = new User();
|
||||
$users = [];
|
||||
$_users = $model->find()->where(['in', 'id', $mids])->all();
|
||||
foreach ($_users as $s) {
|
||||
$s = $s->toArray();
|
||||
$users[$s['id']] = $s;
|
||||
}
|
||||
|
||||
$model = new AcUserExt();
|
||||
$exts = [];
|
||||
$_exts = $model->find()->where(['in', 'mid', $mids])->andwhere(['pid' => $pid, 'deleted' => 0])->indexBy('id')->all();
|
||||
foreach ($_exts as $ext) {
|
||||
$ext = $ext->toArray();
|
||||
if (isset($users[$ext['mid']])) {
|
||||
if ($ext['mobile'] == $users[$ext['mid']]['mobile']) {
|
||||
$exts[$ext['mid']][$ext['key']] = $ext['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$owners = [];
|
||||
foreach ($res as $s) {
|
||||
$s = $s->toArray();
|
||||
if (isset($exts[$s['mid']])) {
|
||||
foreach ($exts[$s['mid']] as $col => $val) {
|
||||
$s[$col] = $val;
|
||||
}
|
||||
}
|
||||
$owners[$s['id']] = $s;
|
||||
}
|
||||
|
||||
return $this->render('list', [
|
||||
'owners' => $owners,
|
||||
'pager' => $pages,
|
||||
'employees' => $employees,
|
||||
'stores' => $stores,
|
||||
'exts' => $exts,
|
||||
'users' => $users,
|
||||
'status' => $status,
|
||||
'gender' => $gender,
|
||||
'search' => $search
|
||||
]);
|
||||
}
|
||||
|
||||
//车主用户选择
|
||||
public function actionSelect()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$model = new AcCarOwner();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = $pid;
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'name', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
// $data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->indexBy('mid')->all();
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$gender = Yii::$app->params['gender'];
|
||||
|
||||
$model = new AcStore();
|
||||
$where = [];
|
||||
$where['pid'] = $pid;
|
||||
$_stores = $model->find()->where($where)->all();
|
||||
$stores = [];
|
||||
foreach ($_stores as $s) {
|
||||
$stores[$s->id] = $s->toArray();
|
||||
}
|
||||
|
||||
$eids = $mids = [];
|
||||
foreach ($res as $r) {
|
||||
$eids[$r['employee_id']] = $r['employee_id'];
|
||||
$mids[$r['mid']] = $r['mid'];
|
||||
}
|
||||
|
||||
$model = new AcEmployee();
|
||||
$employees = [];
|
||||
$_employees = $model->find()->where(['in', 'id', $eids])->indexBy('id')->all();
|
||||
foreach ($_employees as $s) {
|
||||
$employees[$s->id] = $s->toArray();
|
||||
}
|
||||
|
||||
$model = new User();
|
||||
$users = [];
|
||||
$_users = $model->find()->where(['in', 'id', $mids])->all();
|
||||
foreach ($_users as $s) {
|
||||
$s = $s->toArray();
|
||||
$users[$s['id']] = $s;
|
||||
}
|
||||
|
||||
$model = new AcUserExt();
|
||||
$exts = [];
|
||||
$_exts = $model->find()->where(['in', 'mid', $mids])->andwhere(['pid' => $pid, 'deleted' => 0])->indexBy('id')->all();
|
||||
foreach ($_exts as $ext) {
|
||||
$ext = $ext->toArray();
|
||||
if (isset($users[$ext['mid']])) {
|
||||
if ($ext['mobile'] == $users[$ext['mid']]['mobile']) {
|
||||
$exts[$ext['mid']][$ext['key']] = $ext['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$owners = [];
|
||||
foreach ($res as $s) {
|
||||
$s = $s->toArray();
|
||||
if (isset($exts[$s['mid']])) {
|
||||
foreach ($exts[$s['mid']] as $col => $val) {
|
||||
$s[$col] = $val;
|
||||
}
|
||||
}
|
||||
$owners[$s['id']] = $s;
|
||||
}
|
||||
|
||||
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'carowner';
|
||||
return $this->render('select', [
|
||||
'owners' => $owners,
|
||||
'pager' => $pages,
|
||||
'employees' => $employees,
|
||||
'stores' => $stores,
|
||||
'exts' => $exts,
|
||||
'users' => $users,
|
||||
'status' => $status,
|
||||
'gender' => $gender,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
}
|
||||
|
||||
//新增车主
|
||||
public function actionNew()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$levels = Yii::$app->params['customerLevels'];
|
||||
return $this->render('modify', ['levels' => $levels]);
|
||||
}
|
||||
|
||||
//更新车主
|
||||
public function actionEdit()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$levels = Yii::$app->params['customerLevels'];
|
||||
$model = new AcCarOwner();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
$res['last_send'] = $res['last_send'] ? date('Y-m-d', $res['last_send']) : '';
|
||||
$res['last_contact'] = $res['last_contact'] ? date('Y-m-d', $res['last_contact']) : '';
|
||||
} else {
|
||||
$res = [];
|
||||
}
|
||||
|
||||
//查询对应的系统用户
|
||||
$userModel = new User();
|
||||
$user = User::find()->where(['id' => $res['mid']])->one();
|
||||
$res['mobile'] = '';
|
||||
if ($user) {
|
||||
$res['mobile'] = $user->mobile;
|
||||
}
|
||||
|
||||
$store = AcStore::find()->where(['id' => $res['store_id']])->one();
|
||||
if ($store) {
|
||||
$res['store_title'] = $store->title;
|
||||
}
|
||||
|
||||
$employee = AcEmployee::find()->where(['id' => $res['employee_id']])->one();
|
||||
if ($employee) {
|
||||
$res['employee_title'] = $employee->name;
|
||||
}
|
||||
|
||||
$exts = AcUserExt::find()->where(['mid' => $res['mid'], 'mobile' => $res['mobile'], 'pid' => $pid, 'deleted' => 0])->all();
|
||||
if ($exts) {
|
||||
foreach ($exts as $ext) {
|
||||
$res[$ext['key']] = $ext['value'];
|
||||
}
|
||||
}
|
||||
|
||||
// memory_get_usage();//查看当前内存,字节
|
||||
|
||||
return $this->render('modify', [
|
||||
'detail' => $res,
|
||||
'levels' => $levels,
|
||||
'id' => $id,
|
||||
]);
|
||||
}
|
||||
|
||||
//保存车主资料
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
if (!$post['mobile']) {
|
||||
\Yii::$app->getSession()->setFlash('warning', '请输入主手机号码!');
|
||||
$url = Url::toRoute(['carowner/edit', 'id' => $id]);
|
||||
return $this->redirect(['modify', 'id' => $id]);
|
||||
}
|
||||
|
||||
$mobile = $post['mobile'];
|
||||
//查询对应的系统用户
|
||||
$userModel = new User();
|
||||
$user = User::find()->where(['mobile' => $mobile])->one();
|
||||
if (!$user) {
|
||||
$pwd = isset($post['password']) ? trim($post['password']) : Yii::$app->params['defaultUserPassword'];
|
||||
$username = isset($post['realname']) ? trim($post['realname']) : (isset($post['nickname']) ? trim($post['nickname']) : $mobile);
|
||||
$userModel->mobile = $mobile;
|
||||
$userModel->username = $username;
|
||||
$userModel->email = $mobile . '@hiluker.com';
|
||||
$userModel->setPassword($pwd);
|
||||
$userModel->generateAuthKey();
|
||||
$userModel->avatar = Yii::$app->params['defaultUserAvatar'];
|
||||
$userModel->created_at = time();
|
||||
$userModel->status = 1;
|
||||
$userModel->save();
|
||||
$user_id = $userModel->attributes['id']; //获取插入后id
|
||||
} else {
|
||||
$user_id = $user->id;
|
||||
}
|
||||
|
||||
//格式化数据
|
||||
$data = [];
|
||||
//目标键=》POST键
|
||||
$cols = ['gender' => 'gender', 'total_fee' => 'total_fee', 'level' => 'level', 'score' => 'score', 'store_id' => 'store', 'employee_id' => 'employee', 'status_code' => 'status_code', 'deleted' => 'deleted'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
$cols = ['last_send' => 'last_send', 'last_contact' => 'last_contact'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? strtotime($post[$key]) : 0;
|
||||
}
|
||||
$cols = ['remark' => 'editor'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? htmlspecialchars($post[$key]) : '';
|
||||
}
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
$data['pid'] = $pid;
|
||||
$data['mid'] = $user_id;
|
||||
|
||||
//格式化车主资料
|
||||
$AcCarOwner = new AcCarOwner();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcCarOwner->$key = $val;
|
||||
}
|
||||
|
||||
//查询该车主是否在库
|
||||
$carOwner = AcCarOwner::find()->where(['pid' => $data['pid'], 'mid' => $data['mid']])->one();
|
||||
if ($carOwner) {
|
||||
$id = $carOwner->id;
|
||||
}
|
||||
|
||||
//车主资料入库
|
||||
if ($id) {
|
||||
$AcCarOwner->id = $id;
|
||||
unset($data['create_at']);
|
||||
$res = $AcCarOwner->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcCarOwner->save();
|
||||
$id = $AcCarOwner->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
//保存扩展资料
|
||||
$AcUserExt = new AcUserExt();
|
||||
//批量硬删及软删
|
||||
// $AcUserExt->updateAll(['deleted'=>1],['deleted'=>0,'pid'=>$pid,'mid'=>$user_id]);
|
||||
$AcUserExt->deleteAll(['deleted' => 9, 'pid' => $pid, 'mid' => $user_id]); //硬删,变更历史8次的
|
||||
$AcUserExt->updateAllCounters(['deleted' => 1], ['pid' => $pid, 'mid' => $user_id]); //更新已有数据
|
||||
|
||||
$datas = [];
|
||||
$data = [];
|
||||
$cols = ['realname' => 'realname', 'nickname' => 'nickname', 'title' => 'title', 'password' => 'password', 'mobiles' => 'mobiles', 'thumb' => 'thumb', 'province' => 'province', 'idcard' => 'idcard'];
|
||||
foreach ($cols as $col => $key) {
|
||||
// $data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
$data['pid'] = $pid;
|
||||
$data['mid'] = $user_id;
|
||||
$data['key'] = $col;
|
||||
$data['mobile'] = $mobile;
|
||||
$data['value'] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
$datas[] = $data;
|
||||
}
|
||||
//批量插入
|
||||
$model = clone $AcUserExt;
|
||||
foreach ($datas as $attributes) {
|
||||
$model->isNewRecord = TRUE;
|
||||
$model->setAttributes($attributes, FALSE);
|
||||
$model->save() && $model->id = 0;
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '车主资料保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '车主资料保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
|
||||
// $return = [];
|
||||
// if($res){
|
||||
// $return['msg'] = '车主信息保存成功';
|
||||
// $return['errorcode'] = 200;
|
||||
// $return['url'] = Url::toRoute(['carowner/edit','id'=>$id]);
|
||||
// $return['buttons'] = [
|
||||
// ['title'=>'好的,我知道了','class'=>'primary','url'=>$return['url']]
|
||||
// ];
|
||||
// }else{
|
||||
// $return['msg'] = '车主信息保存失败';
|
||||
// $return['errorcode'] = 0;
|
||||
// $return['url'] = Url::toRoute(['carowner/new',$post]);
|
||||
// $return['buttons'] = [
|
||||
// ['title'=>'好的,我知道了','class'=>'info','url'=>$return['url']]
|
||||
// ];
|
||||
// }
|
||||
|
||||
// $classes = ['0'=>'warning','200'=>'success'];
|
||||
// $return['content'] = $return['msg'];
|
||||
// $return['class'] = $classes[$return['errorcode']];
|
||||
|
||||
// Yii::$app->request->setBodyParams($return);
|
||||
// return Yii::$app->runAction('index/msg');
|
||||
}
|
||||
|
||||
//删除用户
|
||||
public function actionDelete($id)
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
|
||||
$model = new AcCarOwner();
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
$return['url'] = Url::toRoute('carowner/list');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
|
||||
$model = new AcCarOwner();
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
$return = [];
|
||||
$return['timeout'] = 1; //3秒后自动跳转
|
||||
$return['status_code'] = 0;
|
||||
$return['ajax'] = 1;
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
} else {
|
||||
$return['msg'] = '车主数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'hide':
|
||||
$data['status_code'] = 0;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '车主隐藏标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'info'];
|
||||
} else {
|
||||
$return['msg'] = '车主隐藏标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$data['status_code'] = 1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '车主显示标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'default'];
|
||||
} else {
|
||||
$return['msg'] = '车主显示标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
//短信营销
|
||||
public function actionMsg()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$levels = Yii::$app->params['customerLevels'];
|
||||
$model = new AcCarOwner();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
$res['last_send'] = $res['last_send'] ? date('Y-m-d', $res['last_send']) : '';
|
||||
$res['last_contact'] = $res['last_contact'] ? date('Y-m-d', $res['last_contact']) : '';
|
||||
} else {
|
||||
$res = [];
|
||||
}
|
||||
|
||||
//查询对应的系统用户
|
||||
$userModel = new User();
|
||||
$user = User::find()->where(['id' => $res['mid']])->one();
|
||||
$res['mobile'] = '';
|
||||
if ($user) {
|
||||
$res['mobile'] = $user->mobile;
|
||||
}
|
||||
|
||||
$store = AcStore::find()->where(['id' => $res['store_id']])->one();
|
||||
if ($store) {
|
||||
$res['store_title'] = $store->title;
|
||||
}
|
||||
|
||||
$employee = AcEmployee::find()->where(['id' => $res['employee_id']])->one();
|
||||
if ($store) {
|
||||
$res['employee_title'] = $employee->name;
|
||||
}
|
||||
|
||||
$exts = AcUserExt::find()->where(['mid' => $res['mid'], 'mobile' => $res['mobile'], 'pid' => $pid, 'deleted' => 0])->all();
|
||||
if ($exts) {
|
||||
foreach ($exts as $ext) {
|
||||
$res[$ext['key']] = $ext['value'];
|
||||
}
|
||||
}
|
||||
|
||||
$op = Yii::$app->request->get('op');
|
||||
$opp = Yii::$app->request->get('opp');
|
||||
if (!$op) {
|
||||
return $this->render('msg', [
|
||||
'detail' => $res,
|
||||
'levels' => $levels,
|
||||
'id' => $id,
|
||||
]);
|
||||
} else if ($op == 'send') {
|
||||
$option = [];
|
||||
$config = [];
|
||||
$config['accessKeyId'] = Yii::$app->params['aliDySms']['accessKeyId'];
|
||||
$config['accessKeySecret'] = Yii::$app->params['aliDySms']['accessKeySecret'];
|
||||
$config['sign'] = Yii::$app->params['aliDySms']['sign'];
|
||||
$sms = new Sms($option, $config);
|
||||
$phone = $res['mobile'];
|
||||
$content = [];
|
||||
switch ($opp) {
|
||||
case 'vcode': //发送验证码
|
||||
$code = mt_rand(1000, 9999);
|
||||
$content['code'] = $code;
|
||||
$tmpl = Yii::$app->params['aliDySms']['tmpl']['vcode'];
|
||||
//验证码入库
|
||||
$vcodeModel = new CVcode();
|
||||
$vcode = [];
|
||||
$vcode['code'] = $code;
|
||||
$vcode['mobile'] = $phone;
|
||||
$vcode['create_at'] = time();
|
||||
foreach ($vcode as $key => $val) {
|
||||
$vcodeModel->$key = $val;
|
||||
}
|
||||
$vcodeModel->save();
|
||||
break;
|
||||
case 'birthday': //发送生日祝福
|
||||
$realname = isset($res['realname']) ? $res['realname'] : 'VIP';
|
||||
$content['name'] = $realname;
|
||||
$content['company'] = Yii::$app->request->post('company');
|
||||
$content['company'] = $content['company'] ? $content['company'] : '安诚托车';
|
||||
$tmpl = Yii::$app->params['aliDySms']['tmpl']['acBirthday'];
|
||||
break;
|
||||
}
|
||||
$result = $sms->send($phone, $tmpl, $content);
|
||||
//保存发送记录
|
||||
$smsModel = new CSms();
|
||||
$smsdata = [];
|
||||
$sid = Yii::$app->session->get('sid');
|
||||
$smsdata['sid'] = (int)$sid;
|
||||
$smsdata['pid'] = $pid;
|
||||
$smsdata['uid'] = Yii::$app->user->identity->id;
|
||||
$smsdata['mobile'] = $phone;
|
||||
$smsdata['content'] = json_encode($content, JSON_UNESCAPED_UNICODE);
|
||||
$smsdata['create_at'] = time();
|
||||
foreach ($smsdata as $key => $val) {
|
||||
$smsModel->$key = $val;
|
||||
}
|
||||
$smsModel->save();
|
||||
|
||||
$return = [];
|
||||
$msg = '';
|
||||
if (!$result) {
|
||||
$msg .= "【" . $phone . "】发送失败,接口提示:" . $sms->errors . "\r\n";
|
||||
$return['errorcode'] = 0;
|
||||
} else if (is_array($result) && $result['Code'] != 'OK') {
|
||||
$msg .= "【" . $phone . "】发送失败,接口提示:" . $result['Message'] . "\r\n";
|
||||
$return['errorcode'] = 0;
|
||||
} else {
|
||||
$msg .= "【" . $phone . "】发送成功" . "\r\n";
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
$return['msg'] = $msg;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
//信息摘要
|
||||
public function actionInfo()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$levels = Yii::$app->params['customerLevels'];
|
||||
$model = new AcCarOwner();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
$res['last_send'] = $res['last_send'] ? date('Y-m-d', $res['last_send']) : '';
|
||||
$res['last_contact'] = $res['last_contact'] ? date('Y-m-d', $res['last_contact']) : '';
|
||||
} else {
|
||||
$res = [];
|
||||
}
|
||||
|
||||
//查询对应的系统用户
|
||||
$userModel = new User();
|
||||
$user = User::find()->where(['id' => $res['mid']])->one();
|
||||
$res['mobile'] = '';
|
||||
if ($user) {
|
||||
$res['mobile'] = $user->mobile;
|
||||
}
|
||||
|
||||
$store = AcStore::find()->where(['id' => $res['store_id']])->one();
|
||||
if ($store) {
|
||||
$res['store_title'] = $store->title;
|
||||
}
|
||||
|
||||
$employee = AcEmployee::find()->where(['id' => $res['employee_id']])->one();
|
||||
if ($store) {
|
||||
$res['employee_title'] = $employee->name;
|
||||
}
|
||||
|
||||
$exts = AcUserExt::find()->where(['mid' => $res['mid'], 'mobile' => $res['mobile'], 'pid' => $pid, 'deleted' => 0])->all();
|
||||
if ($exts) {
|
||||
foreach ($exts as $ext) {
|
||||
$res[$ext['key']] = $ext['value'];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('info', [
|
||||
'detail' => $res,
|
||||
'levels' => $levels,
|
||||
'id' => $id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
+339
@@ -0,0 +1,339 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:30:22+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:17:27+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcCarBrand;
|
||||
use addons\models\AcCarSeries;
|
||||
|
||||
class CarseriesController extends Common
|
||||
{
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('../layouts/dev', []);
|
||||
}
|
||||
|
||||
//车型列表
|
||||
public function actionList()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$session = Yii::$app->session;
|
||||
$model = new AcCarSeries();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where2[] = ['in', 'pid', [0, $pid]];
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$searchSession = 'carseries::search';
|
||||
if (isset($_GET['reset']) && $_GET['reset'] == 1) {
|
||||
$post['search'] = [];
|
||||
}
|
||||
if (isset($post['search'])) {
|
||||
$search = $post['search'];
|
||||
$session->set($searchSession, $search);
|
||||
} else if ($session->get($searchSession)) {
|
||||
$search = $session->get($searchSession);
|
||||
}
|
||||
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'title', $search['title']];
|
||||
}
|
||||
$search['brand'] = isset($search['brand_id']) ? trim(htmlspecialchars_decode($search['brand'])) : '';
|
||||
$search['brand_id'] = isset($search['brand_id']) ? (int)$search['brand_id'] : 0;
|
||||
if (!empty($search['brand_id'])) {
|
||||
$where['brand_id'] = $search['brand_id'];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->indexBy('id')->all();
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
|
||||
$series = $bids = [];
|
||||
foreach ($res as $r) {
|
||||
$r = $r->toArray();
|
||||
$series[$r['id']] = $r;
|
||||
$bids[] = $r['brand_id'];
|
||||
}
|
||||
|
||||
$AcCarBrand = new AcCarBrand();
|
||||
$brands = [];
|
||||
$_brands = $AcCarBrand->find()->where(['in', 'id', $bids])->indexBy('id')->all();
|
||||
foreach ($_brands as $s) {
|
||||
$brands[$s->id] = $s->toArray();
|
||||
}
|
||||
|
||||
return $this->render('list', [
|
||||
'series' => $series,
|
||||
'pager' => $pages,
|
||||
'brands' => $brands,
|
||||
'status' => $status,
|
||||
'search' => $search
|
||||
]);
|
||||
}
|
||||
|
||||
//车型列表
|
||||
public function actionSelect()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$session = Yii::$app->session;
|
||||
$model = new AcCarSeries();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where2[] = ['in', 'pid', [0, $pid]];
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$searchSession = 'carseries::search';
|
||||
if (isset($_GET['reset']) && $_GET['reset'] == 1) {
|
||||
$post['search'] = [];
|
||||
}
|
||||
if (isset($post['search'])) {
|
||||
$search = $post['search'];
|
||||
$session->set($searchSession, $search);
|
||||
} else if ($session->get($searchSession)) {
|
||||
$search = $session->get($searchSession);
|
||||
}
|
||||
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'title', $search['title']];
|
||||
}
|
||||
// $search['brand'] = isset($search['brand']) ? trim(htmlspecialchars_decode($search['brand'])) : '';
|
||||
$search['brand'] = isset($search['brand_id']) ? trim(htmlspecialchars_decode($search['brand'])) : '';
|
||||
$search['brand_id'] = isset($search['brand_id']) ? (int)$search['brand_id'] : 0;
|
||||
if (!empty($search['brand_id'])) {
|
||||
$where['brand_id'] = $search['brand_id'];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->indexBy('id')->all();
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
|
||||
$series = $bids = [];
|
||||
foreach ($res as $r) {
|
||||
$r = $r->toArray();
|
||||
$series[$r['id']] = $r;
|
||||
$bids[$r['brand_id']] = $r['brand_id'];
|
||||
}
|
||||
|
||||
$AcCarBrand = new AcCarBrand();
|
||||
$brands = [];
|
||||
$_brands = $AcCarBrand->find()->where(['in', 'id', $bids])->indexBy('id')->all();
|
||||
foreach ($_brands as $s) {
|
||||
$brands[$s->id] = $s->toArray();
|
||||
}
|
||||
|
||||
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'car';
|
||||
return $this->render('select', [
|
||||
'series' => $series,
|
||||
'pager' => $pages,
|
||||
'brands' => $brands,
|
||||
'status' => $status,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
}
|
||||
|
||||
//新增车型
|
||||
public function actionNew()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$AcCarSeries = new AcCarSeries();
|
||||
$AcCarSeries->status_code = 0;
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $AcCarSeries->toArray()]);
|
||||
}
|
||||
|
||||
//更新车型
|
||||
public function actionEdit()
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$model = new AcCarSeries();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
$parmas = [];
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
$parmas = json_decode($res['params'], TRUE);
|
||||
} else {
|
||||
$res = [];
|
||||
}
|
||||
|
||||
//查询对应的品牌
|
||||
$brand = AcCarBrand::find()->where(['id' => $res['brand_id']])->one();
|
||||
if ($brand) {
|
||||
$res['brand_title'] = $brand->title;
|
||||
}
|
||||
|
||||
return $this->render('modify', [
|
||||
'detail' => $res,
|
||||
'params' => $parmas,
|
||||
'status' => $status,
|
||||
'id' => $id,
|
||||
]);
|
||||
}
|
||||
|
||||
//保存车型资料
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
//格式化数据
|
||||
$data = [];
|
||||
$data['title'] = trim($post['title']);
|
||||
//目标键=》POST键
|
||||
$cols = ['brand_id' => 'brand_id', 'status_code' => 'status_code', 'deleted' => 'deleted'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
$params = $post['p'];
|
||||
$cols = ['height', 'length', 'width', 'kg', 'seat'];
|
||||
foreach ($cols as $col) {
|
||||
$params[$col] = isset($params[$col]) ? (int)$params[$col] : 0;
|
||||
}
|
||||
$data['params'] = json_encode($params, JSON_UNESCAPED_UNICODE);
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//格式化车型资料
|
||||
$AcCarSeries = new AcCarSeries();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcCarSeries->$key = $val;
|
||||
}
|
||||
|
||||
//车型资料入库
|
||||
if ($id) {
|
||||
$AcCarSeries->id = $id;
|
||||
unset($data['create_at']);
|
||||
$res = $AcCarSeries->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcCarSeries->save();
|
||||
$id = $AcCarSeries->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '车型资料保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '车型资料保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
}
|
||||
|
||||
//删除车型
|
||||
public function actionDelete($id)
|
||||
{
|
||||
global $_HI, $_FM;
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
|
||||
$model = new AcCarSeries();
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
$return['url'] = Url::toRoute('carowner/list');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
|
||||
$model = new AcCarSeries();
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
$return = [];
|
||||
$return['timeout'] = 1; //3秒后自动跳转
|
||||
$return['status_code'] = 0;
|
||||
$return['ajax'] = 1;
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
} else {
|
||||
$return['msg'] = '车型数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'hide':
|
||||
$data['status_code'] = 0;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '车型隐藏标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'info'];
|
||||
} else {
|
||||
$return['msg'] = '车型隐藏标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$data['status_code'] = 1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '车型显示标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'default'];
|
||||
} else {
|
||||
$return['msg'] = '车型显示标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:30:47+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:17:33+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
|
||||
// use backend\models\Citys;
|
||||
|
||||
class CityController extends Common
|
||||
{
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('../layouts/dev', []);
|
||||
}
|
||||
|
||||
public function actionSelect()
|
||||
{
|
||||
$citys = Yii::$app->params['citys'];
|
||||
$pager = new Pagination(['totalCount' => count($citys), 'pageSize' => '100']);
|
||||
$callback = isset($_GET['callback']) ? $_GET['callback'] : 'city';
|
||||
$search = [];
|
||||
return $this->render('select', [
|
||||
'citys' => $citys,
|
||||
'pager' => $pager,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
}
|
||||
}
|
||||
Executable
+121
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-04-15 20:22:03
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-07-08T16:02:30+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
//平台用户入口
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\web\Controller;
|
||||
use common\models\Member as User;
|
||||
use addons\models\AcUserExt;
|
||||
use addons\models\AcStore;
|
||||
use addons\models\AcEmployee;
|
||||
|
||||
class Common extends Controller
|
||||
{
|
||||
protected int $pid = 0;
|
||||
protected int $user_id = 0;
|
||||
protected int $site_id = 0;
|
||||
protected int $store_id = 0;
|
||||
protected int $employee_id = 0;
|
||||
protected object $user_info;
|
||||
protected array $postdata = []; //重新整理一下客户端传输的数据
|
||||
protected bool $imgHttp = TRUE; //图片附件地址生成http(s) //false:不生成http网址; true:仅生成http网址; https:生成https网址
|
||||
protected int $page = 1; //当前数据分页
|
||||
protected int $pageSize = 10; //默认数据分页大小
|
||||
public $enableCsrfValidation = FALSE;
|
||||
//替代常规的_construct 析构函数;其他方法调用前执行
|
||||
protected int $timestamp = TIMESTAMP;
|
||||
|
||||
//替代常规的_construct 析构函数;其他方法调用前执行
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
//判断请求内容类型 content-type,支持 json请求
|
||||
$postdata = Yii::$app->request->post();
|
||||
$headers = Yii::$app->request->headers;
|
||||
$contentType = $headers->get('content-type');
|
||||
if ($contentType == "application/json") {
|
||||
$postdata = json_decode(file_get_contents('php://input'), TRUE);
|
||||
}
|
||||
$this->postdata = $postdata;
|
||||
|
||||
$session = Yii::$app->session;
|
||||
if (isset($postdata['pid'])) {
|
||||
if ((int)$postdata['pid'] > 0) {
|
||||
$this->pid = (int)$postdata['pid'];
|
||||
$session->set('pid', $this->pid);
|
||||
} else {
|
||||
$session->set('pid', 0);
|
||||
}
|
||||
} else if (isset($_GET['pid'])) {
|
||||
if ((int)$_GET['pid'] > 0) {
|
||||
$this->pid = $_GET['pid'];
|
||||
$session->set('pid', $this->pid);
|
||||
} else {
|
||||
$session->set('pid', 0);
|
||||
}
|
||||
} else {
|
||||
$session->set('pid', 0);
|
||||
}
|
||||
|
||||
$this->site_id = Yii::$app->params['siteId'];
|
||||
|
||||
if (isset($postdata['uid']) && (int)$postdata['uid'] > 0) {
|
||||
$this->user_id = (int)$postdata['uid'];
|
||||
}
|
||||
if ($this->user_id) {
|
||||
$userModel = new User();
|
||||
$res = $userModel->findOne($this->user_id);
|
||||
if (!$res) {
|
||||
$this->user_id = 0;
|
||||
} else {
|
||||
$this->user_info = $res;
|
||||
}
|
||||
//TBD 后期需加上更多登陆验证逻辑
|
||||
}
|
||||
if (isset($postdata['employee_id']) && (int)$postdata['employee_id'] > 0) {
|
||||
$this->employee_id = (int)$postdata['employee_id'];
|
||||
}
|
||||
|
||||
$page = isset($postdata['page']) ? (int)$postdata['page'] : 1;
|
||||
$this->page = $page <= 0 ? 1 : $page;
|
||||
$pageSize = isset($postdata['psize']) ? (int)$postdata['psize'] : 10;
|
||||
$this->pageSize = $pageSize <= 0 ? 10 : $pageSize;
|
||||
}
|
||||
|
||||
public function result($msg, $data = NULL, $code = 0)
|
||||
{
|
||||
$return = [];
|
||||
$return['code'] = $code;
|
||||
$return['msg'] = $msg;
|
||||
if ($data) {
|
||||
$return['data'] = $data;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function userToken($user = [], $refresh = FALSE, $expire = NULL)
|
||||
{
|
||||
//生成token(用户数据,是否强制更新,过期时间 // TBD 具体方法有待优化
|
||||
$expire = $expire ? $expire : '+1 day';
|
||||
$token = Yii::$app->session->get('memberToken');
|
||||
$tokenExpired = Yii::$app->session->get('memberTokenExpired');
|
||||
if (!$token || $refresh) {
|
||||
$tokenExpired = strtotime($expire) * 1000;
|
||||
$token = md5('username=' . $user['username'] . '&mobile=' . $user['mobile'] . '&time=' . $tokenExpired);
|
||||
Yii::$app->session->set('memberToken', $token);
|
||||
Yii::$app->session->set('memberTokenExpired', $tokenExpired);
|
||||
}
|
||||
$user['token'] = $token;
|
||||
$user['tokenExpired'] = $tokenExpired;
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
+278
@@ -0,0 +1,278 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:35:33+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:17:44+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcContact;
|
||||
use common\models\Member as User;
|
||||
use common\models\UserExt;
|
||||
|
||||
class ContactController extends Common
|
||||
{
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('index');
|
||||
}
|
||||
|
||||
//通讯录列表
|
||||
public function actionList()
|
||||
{
|
||||
$model = new AcContact();
|
||||
$where = $where2 = [];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$session = Yii::$app->session;
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$searchSession = 'contact::search';
|
||||
if (isset($_GET['reset']) && $_GET['reset'] == 1) {
|
||||
$post['search'] = [];
|
||||
}
|
||||
if (isset($post['search'])) {
|
||||
$search = $post['search'];
|
||||
$session->set($searchSession, $search);
|
||||
} else if ($session->get($searchSession)) {
|
||||
$search = $session->get($searchSession);
|
||||
}
|
||||
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = 'or';
|
||||
$where2[] = ['LIKE', 'name', $search['title']];
|
||||
$where2[] = ['LIKE', 'mobile', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
|
||||
return $this->render('list', [
|
||||
'contactors' => $res,
|
||||
'pager' => $pages,
|
||||
'status' => $status,
|
||||
'search' => $search
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionSelect()
|
||||
{
|
||||
$model = new AcContact();
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$session = Yii::$app->session;
|
||||
$where = $where2 = [];
|
||||
$where['pid'] = $pid;
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$searchSession = 'contact::search';
|
||||
if (isset($_GET['reset']) && $_GET['reset'] == 1) {
|
||||
$post['search'] = [];
|
||||
}
|
||||
if (isset($post['search'])) {
|
||||
$search = $post['search'];
|
||||
$session->set($searchSession, $search);
|
||||
} else if ($session->get($searchSession)) {
|
||||
$search = $session->get($searchSession);
|
||||
}
|
||||
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = 'or';
|
||||
$where2[] = ['LIKE', 'name', $search['title']];
|
||||
$where2[] = ['LIKE', 'mobile', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'contactor';
|
||||
return $this->render('select', [
|
||||
'contactors' => $res,
|
||||
'pager' => $pages,
|
||||
'status' => $status,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionNew()
|
||||
{
|
||||
return $this->render('modify', []);
|
||||
}
|
||||
|
||||
//编辑通讯录资料
|
||||
public function actionEdit()
|
||||
{
|
||||
$model = new AcContact();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
}
|
||||
|
||||
return $this->render('modify', ['detail' => $res]);
|
||||
}
|
||||
|
||||
//保存通讯录资料
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['company' => 'company', 'name' => 'name', 'mobile' => 'mobile', 'idcard' => 'idcard'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
//查询通讯录手机号是否在库
|
||||
$hasContactor = AcContact::find()->where(['mobile' => $data['mobile']])->one();
|
||||
if ($hasContactor) {
|
||||
if ($id && $id == $hasContactor->id) {
|
||||
} else {
|
||||
$id = $hasContactor->id;
|
||||
\Yii::$app->getSession()->setFlash('danger', '保存失败,该手机号对应的通讯录已在库,系统自动现在为您调出该通讯录资料!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
}
|
||||
}
|
||||
$cols = ['status_code' => 'status_code', 'deleted' => 'deleted'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//保存通讯录资料
|
||||
$AcContact = new AcContact();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcContact->$key = $val;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$AcContact->id = $id;
|
||||
unset($data['create_at']);
|
||||
$res = $AcContact->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcContact->save();
|
||||
$id = $AcContact->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '通讯录信息保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '通讯录信息保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
}
|
||||
|
||||
//删除
|
||||
public function actionDelete()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
|
||||
$model = new AcContact();
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
$return['url'] = Url::toRoute('contact/list');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '通讯录删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '通讯录删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
|
||||
$model = new AcContact();
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
$return = [];
|
||||
$return['timeout'] = 1; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
$return['ajax'] = 1;
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
} else {
|
||||
$return['msg'] = '通讯录数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'out':
|
||||
$data['status'] = 0;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '通讯录隐藏标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'info'];
|
||||
} else {
|
||||
$return['msg'] = '通讯录隐藏标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'in':
|
||||
$data['status'] = 1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '通讯录显示标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'default'];
|
||||
} else {
|
||||
$return['msg'] = '通讯录显示标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
+268
@@ -0,0 +1,268 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:35:09+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:17:49+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcDriver;
|
||||
use common\models\Member as User;
|
||||
use common\models\UserExt;
|
||||
|
||||
class DriverController extends Common
|
||||
{
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('index');
|
||||
}
|
||||
|
||||
//司机列表
|
||||
public function actionList()
|
||||
{
|
||||
$model = new AcDriver();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'name', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['DriverStatus'];
|
||||
|
||||
return $this->render('list', [
|
||||
'drivers' => $res,
|
||||
'pager' => $pages,
|
||||
'status' => $status,
|
||||
'search' => $search
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionSelect()
|
||||
{
|
||||
$model = new AcDriver();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'name', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['DriverStatus'];
|
||||
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'driver';
|
||||
return $this->render('select', [
|
||||
'drivers' => $res,
|
||||
'pager' => $pages,
|
||||
'status' => $status,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionNew()
|
||||
{
|
||||
return $this->render('modify', []);
|
||||
}
|
||||
|
||||
//编辑司机资料
|
||||
public function actionEdit()
|
||||
{
|
||||
$model = new AcDriver();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
}
|
||||
|
||||
return $this->render('modify', ['detail' => $res]);
|
||||
}
|
||||
|
||||
//保存司机资料
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['name' => 'name', 'mobile' => 'mobile', 'idcard' => 'idcard'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
//查询司机手机号是否在库
|
||||
$hasDriver = AcDriver::find()->where(['mobile' => $data['mobile']])->one();
|
||||
if ($hasDriver) {
|
||||
if ($id && $id == $hasDriver->id) {
|
||||
} else {
|
||||
$id = $hasDriver->id;
|
||||
\Yii::$app->getSession()->setFlash('danger', '保存失败,该手机号对应的司机已在库,系统自动现在为您调出该司机资料!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
}
|
||||
}
|
||||
$cols = ['status_code' => 'status_code', 'deleted' => 'deleted'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//保存司机资料
|
||||
$AcDriver = new AcDriver();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcDriver->$key = $val;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$AcDriver->id = $id;
|
||||
unset($data['create_at']);
|
||||
$res = $AcDriver->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcDriver->save();
|
||||
$id = $AcDriver->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
//查询司机对应的系统用户
|
||||
$userModel = new User();
|
||||
$user = $userModel->find()->where(['mobile' => $data['mobile']])->one();
|
||||
if (empty($user)) {
|
||||
$userModel->username = !$data['name'] ? $data['mobile'] : $data['name'];
|
||||
$userModel->mobile = $data['mobile'];
|
||||
$userModel->email = $data['mobile'] . '@hiluker.com';
|
||||
$userModel->setPassword(Yii::$app->params['defaultUserPassword']);
|
||||
$userModel->generateAuthKey();
|
||||
$userModel->avatar = Yii::$app->params['defaultUserAvatar'];
|
||||
$userModel->created_at = time();
|
||||
$userModel->status = 1;
|
||||
$userModel->save();
|
||||
$user_id = $userModel->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
\Yii::$app->getSession()->setFlash('info', '已成功注册该用户!');
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '司机信息保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '司机信息保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
}
|
||||
|
||||
//删除员工
|
||||
public function actionDelete()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
|
||||
$model = new AcDriver();
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
$return['url'] = Url::toRoute('driver/list');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '司机删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '司机删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
|
||||
$model = new AcDriver();
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
$return = [];
|
||||
$return['timeout'] = 1; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
$return['ajax'] = 1;
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
} else {
|
||||
$return['msg'] = '司机数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'out':
|
||||
$data['status'] = 0;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '司机离职标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'info'];
|
||||
} else {
|
||||
$return['msg'] = '司机离职标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'in':
|
||||
$data['status'] = 1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '司机在职标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'default'];
|
||||
} else {
|
||||
$return['msg'] = '司机在职标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
+295
@@ -0,0 +1,295 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:34:47+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:17:55+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcEmployee;
|
||||
use addons\models\AcStore;
|
||||
use common\models\Member as User;
|
||||
use addons\models\AcUserExt;
|
||||
|
||||
class EmployeeController extends Common
|
||||
{
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('index');
|
||||
}
|
||||
|
||||
//用户列表
|
||||
public function actionList()
|
||||
{
|
||||
$model = new AcEmployee();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'name', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['EmployeeStatus'];
|
||||
$gender = Yii::$app->params['gender'];
|
||||
$model = new AcStore();
|
||||
$where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$_stores = $model->find()->where($where)->all();
|
||||
$stores = [];
|
||||
foreach ($_stores as $s) {
|
||||
$stores[$s->id] = $s->toArray();
|
||||
}
|
||||
return $this->render('list', [
|
||||
'employees' => $res,
|
||||
'pager' => $pages,
|
||||
'stores' => $stores,
|
||||
'status' => $status,
|
||||
'gender' => $gender,
|
||||
'search' => $search
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionSelect()
|
||||
{
|
||||
$model = new AcEmployee();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'name', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['EmployeeStatus'];
|
||||
$gender = Yii::$app->params['gender'];
|
||||
$model = new AcStore();
|
||||
$where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$_stores = $model->find()->where($where)->all();
|
||||
$stores = [];
|
||||
foreach ($_stores as $s) {
|
||||
$stores[$s->id] = $s->toArray();
|
||||
}
|
||||
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'employee';
|
||||
return $this->render('select', [
|
||||
'employees' => $res,
|
||||
'pager' => $pages,
|
||||
'stores' => $stores,
|
||||
'status' => $status,
|
||||
'gender' => $gender,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionNew()
|
||||
{
|
||||
return $this->render('modify', []);
|
||||
}
|
||||
|
||||
//编辑员工资料
|
||||
public function actionEdit()
|
||||
{
|
||||
$model = new AcEmployee();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
}
|
||||
|
||||
$store = AcStore::find()->where(['id' => $res['store_id']])->one();
|
||||
if ($store) {
|
||||
$res['store_title'] = $store->title;
|
||||
}
|
||||
return $this->render('modify', ['detail' => $res]);
|
||||
}
|
||||
|
||||
//保存员工资料
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['name' => 'name', 'mobile' => 'mobile'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
$cols = ['gender' => 'gender', 'status' => 'status', 'store_id' => 'store', 'deleted' => 'deleted'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
$cols = ['remark' => 'editor'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? htmlspecialchars($post[$key]) : '';
|
||||
}
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
$data['status_code'] = 1;
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//保存员工资料
|
||||
$AcEmployee = new AcEmployee();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcEmployee->$key = $val;
|
||||
}
|
||||
|
||||
//查询员工手机号是否在库
|
||||
$employee = AcEmployee::find()->where(['mobile' => $data['mobile']])->one();
|
||||
if ($employee) {
|
||||
$id = $employee->id;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$AcEmployee->id = $id;
|
||||
unset($data['create_at']);
|
||||
$res = $AcEmployee->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcEmployee->save();
|
||||
$id = $AcEmployee->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
//查询员工对应的系统用户
|
||||
$userModel = new User();
|
||||
$user = User::find()->where(['mobile' => $data['mobile']])->one();
|
||||
if (empty($user)) {
|
||||
$userModel->username = $data['mobile'];
|
||||
$userModel->mobile = $data['mobile'];
|
||||
$userModel->email = $data['mobile'] . '@hiluker.com';
|
||||
$userModel->setPassword(Yii::$app->params['defaultUserPassword']);
|
||||
$userModel->generateAuthKey();
|
||||
$userModel->avatar = Yii::$app->params['defaultUserAvatar'];
|
||||
$userModel->created_at = time();
|
||||
$userModel->status = 1;
|
||||
$userModel->save();
|
||||
$user_id = $userModel->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
\Yii::$app->getSession()->setFlash('info', '已成功注册该用户!');
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '员工信息保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '员工信息保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
}
|
||||
|
||||
//删除员工
|
||||
public function actionDelete()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
|
||||
$model = new AcEmployee();
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
$return['url'] = Url::toRoute('employee/list');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '员工删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '员工删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
|
||||
$model = new AcEmployee();
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
$return = [];
|
||||
$return['timeout'] = 1; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
$return['ajax'] = 1;
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
} else {
|
||||
$return['msg'] = '员工数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'out':
|
||||
$data['status'] = 0;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '员工离职标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'info'];
|
||||
} else {
|
||||
$return['msg'] = '员工离职标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'in':
|
||||
$data['status'] = 1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '员工在职标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'default'];
|
||||
} else {
|
||||
$return['msg'] = '员工在职标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:33:38+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:18:05+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcFeeOrder;
|
||||
use addons\models\AcFeeDriver;
|
||||
use addons\models\AcOrder;
|
||||
use addons\models\AcOrderPre;
|
||||
use addons\models\AcOrderStatus;
|
||||
use addons\models\AcStore;
|
||||
use addons\models\AcEmployee;
|
||||
use addons\models\AcPlat;
|
||||
use common\models\CVcode;
|
||||
|
||||
class FeeController extends Common
|
||||
{
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('@app/views/layouts/dev', []);
|
||||
}
|
||||
}
|
||||
+1181
File diff suppressed because it is too large
Load Diff
+1392
File diff suppressed because it is too large
Load Diff
Executable
+378
@@ -0,0 +1,378 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:32:02+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:18:34+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcTruck;
|
||||
use addons\models\AcDriver;
|
||||
use addons\models\AcTruckOnline;
|
||||
use addons\models\AcTruckCars;
|
||||
use addons\models\AcStore;
|
||||
use addons\models\AcCar;
|
||||
use addons\models\AcCarBrand;
|
||||
use addons\models\AcCarSeries;
|
||||
use addons\models\AcOrder;
|
||||
use addons\models\AcGps;
|
||||
use addons\models\AcGpsRoute;
|
||||
use addons\models\AcTruckRoute;
|
||||
|
||||
class GpsController extends Common
|
||||
{
|
||||
//替代常规的_construct 析构函数;其他方法调用前执行
|
||||
public function init()
|
||||
{
|
||||
$session = Yii::$app->session;
|
||||
if (isset($_GET['pid']) && (int)$_GET['pid'] > 0) {
|
||||
$session->set('pid', (int)$_GET['pid']);
|
||||
}
|
||||
$pid = $session->get('pid');
|
||||
if (!$pid) {
|
||||
return Yii::$app->response->redirect(['index/index']);
|
||||
}
|
||||
$online_id = Yii::$app->request->get('online_id'); //发车任务ID
|
||||
if (!$online_id) {
|
||||
$online_id = $session->get('online_id');
|
||||
} else {
|
||||
$session->set('online_id', $online_id);
|
||||
}
|
||||
if (!$online_id) {
|
||||
$post = Yii::$app->request->post();
|
||||
$return = [];
|
||||
$return['msg'] = '请先选择好要查看的出车大板';
|
||||
$return['errorcode'] = 0;
|
||||
// $return['url'] = Url::toRoute(['truckol/index',$post]);
|
||||
// $return['buttons'] = [
|
||||
// ['title'=>'好的,我知道了','class'=>'info','url'=>$return['url']]
|
||||
// ];
|
||||
$return['content'] = $return['msg'];
|
||||
$return['class'] = 'warning';
|
||||
Yii::$app->request->setBodyParams($return);
|
||||
return Yii::$app->runAction('index/msg');
|
||||
}
|
||||
$truckol = $session->get('truckOnline');
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$res = TRUE;
|
||||
if (!$truckol) {
|
||||
$res = $AcTruckOnline->findOne($online_id);
|
||||
if ($res) {
|
||||
$truck_id = $res->truck_id;
|
||||
$store_id = $res->from_store;
|
||||
$store2_id = $res->end_store;
|
||||
$truckol = $res->toArray();
|
||||
|
||||
$AcStore = new AcStore();
|
||||
$store = $AcStore->findOne($store_id);
|
||||
if ($store) {
|
||||
$truckol['fromstore_title'] = $store->title;
|
||||
}
|
||||
$store2 = $AcStore->findOne($store2_id);
|
||||
if ($store2) {
|
||||
$truckol['endstore_title'] = $store2->title;
|
||||
}
|
||||
$session->set('truckOnline', $truckol);
|
||||
}
|
||||
}
|
||||
if ($online_id != $truckol['id']) {
|
||||
$res = $AcTruckOnline->findOne($online_id);
|
||||
if ($res) {
|
||||
$truck_id = $res->truck_id;
|
||||
$store_id = $res->from_store;
|
||||
$store2_id = $res->end_store;
|
||||
$truckol = $res->toArray();
|
||||
|
||||
$AcStore = new AcStore();
|
||||
$store = $AcStore->findOne($store_id);
|
||||
if ($store) {
|
||||
$truckol['fromstore_title'] = $store->title;
|
||||
}
|
||||
$store2 = $AcStore->findOne($store2_id);
|
||||
if ($store2) {
|
||||
$truckol['endstore_title'] = $store2->title;
|
||||
}
|
||||
$session->set('truckOnline', $truckol);
|
||||
}
|
||||
}
|
||||
if (!$res) {
|
||||
$post = Yii::$app->request->post();
|
||||
$return = [];
|
||||
$return['msg'] = '请先选择好要查看的出车大板';
|
||||
$return['errorcode'] = 0;
|
||||
$return['url'] = Url::toRoute(['truckol/index', $post]);
|
||||
$return['buttons'] = [
|
||||
['title' => '好的,我知道了', 'class' => 'info', 'url' => $return['url']]
|
||||
];
|
||||
$return['content'] = $return['msg'];
|
||||
$return['class'] = 'warning';
|
||||
Yii::$app->request->setBodyParams($return);
|
||||
return Yii::$app->runAction('index/msg');
|
||||
}
|
||||
}
|
||||
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('index', []);
|
||||
}
|
||||
|
||||
//所有板车位置记录列表
|
||||
public function actionList()
|
||||
{
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$post = Yii::$app->request->post();
|
||||
$online_id = Yii::$app->session->get('online_id'); //发车任务ID
|
||||
$truckol = Yii::$app->session->get('truckOnline'); //发车任务
|
||||
|
||||
$AcTruckRoute = new AcTruckRoute();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', Yii::$app->session->get('pid')];
|
||||
if ($online_id) {
|
||||
$where[] = ['=', 'online_id', $online_id];
|
||||
}
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$data = $AcTruckRoute->find()->where($where)->orderby('orderby ASC,id DESC');
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
|
||||
$truck_ids = [];
|
||||
foreach ($res as $r) {
|
||||
$truck_ids[] = $r->truck_id;
|
||||
}
|
||||
|
||||
$AcTruck = new AcTruck();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$where[] = ['IN', 'id', $truck_ids];
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$trucks = $AcTruck->find()->where($where)->indexby('id')->all();
|
||||
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
|
||||
return $this->render('list', [
|
||||
'list' => $res,
|
||||
'pager' => $pages,
|
||||
'status' => $status,
|
||||
'trucks' => $trucks,
|
||||
'online_id' => $online_id,
|
||||
'truckol' => $truckol
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionNew()
|
||||
{
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$AcTruckRoute = [];
|
||||
$AcTruckRoute['status_code'] = 0;
|
||||
$online_id = Yii::$app->session->get('online_id'); //发车任务ID
|
||||
$truckol = Yii::$app->session->get('truckOnline'); //发车任务
|
||||
|
||||
$AcTruckRoute['truck_id'] = $truckol['truck_id'];
|
||||
$AcTruckRoute['truck_num'] = $truckol['truck_num'];
|
||||
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $AcTruckRoute, 'online_id' => $online_id, 'truckol' => $truckol]);
|
||||
}
|
||||
|
||||
//编辑板车位置信息
|
||||
public function actionEdit()
|
||||
{
|
||||
$id = Yii::$app->request->get('id'); //记录ID
|
||||
$online_id = Yii::$app->session->get('online_id'); //发车任务ID
|
||||
$truckol = Yii::$app->session->get('truckOnline'); //发车任务
|
||||
|
||||
$AcTruckRoute = new AcTruckRoute();
|
||||
$route = $AcTruckRoute->findOne($id);
|
||||
if (!$route) {
|
||||
$post = Yii::$app->request->post();
|
||||
$return = [];
|
||||
$return['msg'] = '位置记录数据获取异常,请重新选择获取';
|
||||
$return['errorcode'] = 0;
|
||||
$return['url'] = '';
|
||||
$return['buttons'] = [
|
||||
['title' => '好的,我知道了', 'class' => 'info', 'url' => $return['url']]
|
||||
];
|
||||
$return['content'] = $return['msg'];
|
||||
$return['class'] = 'warning';
|
||||
Yii::$app->request->setBodyParams($return);
|
||||
return Yii::$app->runAction('index/msg');
|
||||
}
|
||||
$route = $route->toArray();
|
||||
$route['truck_id'] = $truckol['truck_id'];
|
||||
$route['online_id'] = $online_id;
|
||||
$route['truck_num'] = $truckol['truck_num'];
|
||||
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $route, 'online_id' => $online_id, 'truckol' => $truckol]);
|
||||
}
|
||||
|
||||
//保存位置记录信息
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$online_id = Yii::$app->session->get('online_id');
|
||||
$truckol = Yii::$app->session->get('truckOnline'); //发车任务
|
||||
$data = [];
|
||||
$data['truck_id'] = $truckol['truck_id'];
|
||||
$data['online_id'] = $online_id;
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['longt' => 'lng', 'lat' => 'lat', 'addr' => 'addr'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
|
||||
$cols = ['orderby' => 'orderby', 'status_code' => 'status_code'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
|
||||
$_time = time();
|
||||
$key = 'update_at';
|
||||
$data[$key] = isset($post[$key]) ? strtotime($post[$key]) : $_time;
|
||||
|
||||
if (!$id) {
|
||||
$data['create_at'] = $_time;
|
||||
}
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//保存位置资料
|
||||
$AcTruckRoute = new AcTruckRoute();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcTruckRoute->$key = $val;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$res = $AcTruckRoute->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcTruckRoute->save();
|
||||
$id = $AcTruckRoute->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '信息保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '信息保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
}
|
||||
|
||||
//删除记录
|
||||
public function actionDelete()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$return = [];
|
||||
|
||||
$model = new AcTruckRoute();
|
||||
$route = $model->findOne($id);
|
||||
if (!$route) {
|
||||
$return['msg'] = '数据不存在,删除失败';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($route->pid != $pid) {
|
||||
$return['msg'] = '非本平台数据,不允许操作';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($route->deleted != 0) {
|
||||
$return['msg'] = '数据已被删除过,操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
$route->deleted = 1;
|
||||
$res = $route->save();
|
||||
|
||||
$return['url'] = '';
|
||||
$return['timeout'] = 1; //n秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '位置记录删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '位置记录删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$return = [];
|
||||
|
||||
$model = new AcTruckRoute();
|
||||
$route = $model->findOne($id);
|
||||
if (!$route) {
|
||||
$return['msg'] = '数据不存在,删除失败';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($route->pid != $pid) {
|
||||
$return['msg'] = '非本平台数据,不允许操作';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
if ($route->deleted != 0) {
|
||||
$return['msg'] = '数据已被删除,操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
$return['timeout'] = 1; //n秒后自动跳转
|
||||
$res = TRUE;
|
||||
switch ($get['do']) {
|
||||
case 'show':
|
||||
if ($route->status_code != 1) {
|
||||
$route->status_code = 1;
|
||||
$res = $route->save();
|
||||
}
|
||||
if ($res) {
|
||||
$return['msg'] = '记录显示标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'success'];
|
||||
} else {
|
||||
$return['msg'] = '客车上板标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'hide':
|
||||
if ($route->status_code != 0) {
|
||||
$route->status_code = 0;
|
||||
$res = $route->save();
|
||||
}
|
||||
if ($res) {
|
||||
$return['msg'] = '记录隐藏标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'success'];
|
||||
} else {
|
||||
$return['msg'] = '客车上板标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-10T01:13:34+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:18:41+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\web\UploadedFile;
|
||||
use common\models\CAttachment;
|
||||
use backend\controllers\Common;
|
||||
|
||||
class ImageController extends Common
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
$apis = [
|
||||
'list' => '图片列表',
|
||||
];
|
||||
$this->result('您正使用CMTS系统订单管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
public function actionList()
|
||||
{
|
||||
$siteId = Yii::$app->params['siteId'];
|
||||
$session = Yii::$app->session;
|
||||
$pid = $this->pid;
|
||||
$model = new CAttachment();
|
||||
$search = $where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'status_code', 1];
|
||||
$where[] = ['=', 'type', 0];
|
||||
$where[] = ['=', 'siteid', $siteId];
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$post = $this->postdata;
|
||||
|
||||
if (isset($post['search'])) {
|
||||
$search = $post['search'];
|
||||
$session->set('images::search', $search);
|
||||
} else if ($session->get('images::search')) {
|
||||
$search = $session->get('images::search');
|
||||
}
|
||||
if ($search) {
|
||||
if ($search['create_m']) {
|
||||
$start = strtotime($search['create_m']);
|
||||
$s = date("Y-m-d H:i:s", $start);
|
||||
$ldm = strtotime("last day of " . $s);
|
||||
$m = date("Y-m-d", $ldm) . " 23:59:59";
|
||||
$end = strtotime($m);
|
||||
$where[] = ['between', 'create_at', $start, $end];
|
||||
} else if (!empty($search['create_after']) && !empty($search['create_before'])) {
|
||||
$start = strtotime($search['create_after']);
|
||||
$end = strtotime($search['create_before']);
|
||||
$where[] = ['between', 'create_at', $start, $end];
|
||||
} else if (!empty($search['create_after'])) {
|
||||
$start = strtotime($search['create_after']);
|
||||
$where[] = ['>=', 'create_at', $start];
|
||||
} else if (!empty($search['create_before'])) {
|
||||
$end = strtotime($search['create_before']);
|
||||
$where[] = ['<=', 'create_at', $end];
|
||||
}
|
||||
if ($search['title']) {
|
||||
$where[] = ['LIKE', 'title', $search['title']];
|
||||
}
|
||||
}
|
||||
//分页
|
||||
$orderby = ['id' => SORT_DESC];
|
||||
$Attachment = new Attachment();
|
||||
$list = $Attachment->getData($model, $where, $orderby);
|
||||
$pager = $Attachment->getPagination();
|
||||
|
||||
//附件网址前缀
|
||||
$src = Url::base(TRUE) . "/../../upload"; //在网站根目录下使用upload/pics目录;适合使用yii框架主目录入口而非绑定子域名的情形
|
||||
if ($_SERVER['DOCUMENT_ROOT'] . '/upload' != Yii::getAlias("@upload")) {
|
||||
// $src = Url::toRoute(['attach/index','img'=>'']); //换用网络加载转换的方式-反应慢
|
||||
$src = Yii::$app->params['attachSrc'] . Yii::$app->params['attachDir'];
|
||||
}
|
||||
|
||||
$callback = isset($_GET['callback']) ? $_GET['callback'] : 'thumb';
|
||||
$data = [
|
||||
'list' => $list,
|
||||
'pager' => $pager,
|
||||
'src' => $src,
|
||||
'callback' => $callback
|
||||
];
|
||||
$this->result('', $data, 200);
|
||||
}
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-13T09:20:03+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:18:46+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
|
||||
//主入口页
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use addons\models\AcCar;
|
||||
use addons\models\AcCarOwner;
|
||||
use addons\models\AcCarBrand;
|
||||
use addons\models\AcCarSeries;
|
||||
use addons\models\AcStore;
|
||||
use addons\models\AcEmployee;
|
||||
use addons\models\AcOrder;
|
||||
use addons\models\AcOrderPre;
|
||||
use addons\models\AcOrderStatus;
|
||||
use addons\models\AcTruck;
|
||||
use addons\models\AcDriver;
|
||||
use addons\models\AcPlat;
|
||||
use common\models\CVcode;
|
||||
use addons\models\AcContact;
|
||||
use common\models\Member as User;
|
||||
use addons\models\AcUserExt;
|
||||
|
||||
class IndexController extends Common
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
$apis = [
|
||||
'h5data' => '拉取APP首页数据',
|
||||
];
|
||||
$this->result('您正使用CMTS系统接口!', $apis, 200);
|
||||
}
|
||||
|
||||
public function actionH5data()
|
||||
{
|
||||
$pid = $this->pid;
|
||||
|
||||
$model = new AcOrder();
|
||||
$search = $where = $orwhere = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$deleted = 0;
|
||||
$where[] = ['=', 'deleted', $deleted]; //排除已删除运单
|
||||
$status_code = -1;
|
||||
$where[] = ['<>', 'status_code', $status_code]; //排除已取消运单
|
||||
|
||||
$start = date('Y-m-d 00:00:00'); //今日0点
|
||||
// $start = date('2020-08-29 00:00:00'); //测试时段
|
||||
$start = strtotime($start);
|
||||
|
||||
$end = date('Y-m-d H:i:s'); //当前时间点
|
||||
// $end = date('2021-09-04 00:00:00'); //测试时段
|
||||
$end = strtotime($end);
|
||||
|
||||
//今日运单
|
||||
$_where = $where;
|
||||
$_where[] = ['=', 'is_turnover', 0]; //排除交车单
|
||||
$_where[] = ['between', 'sign_date', $start, $end];
|
||||
$data = $model->find()->where($_where);
|
||||
$order_today_count = $data->count();
|
||||
//今日交车
|
||||
$_where = $where;
|
||||
$_where[] = ['=', 'is_turnover', 1]; //交车单
|
||||
$_where[] = ['between', 'sign_date', $start, $end];
|
||||
$data = $model->find()->where($_where);
|
||||
$jiaoche_today_count = $data->count();
|
||||
//今日录单
|
||||
$_where = $where;
|
||||
$_where[] = ['between', 'create_at', $start, $end];
|
||||
$data = $model->find()->where($_where);
|
||||
$order_today_create = $data->count();
|
||||
|
||||
//昨日
|
||||
$_end = $start;
|
||||
$_start = date('Y-m-d 00:00:00', strtotime("-1 day"));
|
||||
$_start = strtotime($_start);
|
||||
//昨日运单
|
||||
$_where = $where;
|
||||
$_where[] = ['=', 'is_turnover', 0]; //排除交车单
|
||||
$_where[] = ['between', 'sign_date', $_start, $_end];
|
||||
$data = $model->find()->where($_where);
|
||||
$order_yesterday_count = $data->count();
|
||||
//昨日交车
|
||||
$_where = $where;
|
||||
$_where[] = ['=', 'is_turnover', 1]; //交车单
|
||||
$_where[] = ['between', 'sign_date', $_start, $_end];
|
||||
$data = $model->find()->where($_where);
|
||||
$jiaoche_yesterday_count = $data->count();
|
||||
//昨日录单
|
||||
$_where = $where;
|
||||
$_where[] = ['between', 'create_at', $_start, $_end];
|
||||
$data = $model->find()->where($_where);
|
||||
$order_yesterday_create = $data->count();
|
||||
|
||||
//本月起始时间点
|
||||
$_start = date('Y-m-01 00:00:00');
|
||||
$ldm = strtotime("last day of " . $_start);
|
||||
$m = date("Y-m-d", $ldm) . " 23:59:59";
|
||||
$_start = strtotime($_start);
|
||||
$_end = strtotime($m);
|
||||
//本月运单
|
||||
$_where = $where;
|
||||
$_where[] = ['=', 'is_turnover', 0]; //排除交车单
|
||||
$_where[] = ['between', 'sign_date', $_start, $_end];
|
||||
$data = $model->find()->where($_where);
|
||||
$order_month_count = $data->count();
|
||||
//本月交车
|
||||
$_where = $where;
|
||||
$_where[] = ['=', 'is_turnover', 1];
|
||||
$_where[] = ['between', 'sign_date', $_start, $_end];
|
||||
$data = $model->find()->where($_where);
|
||||
$jiaoche_month_count = $data->count();
|
||||
|
||||
//累计运单
|
||||
$_where = $where;
|
||||
$_where[] = ['=', 'is_turnover', 0]; //排除交车单
|
||||
$data = $model->find()->where($_where);
|
||||
$order_all_count = $data->count();
|
||||
//累计交车
|
||||
$_where = $where;
|
||||
$_where[] = ['=', 'is_turnover', 1];
|
||||
$data = $model->find()->where($_where);
|
||||
$jiaoche_all_count = $data->count();
|
||||
|
||||
$return = [];
|
||||
$return['code'] = 200;
|
||||
$return['msg'] = '首页数据下载!';
|
||||
$return['data'] = [
|
||||
'orderToday' => $order_today_count,
|
||||
'orderYesterday' => $order_yesterday_count,
|
||||
'orderMonth' => $order_month_count,
|
||||
'orderTotal' => $order_all_count,
|
||||
'jiaocheToday' => $jiaoche_today_count,
|
||||
'jiaocheYesterday' => $jiaoche_yesterday_count,
|
||||
'jiaocheMonth' => $jiaoche_month_count,
|
||||
'jiaocheTotal' => $jiaoche_all_count,
|
||||
'notice' => 0
|
||||
];
|
||||
$this->result($return['msg'], $return['data'], $return['code']);
|
||||
}
|
||||
}
|
||||
+634
@@ -0,0 +1,634 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-04-25T01:57:06+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:18:53+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use addons\models\AcCar;
|
||||
use addons\models\AcCarOwner;
|
||||
use addons\models\AcCarBrand;
|
||||
use addons\models\AcCarSeries;
|
||||
use addons\models\AcStore;
|
||||
use addons\models\AcEmployee;
|
||||
use addons\models\AcOrder;
|
||||
use addons\models\AcOrderPre;
|
||||
use addons\models\AcOrderStatus;
|
||||
use addons\models\AcTruck;
|
||||
use addons\models\AcDriver;
|
||||
use addons\models\AcPlat;
|
||||
use common\models\CVcode;
|
||||
use addons\models\AcContact;
|
||||
use common\models\Member as User;
|
||||
use addons\models\AcUserExt;
|
||||
use common\models\Fans;
|
||||
|
||||
class JiaocheController extends Common
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
$session = Yii::$app->session;
|
||||
$pid = $session->get('pid');
|
||||
$pid = 1;
|
||||
if (!$pid) {
|
||||
$return = [];
|
||||
$return['code'] = 0;
|
||||
$return['msg'] = '您正使用本系统内部接口,禁止非法链接使用!';
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
$return = [];
|
||||
$return['code'] = 200;
|
||||
$return['msg'] = '您正使用CMTS系统,本接口为内部系统接口,禁止非法链接使用!';
|
||||
$return['data'] = ['total' => 0, 'data' => [], 'page' => 1];
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT));
|
||||
}
|
||||
|
||||
//订单列表
|
||||
public function actionList()
|
||||
{
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$pid = 1;
|
||||
$session = Yii::$app->session;
|
||||
$return = [];
|
||||
$model = new AcOrder();
|
||||
$where = $orwhere = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$post = Yii::$app->request->post();
|
||||
$search = isset($post['search']) ? $post['search'] : [];
|
||||
|
||||
$CarModel = new AcCar();
|
||||
if (isset($search['carno']) && !empty($search['carno'])) {
|
||||
$search['carno'] = trim($search['carno']);
|
||||
$cars = $CarModel->find()->where(['LIKE', 'num_left', $search['carno']])->limit(5)->offset(0)->all(); //最多仅显示可匹配车牌号的前5个
|
||||
if (empty($cars)) {
|
||||
$return['code'] = 400;
|
||||
$return['msg'] = '未查询到相关车辆';
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT));
|
||||
} else {
|
||||
$car_ids = [];
|
||||
foreach ($cars as $car) {
|
||||
$car_ids[] = $car->id;
|
||||
}
|
||||
$where[] = ['IN', 'car_id', $car_ids];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($search['city']) && !empty($search['city'])) {
|
||||
$search['city'] = trim($search['city']);
|
||||
$where[] = ['LIKE', 'start_city', $search['city']];
|
||||
}
|
||||
|
||||
if (isset($search['phone']) && !empty($search['phone'])) {
|
||||
$search['phone'] = trim($search['phone']);
|
||||
$orwhere = ['or', ['LIKE', 'sender_mobiles', $search['phone']], ['LIKE', 'receiver_mobiles', $search['phone']]];
|
||||
}
|
||||
|
||||
$deleted = 0;
|
||||
$where[] = ['=', 'deleted', $deleted];
|
||||
$where[] = ['=', 'is_turnover', 1]; //交车单
|
||||
|
||||
$data = $model->find()->where($where)->andwhere($orwhere);
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '10']);
|
||||
|
||||
$_orderby = 'sign_date DESC,id DESC';
|
||||
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
|
||||
$status = Yii::$app->params['OrderStatus'];
|
||||
|
||||
$cids = $sids = $eids = $mids = [];
|
||||
if ($res) {
|
||||
foreach ($res as $r) {
|
||||
$cids[$r->car_id] = $r->car_id;
|
||||
$sids[$r->store_id] = $r->store_id;
|
||||
$eids[$r->employee_id] = $r->employee_id;
|
||||
$mids[$r->from_mid] = $r->from_mid;
|
||||
}
|
||||
}
|
||||
|
||||
$model = new AcStore();
|
||||
$where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$_stores = $model->find()->where(['in', 'id', $sids])->all();
|
||||
$stores = [];
|
||||
foreach ($_stores as $s) {
|
||||
$stores[$s->id] = $s->toArray();
|
||||
}
|
||||
|
||||
$model = new AcEmployee();
|
||||
$employees = [];
|
||||
$_employees = $model->find()->where(['in', 'id', $eids])->indexBy('id')->all();
|
||||
foreach ($_employees as $s) {
|
||||
$employees[$s->id] = $s->toArray();
|
||||
}
|
||||
|
||||
$model = new User();
|
||||
$users = [];
|
||||
$_users = $model->find()->where(['in', 'id', $mids])->all();
|
||||
foreach ($_users as $s) {
|
||||
$s = $s->toArray();
|
||||
$users[$s['id']] = $s;
|
||||
}
|
||||
|
||||
$model = new AcCar();
|
||||
$cars = [];
|
||||
$_cars = $model->find()->where(['in', 'id', $cids])->indexBy('id')->all();
|
||||
$bids = $sids = [];
|
||||
foreach ($_cars as $s) {
|
||||
$bids[] = $s->brand_id;
|
||||
$sids[] = $s->series_id;
|
||||
$cars[$s->id] = $s->toArray();
|
||||
}
|
||||
|
||||
if ($cars) {
|
||||
foreach ($cars as &$car) {
|
||||
$car['title2'] = '';
|
||||
if (isset($brands[$car['brand_id']])) {
|
||||
$car['title2'] .= $brands[$car['brand_id']]['title'];
|
||||
}
|
||||
if (isset($series[$car['series_id']])) {
|
||||
$car['title2'] .= $series[$car['series_id']]['title'];
|
||||
}
|
||||
$car['number2'] = $car['num_frame'];
|
||||
if ($car['num_p']) {
|
||||
$car['number2'] = $car['num_p'];
|
||||
}
|
||||
if ($car['num_area']) {
|
||||
$car['number2'] .= $car['num_area'];
|
||||
}
|
||||
if ($car['num_left']) {
|
||||
$car['number2'] .= $car['num_left'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$orders = [];
|
||||
$unsets = ['pid', 'commission', 'commission_left', 'fee_truck', 'create_at', 'create_by', 'deleted', 'income', 'expense', 'fee_deliver', 'fee_extra', 'fee_insurance', 'fee_pickup', 'fee_urgent', 'from_bid', 'from_mid', 'is_commission', 'is_cwqr', 'is_holdon', 'is_over', 'pay_receive_pids', 'pay_send_pids', 'pre_id', 'remark', 'car_extra', 'thumb_b', 'thumb_f', 'thumb_l', 'thumb_r', 'thumbs', 'driving_lisence', 'videos'];
|
||||
|
||||
foreach ($res as $s) {
|
||||
$car = $cars[$s->car_id];
|
||||
$s = $s->toArray();
|
||||
if (isset($exts[$s['from_mid']])) {
|
||||
foreach ($exts[$s['from_mid']] as $col => $val) {
|
||||
$s[$col] = $val;
|
||||
}
|
||||
}
|
||||
foreach ($unsets as $us) {
|
||||
unset($s[$us]);
|
||||
}
|
||||
$weekdays = [0 => '日', 1 => '一', 2 => '二', 3 => '三', 4 => '四', 5 => '五', 6 => '六'];
|
||||
$wk = date('w', $s['sign_date']);
|
||||
$s['signdate'] = date('Y-m-d ', $s['sign_date']) . '星期' . $weekdays[$wk];
|
||||
$s['from_province'] = Yii::$app->params['regionAreas'][$s['start_province']];
|
||||
$s['to_province'] = Yii::$app->params['regionAreas'][$s['aim_province']];
|
||||
$s['car_number'] = $car['number2'];
|
||||
$s['car_title'] = $car['title'];
|
||||
$s['status'] = $status[$s['status_code']];
|
||||
$orders[] = $s;
|
||||
}
|
||||
|
||||
$return = [];
|
||||
$return['code'] = 200;
|
||||
$return['msg'] = '订单查询成功!';
|
||||
$return['data'] = ['total' => $data->count(),
|
||||
'data' => [
|
||||
'orders' => $orders,
|
||||
'employees' => $employees,
|
||||
'stores' => $stores,
|
||||
'users' => $users
|
||||
],
|
||||
'page' => 1];
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT));
|
||||
}
|
||||
|
||||
public function actionDetail()
|
||||
{
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$status = Yii::$app->params['OrderStatus'];
|
||||
$post = Yii::$app->request->post();
|
||||
$return = [];
|
||||
|
||||
$id = isset($post['oid']) ? $post['oid'] : 0;
|
||||
if ($id <= 0) {
|
||||
$return['code'] = 200;
|
||||
$return['msg'] = '查询参数错误!';
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT));
|
||||
}
|
||||
$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;
|
||||
|
||||
$detail['signdate'] = date('Y-m-d 星期w', $detail['sign_date']);
|
||||
$detail['from_province'] = Yii::$app->params['regionAreas'][$detail['start_province']];
|
||||
$detail['to_province'] = Yii::$app->params['regionAreas'][$detail['aim_province']];
|
||||
$detail['remark'] = htmlspecialchars_decode($detail['remark']);
|
||||
|
||||
// $src = 'http://'.$_SERVER["HTTP_HOST"].'/upload';
|
||||
// $detail['thumb_b'] = $src.$detail['thumb_b'];
|
||||
|
||||
$unsets = ['commission', 'commission_left', 'fee_truck', 'create_at', 'create_by', 'deleted', 'income', 'expense', 'fee_deliver', 'fee_extra', 'fee_insurance', 'fee_pickup', 'fee_urgent', 'from_bid', 'from_mid', 'is_commission', 'is_cwqr', 'is_holdon', 'is_over', 'pay_receive_pids', 'pay_send_pids', 'pre_id'];
|
||||
foreach ($unsets as $us) {
|
||||
unset($detail[$us]);
|
||||
}
|
||||
|
||||
$return['code'] = 200;
|
||||
$return['msg'] = '订单查询成功!';
|
||||
$return['data'] = $detail;
|
||||
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT));
|
||||
}
|
||||
|
||||
public function actionCreate()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$pid = (int)$post['pid'];
|
||||
|
||||
//格式化数据 为空的项则不修改
|
||||
//目标键=》POST键
|
||||
$cols = ['start_province' => 'start_province', 'start_city' => 'start_city', 'aim_province' => 'aim_province', 'aim_city' => 'aim_city', 'aim_address' => 'aim_address',
|
||||
'signer' => 'signer', 'bind' => 'bind', 'wtdw' => "wtdw",
|
||||
'sender_name' => 'sender_name', 'sender_idcard' => 'sender_idcard', 'sender_mobiles' => 'sender_mobiles',
|
||||
'receiver_name' => 'receiver_name', 'receiver_idcard' => 'receiver_idcard', 'receiver_mobiles' => 'receiver_mobiles',
|
||||
'car_extra' => 'car_extra'];
|
||||
foreach ($cols as $col => $key) {
|
||||
if (isset($post[$key]) && $post[$key] != '') {
|
||||
$data[$col] = trim($post[$key]);
|
||||
}
|
||||
}
|
||||
//'car_id'=>'car_id','employee_id'=>'employee_id',
|
||||
//'weituo'=>'weituo'
|
||||
$cols = ['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', 'not_insurance' => 'not_insurance',];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = 0;
|
||||
if (isset($post[$key]) && $post[$key] != '') {
|
||||
$data[$col] = (int)$post[$key];
|
||||
}
|
||||
}
|
||||
|
||||
$cols = ['remark' => 'remark'];
|
||||
foreach ($cols as $col => $key) {
|
||||
if (isset($post[$key]) && $post[$key] != '') {
|
||||
$data[$col] = htmlspecialchars($post[$key]);
|
||||
}
|
||||
}
|
||||
$data['remark'] = isset($data['remark']) ? isset($data['remark']) : '';
|
||||
|
||||
/*@sign_date: 1649952000000*/
|
||||
$sign_date = isset($post['sign_date']) ? strtotime($post['sign_date'] / 1000) : '';
|
||||
$data['sign_date'] = $sign_date ? $sign_date : time();
|
||||
|
||||
$mid = isset($post['mid']) ? (int)$post['mid'] : 11; //11是方孟
|
||||
$data['create_by'] = $mid;
|
||||
$data['is_cwqr'] = 0; //修改财务确认状态为待确认
|
||||
$data['is_turnover'] = 1; //交车补单
|
||||
$data['status_code'] = 1; //订单处于创建待审核状态
|
||||
|
||||
//部分规则校验
|
||||
$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']) {
|
||||
$return = [];
|
||||
$return['code'] = 100;
|
||||
$return['msg'] = '请注意,运费未正确填写!';
|
||||
$return['data'] = [];
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT));
|
||||
}
|
||||
|
||||
if ($fee_total != $data['fee_total']) {
|
||||
$return = [];
|
||||
$return['code'] = 100;
|
||||
$return['msg'] = '所填各项费用汇总的值与所填写的总费用不一致!';
|
||||
$return['data'] = [];
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT));
|
||||
}
|
||||
if ($fee_pay != $data['fee_total']) {
|
||||
$return = [];
|
||||
$return['code'] = 100;
|
||||
$return['msg'] = '所填现付与到收费用汇总的值与所填写的总费用不一致!';
|
||||
$return['data'] = [];
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT));
|
||||
}
|
||||
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
$data['pid'] = $pid;
|
||||
|
||||
$data['employee_id'] = isset($post['employee_id']) ? (int)$post['employee_id'] : 0;
|
||||
$data['store_id'] = 0;
|
||||
$model = new AcEmployee();
|
||||
$employee = $model->findOne($data['employee_id']);
|
||||
if ($employee) {
|
||||
$data['store_id'] = $employee->store_id;
|
||||
}
|
||||
|
||||
//校验生成部分补充数据
|
||||
//生成现付说明
|
||||
$payments = [
|
||||
'wechat' => '微信',
|
||||
'alipay' => '支付宝',
|
||||
'cash' => '现金',
|
||||
'bankcard' => '银行卡',
|
||||
'bankunion' => '银联',
|
||||
'others' => '其他'
|
||||
];
|
||||
if ($post['pay_send']) {
|
||||
$txt = $post['payto'] . '收款' . $post['pay_send'] . '元(' . $payments[$post['payment']] . ')';
|
||||
$data['remark'] .= ' ; ' . $txt;
|
||||
}
|
||||
//生成车辆信息
|
||||
$carModel = new AcCar();
|
||||
$where = [];
|
||||
if ($post['isTempCarno']) {
|
||||
$post['carno_left'] .= '临';
|
||||
}
|
||||
if (empty($post['carno_frame'])) {
|
||||
$where['num_p'] = $post['carno_p'];
|
||||
$where['num_area'] = $post['carno_area'];
|
||||
$where['num_left'] = $post['carno_left'];
|
||||
}
|
||||
if (!empty($post['carno_frame'])) {
|
||||
$where['num_frame'] = $post['carno_frame'];
|
||||
}
|
||||
$car = $carModel->find()->where($where)->one();
|
||||
if (empty($car)) {
|
||||
$carModel->pid = $pid;
|
||||
$carModel->num_frame = $post['carno_frame'];
|
||||
$carModel->num_p = $post['carno_p'];
|
||||
$carModel->num_area = $post['carno_area'];
|
||||
$carModel->num_left = $post['carno_left'];
|
||||
$carModel->title = $post['carno_title'];
|
||||
$carModel->status_code = 1;
|
||||
$carModel->create_at = time();
|
||||
$carModel->update_at = time();
|
||||
$carModel->save();
|
||||
$car_id = $carModel->attributes['id'];
|
||||
} else {
|
||||
$car_id = $car->id;
|
||||
}
|
||||
$data['car_id'] = $car_id;
|
||||
|
||||
//查询联系人信息是否在库
|
||||
$sender_mobiles = isset($data['sender_mobiles']) ? $data['sender_mobiles'] : NULL;
|
||||
$receiver_mobiles = isset($data['receiver_mobiles']) ? $data['receiver_mobiles'] : NULL;
|
||||
if ($sender_mobiles) {
|
||||
//项目分支自有数据表
|
||||
$contactModel = new AcContact();
|
||||
$contactor = $contactModel->find()->where(['mobile' => $data['sender_mobiles'], 'pid' => $pid])->one();
|
||||
if (empty($contactor)) {
|
||||
$contactModel->name = isset($data['sender_name']) ? $data['sender_name'] : '客户';
|
||||
$contactModel->mobile = $data['sender_mobiles'];
|
||||
$contactModel->pid = $pid;
|
||||
$contactModel->idcard = isset($data['sender_idcard']) ? $data['sender_idcard'] : '';
|
||||
$contactModel->create_at = time();
|
||||
$contactModel->status_code = 1;
|
||||
$contactModel->save();
|
||||
} else {
|
||||
$_contactDatas = [];
|
||||
$_contactDatas['name'] = isset($data['sender_name']) ? $data['sender_name'] : $contactModel->name;
|
||||
$_contactDatas['idcard'] = isset($data['idcard']) ? $data['idcard'] : $contactModel->idcard;
|
||||
if ($_contactDatas['name'] == $contactModel->name && $_contactDatas['idcard'] == $contactModel->idcard) {
|
||||
//无须做任何变化
|
||||
} else {
|
||||
$_contactDatas['update_at'] = time();
|
||||
$contactModel->updateAll($_contactDatas, ['id' => $contactModel->id]);
|
||||
}
|
||||
}
|
||||
|
||||
//框架核心数据表Fans
|
||||
$userModel = new Fans();
|
||||
$user = $userModel->findByUsername($sender_mobiles);
|
||||
if (empty($user)) {
|
||||
$userModel->mobile = $sender_mobiles;
|
||||
$userModel->email = $sender_mobiles . '@hiluker.com';
|
||||
$userModel->setPassword(Yii::$app->params['defaultFansPassword']);
|
||||
$userModel->generateAuthKey();
|
||||
$userModel->created_at = time();
|
||||
$userModel->from = 'ctms';
|
||||
$userModel->save();
|
||||
}
|
||||
}
|
||||
if ($receiver_mobiles && $receiver_mobiles != $sender_mobiles) {
|
||||
//项目分支自有数据表
|
||||
$contactModel2 = new AcContact();
|
||||
$contactor2 = $contactModel2->find()->where(['mobile' => $data['receiver_mobiles'], 'pid' => $pid])->one();
|
||||
if (empty($contactor2)) {
|
||||
$contactModel2->name = isset($data['receiver_name']) ? $data['receiver_name'] : '客户';
|
||||
$contactModel2->mobile = $data['receiver_mobiles'];
|
||||
$contactModel2->pid = $pid;
|
||||
$contactModel2->idcard = isset($data['receiver_idcard']) ? $data['receiver_idcard'] : '';
|
||||
$contactModel2->create_at = time();
|
||||
$contactModel2->status_code = 1;
|
||||
$contactModel2->save();
|
||||
} else {
|
||||
$_contactDatas = [];
|
||||
$_contactDatas['name'] = isset($data['receiver_name']) ? $data['receiver_name'] : $contactModel2->name;
|
||||
$_contactDatas['idcard'] = isset($data['idcard']) ? $data['idcard'] : $contactModel2->idcard;
|
||||
if ($_contactDatas['name'] == $contactModel2->name && $_contactDatas['idcard'] == $contactModel2->idcard) {
|
||||
//无须做任何变化
|
||||
} else {
|
||||
$_contactDatas['update_at'] = time();
|
||||
$contactModel2->updateAll($_contactDatas, ['id' => $contactModel2->id]);
|
||||
}
|
||||
}
|
||||
//框架核心数据表Fans
|
||||
$userModel = new Fans();
|
||||
$user = $userModel->findByUsername($receiver_mobiles);
|
||||
if (empty($user)) {
|
||||
$userModel->mobile = $receiver_mobiles;
|
||||
$userModel->email = $receiver_mobiles . '@hiluker.com';
|
||||
$userModel->setPassword(Yii::$app->params['defaultFansPassword']);
|
||||
$userModel->generateAuthKey();
|
||||
$userModel->created_at = time();
|
||||
$userModel->from = 'ctms';
|
||||
$userModel->save();
|
||||
}
|
||||
}
|
||||
|
||||
//保存资料
|
||||
$AcOrder = new AcOrder();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcOrder->$key = $val;
|
||||
}
|
||||
|
||||
$res = $AcOrder->save();
|
||||
$id = $AcOrder->attributes['id']; //获取插入后id
|
||||
|
||||
if ($res) {
|
||||
$return = [];
|
||||
$return['code'] = 200;
|
||||
$return['msg'] = '订单保存成功!';
|
||||
$return['data'] = ['id' => $id];
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT));
|
||||
} else {
|
||||
$return = [];
|
||||
$return['code'] = 100;
|
||||
$return['msg'] = '订单保存失败!';
|
||||
$return['data'] = [];
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT));
|
||||
}
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
|
||||
$model = new AcOrder();
|
||||
$res = $model->findOne($id);
|
||||
$return = [];
|
||||
$return['timeout'] = 1; //几秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
$return['ajax'] = 1;
|
||||
|
||||
if (!$res) {
|
||||
$return['msg'] = '订单数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
} else {
|
||||
$order = $res;
|
||||
if ($order->deleted > 0) {
|
||||
$return['msg'] = '订单已被删除了,无法操作';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'cancel':
|
||||
if ($order->is_cwqr > 0) {
|
||||
$return['msg'] = '订单已入账,请先联系财务销账后再取消';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($order->status_code > 1) {
|
||||
$return['msg'] = '订单已进入运输后流程,无法操作取消';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($order->status_code == -1) {
|
||||
$return['msg'] = '订单已经是被取消状态';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$data['status_code'] = -1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '订单取消成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'btn-info'];
|
||||
} else {
|
||||
$return['msg'] = '订单取消失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'truckcar':
|
||||
if ($order->status_code == -1) {
|
||||
$return['msg'] = '订单已被取消,不能承运';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($order->status_code != 1) {
|
||||
$return['msg'] = '订单当前非初始状态(协议签订),不可作承运处理';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$data['status_code'] = 5;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '订单已转为待承运状态';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'default'];
|
||||
} else {
|
||||
$return['msg'] = '订单标记失败,请稍后再试';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:35:53+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:18:58+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
//前端管理员入口
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use common\models\Member as User;
|
||||
use addons\models\AcUserExt;
|
||||
use addons\models\AcEmployee;
|
||||
use addons\models\AcStore;
|
||||
|
||||
class MemberController extends Common
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
$apis = [
|
||||
'login' => '登陆'
|
||||
];
|
||||
$this->result('您正使用CMTS系统用户管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
//用户登陆
|
||||
public function actionLogin()
|
||||
{
|
||||
$pid = $this->pid;
|
||||
$post = $this->postdata;
|
||||
$search = $post['search'] ?? NULL;
|
||||
|
||||
$username = $search['username'] ?? NULL;
|
||||
$username = $post['username'] ?? $username;
|
||||
|
||||
$passwd = $search['passwd'] ?? NULL;
|
||||
$passwd = $post['passwd'] ?? $passwd;
|
||||
|
||||
$return = [];
|
||||
if (!$username && !$passwd) {
|
||||
$this->result('登陆参数错误!', NULL, 400);
|
||||
}
|
||||
if (!$username) {
|
||||
$this->result('请输入您的账号!', NULL, 400);
|
||||
}
|
||||
if (!$passwd) {
|
||||
$this->result('请输入您的密码!', NULL, 400);
|
||||
}
|
||||
$username = trim(htmlspecialchars_decode($username));
|
||||
$passwd = trim(htmlspecialchars_decode($passwd));
|
||||
if (!$username) {
|
||||
$this->result('输入错误,请检查您的账号!', NULL, 400);
|
||||
}
|
||||
if (!$passwd) {
|
||||
$this->result('输入有误,请检查您的密码!', NULL, 400);
|
||||
}
|
||||
|
||||
$model = new User();
|
||||
$user = $model->findOne(['mobile' => $username]);
|
||||
if (!$user) {
|
||||
$this->result('查无此人!', NULL, 404);
|
||||
}
|
||||
|
||||
if ($user->status != User::STATUS_ACTIVE) {
|
||||
$this->result('账户异常,禁止登陆!', NULL, 403);
|
||||
}
|
||||
//安全校验,登陆密码
|
||||
$isPwdRight = $user->validatePassword($passwd);
|
||||
|
||||
if (!$isPwdRight) {
|
||||
$this->result('密码错误,禁止登陆!', NULL, 400);
|
||||
}
|
||||
//用户主信息校验结束
|
||||
|
||||
//校验网点身份信息
|
||||
$AcEmployeeModel = new AcEmployee();
|
||||
$employee = $AcEmployeeModel->findOne(['mobile' => $user->mobile]);
|
||||
if (!$employee) {
|
||||
$this->result('未找到对应工号,请联系管理员!', NULL, 404);
|
||||
}
|
||||
if ($employee->deleted) {
|
||||
$this->result('工号已清除,禁止登陆!', NULL, 403);
|
||||
}
|
||||
if (!$employee->status) {
|
||||
$this->result('工号禁用,禁止登陆!', NULL, 403);
|
||||
}
|
||||
$this->employee_id = $employee->id;
|
||||
|
||||
$_user = $this->userLogin($user, $employee, TRUE);
|
||||
$this->result('登陆成功!', ['user' => $_user], 200);
|
||||
}
|
||||
|
||||
private function userLogin($user, $employee, $hasExt = FALSE)
|
||||
{
|
||||
// 使用指定用户名获取用户身份实例
|
||||
$identity = $user;
|
||||
// 登录用户,有效期30d
|
||||
$duration = 3600 * 24 * 30;
|
||||
$_login = Yii::$app->user->login($identity, $duration);
|
||||
if (!$_login) {
|
||||
$this->result('登陆失败!', NULL, 400);
|
||||
}
|
||||
//登陆成功,返回用户信息
|
||||
$_user = ['id' => $user->id, 'username' => $user->username, 'mobile' => $user->mobile, 'email' => $user->email, 'avatar' => $user->avatar];
|
||||
$_user['employee_id'] = $this->employee_id;
|
||||
|
||||
$AcStoreModel = new AcStore();
|
||||
$store = $AcStoreModel->findOne($employee->store_id);
|
||||
$_store = [];
|
||||
$citys = Yii::$app->params['citys'];
|
||||
if ($store && !$store->deleted) {
|
||||
$_store = [
|
||||
'id' => $store->id,
|
||||
'title' => $store->title,
|
||||
'city' => isset($citys[$store->city]) ? $citys[$store->city]['name'] : '',
|
||||
'addr' => $store->addr,
|
||||
'longt' => $store->longt,
|
||||
'lat' => $store->lat,
|
||||
'status' => $store->status_code
|
||||
];
|
||||
}
|
||||
$_user['store'] = $_store;
|
||||
|
||||
if ($hasExt) {
|
||||
//查询关联用户的在当前系统中的扩展信息
|
||||
$AcUserExt = new AcUserExt();
|
||||
$exts = $AcUserExt->find()->where(['mid' => $user->id, 'mobile' => $user->mobile, 'pid' => $this->pid, 'deleted' => 0])->all();
|
||||
if ($exts) {
|
||||
foreach ($exts as $ext) {
|
||||
$_user[$ext['key']] = $ext['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
//生成token(用户数据,是否强制更新,过期时间
|
||||
$isLong = $this->postdata['isLong'] ?? FALSE;
|
||||
$expire = $isLong ? '+1 Month' : FALSE;
|
||||
$_user = $this->userToken($_user, $refresh = TRUE, $expire);
|
||||
return $_user;
|
||||
}
|
||||
}
|
||||
Executable
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-13T09:20:03+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:19:04+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
|
||||
//主入口页
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
|
||||
use vendor\huawei\obsclient\Hwobs;
|
||||
use vendor\huawei\obsclient\TemporarySignature;
|
||||
use vendor\huawei\obsclient\PostObject;
|
||||
|
||||
class ObsController extends Common
|
||||
{
|
||||
public function actionIndex()
|
||||
{
|
||||
$apis = [
|
||||
'getkey' => '获取访问Key',
|
||||
];
|
||||
$this->result('您正使用CMTS系统-华为云OBS接口!', $apis, 200);
|
||||
}
|
||||
|
||||
private function getconf()
|
||||
{
|
||||
return [
|
||||
'id' => 'ee124c5102064b83bccd2fdda53261cc', //账号ID
|
||||
'ak' => '1DYBXUNEPNCIEEQOGGAE',
|
||||
'sk' => '0VBI2xPlDB0NtqqVJv3hSFC8DY52G8OYPYNhncGK',
|
||||
'area' => 'cn-south-1', //华南广州
|
||||
'endpoint' => 'obs.cn-south-1.myhuaweicloud.com',
|
||||
'bucketName' => 'hilu-ctms',
|
||||
];
|
||||
}
|
||||
|
||||
public function actionGetkey()
|
||||
{
|
||||
$params = $this->getconf();
|
||||
$obs = new Hwobs($ak = $params['ak'], $sk = $params['sk'], $endpoint = $params['endpoint'], $t1 = 30, $t2 = 10);
|
||||
}
|
||||
|
||||
public function actionGeturl()
|
||||
{
|
||||
$params = $this->getconf();
|
||||
$obs = new TemporarySignature($ak = $params['ak'], $sk = $params['sk'], $endpoint = $params['endpoint'], $t1 = 30, $t2 = 10);
|
||||
$res = $obs->UploadUrl($params['bucketName']);
|
||||
// $res = $obs->getCors($params['bucketName']);
|
||||
var_dump($res);
|
||||
// $this->result('获取上传网址成功!', $res, 200);
|
||||
}
|
||||
|
||||
public function actionGetform()
|
||||
{
|
||||
$params = $this->getconf();
|
||||
$obs = new PostObject($ak = $params['ak'], $sk = $params['sk'], $endpoint = $params['endpoint'], $t1 = 30, $t2 = 10);
|
||||
$obs->init('obs');
|
||||
$res = $obs->claimPost('hilu-ctms', 'file.jpg');
|
||||
$url = 'https://' . $params['bucketName'] . "." . $params['endpoint'];
|
||||
$res['up_url'] = $url;
|
||||
$this->result('获取OBS上传准备信息!', $res, 200);
|
||||
}
|
||||
}
|
||||
+1171
File diff suppressed because it is too large
Load Diff
+198
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-04-24T20:28:47+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:13:49+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use addons\models\AcOrder;
|
||||
|
||||
class OrdercheckController extends Common
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
$apis = [
|
||||
'basic' => '基础验车', //启运网点
|
||||
'online' => '中转验车',
|
||||
'arrive' => '到站验车', //目的地网点
|
||||
];
|
||||
$this->result('您正使用CMTS系统运单验车管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
public function actionBasic()
|
||||
{
|
||||
$pid = $this->pid;
|
||||
$status = Yii::$app->params['OrderStatus'];
|
||||
$post = $this->postdata;
|
||||
|
||||
$id = isset($post['oid']) ? $post['oid'] : 0;
|
||||
if ($id <= 0) {
|
||||
$this->result('查询参数错误!');
|
||||
}
|
||||
$AcOrder = new AcOrder();
|
||||
$order = $AcOrder->findOne($id);
|
||||
if (!$order) {
|
||||
$this->result('该运单数据不存在!');
|
||||
}
|
||||
if (!isset($post['checks'])) {
|
||||
$this->result('验车参数错误!');
|
||||
}
|
||||
$checks = $post['checks']; //需要更新的验车信息
|
||||
//判断执行权限 S
|
||||
if (!$this->user_info) {
|
||||
$this->result('无有效用户登陆信息,无权操作!');
|
||||
}
|
||||
if (!$this->user_id !== $order->from_mid) {
|
||||
// $this->result('不是当前用户的运单,无权操作!');
|
||||
}
|
||||
//判断执行权限 E
|
||||
$hasChange = 0; //是否有需要更新的数据
|
||||
$op = isset($post['op']) ? $post['op'] : '';
|
||||
$isOss = TRUE; //是否启用OSS服务
|
||||
switch ($op) {
|
||||
case 'data':
|
||||
$hasChange = 1;
|
||||
$checker = isset($checks['checker']) ? trim($checks['checker']) : '';
|
||||
$order->checker = $checker ? $checker : $this->user_info->username;
|
||||
$start_km = isset($checks['start_km']) ? (int)$checks['start_km'] : 0;
|
||||
$order->start_km = $start_km;
|
||||
$is_driving_lisence = isset($checks['is_driving_lisence']) ? (int)$checks['is_driving_lisence'] : 0;
|
||||
$order->no_driving_lisence = $is_driving_lisence == 1 ? 1 : 0;
|
||||
$car_extra = isset($checks['car_extra']) ? trim($checks['car_extra']) : '';
|
||||
$order->car_extra = $car_extra;
|
||||
break;
|
||||
case 'driving_lisence':
|
||||
$k = 'driving_lisence';
|
||||
if (isset($checks[$k]) && $checks[$k]) {
|
||||
if (!$isOss) {
|
||||
$file = Yii::getAlias('@upload-src') . $checks[$k];
|
||||
if (file_exists($file)) {
|
||||
$hasChange = 1;
|
||||
$order->$k = $checks[$k];
|
||||
}
|
||||
} else {
|
||||
$hasChange = 1;
|
||||
$order->$k = $checks[$k];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'thumb_f':
|
||||
$k = 'thumb_f';
|
||||
if (isset($checks[$k]) && $checks[$k]) {
|
||||
if (!$isOss) {
|
||||
$file = Yii::getAlias('@upload-src') . $checks[$k];
|
||||
if (file_exists($file)) {
|
||||
$hasChange = 1;
|
||||
$order->$k = $checks[$k];
|
||||
}
|
||||
} else {
|
||||
$hasChange = 1;
|
||||
$order->$k = $checks[$k];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'thumb_b':
|
||||
$k = 'thumb_b';
|
||||
if (isset($checks[$k]) && $checks[$k]) {
|
||||
$file = Yii::getAlias('@upload-src') . $checks[$k];
|
||||
if (file_exists($file)) {
|
||||
$hasChange = 1;
|
||||
$order->$k = $checks[$k];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'thumb_l':
|
||||
$k = 'thumb_l';
|
||||
if (isset($checks[$k]) && $checks[$k]) {
|
||||
if (!$isOss) {
|
||||
$file = Yii::getAlias('@upload-src') . $checks[$k];
|
||||
if (file_exists($file)) {
|
||||
$hasChange = 1;
|
||||
$order->$k = $checks[$k];
|
||||
}
|
||||
} else {
|
||||
$hasChange = 1;
|
||||
$order->$k = $checks[$k];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'thumb_r':
|
||||
$k = 'thumb_r';
|
||||
if (isset($checks[$k]) && $checks[$k]) {
|
||||
if (!$isOss) {
|
||||
$file = Yii::getAlias('@upload-src') . $checks[$k];
|
||||
if (file_exists($file)) {
|
||||
$hasChange = 1;
|
||||
$order->$k = $checks[$k];
|
||||
}
|
||||
} else {
|
||||
$hasChange = 1;
|
||||
$order->$k = $checks[$k];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'thumbs':
|
||||
$k = 'thumbs';
|
||||
if (isset($checks[$k]) && $checks[$k]) {
|
||||
$hasChange = 1;
|
||||
$thumbs = json_encode($checks[$k]);
|
||||
$order->$k = $thumbs;
|
||||
}
|
||||
break;
|
||||
case 'all':
|
||||
$keys = ['driving_lisence', 'thumb_f', 'thumb_b', 'thumb_l', 'thumb_r'];
|
||||
foreach ($keys as $k) {
|
||||
if (isset($checks[$k]) && $checks[$k]) {
|
||||
if (!$isOss) {
|
||||
$file = Yii::getAlias('@upload-src') . $checks[$k];
|
||||
if (file_exists($file)) {
|
||||
$hasChange = 1;
|
||||
$order->$k = $checks[$k];
|
||||
}
|
||||
} else {
|
||||
$hasChange = 1;
|
||||
$order->$k = $checks[$k];
|
||||
}
|
||||
}
|
||||
}
|
||||
$k = 'thumbs';
|
||||
if (isset($checks[$k]) && $checks[$k]) {
|
||||
$hasChange = 1;
|
||||
$thumbs = json_encode($checks[$k]);
|
||||
$order->$k = $thumbs;
|
||||
}
|
||||
$checker = isset($checks['checker']) ? trim($checks['checker']) : '';
|
||||
$order->checker = $checker ? $checker : $this->user_info->username;
|
||||
$start_km = isset($checks['start_km']) ? (int)$checks['start_km'] : 0;
|
||||
$order->start_km = $start_km;
|
||||
$is_driving_lisence = isset($checks['is_driving_lisence']) ? (int)$checks['is_driving_lisence'] : 0;
|
||||
$order->no_driving_lisence = $is_driving_lisence == 1 ? 1 : 0;
|
||||
$car_extra = isset($checks['car_extra']) ? trim($checks['car_extra']) : '';
|
||||
$order->car_extra = $car_extra;
|
||||
if ($hasChange) {
|
||||
$order->is_checked = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ($hasChange) {
|
||||
$res = $order->save();
|
||||
$this->result('操作完成!', $order->toArray(), 200);
|
||||
} else {
|
||||
$this->result('没有要更新的数据!', NULL, 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
+418
@@ -0,0 +1,418 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-04-24T20:28:47+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:00:19+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use addons\models\AcEmployee;
|
||||
use addons\models\AcOrderPre;
|
||||
use addons\models\AcStore;
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
|
||||
class OrderpreController extends Common
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
$apis = [
|
||||
'list' => '搜索询单',
|
||||
'detail' => '询单详情',
|
||||
'create' => '创建询单'
|
||||
];
|
||||
$this->result('您正使用CMTS系统询价单管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
//订单列表
|
||||
public function actionList()
|
||||
{
|
||||
$s = $this->search();
|
||||
$res = $s['res'];
|
||||
if (!$res) {
|
||||
$this->result('没有查询到相应的数据!', [], 0);
|
||||
}
|
||||
$data = $s['data'];
|
||||
$this->showOrder($res, $data);
|
||||
}
|
||||
|
||||
private function search()
|
||||
{
|
||||
$pid = $this->pid;
|
||||
$return = [];
|
||||
$model = new AcOrderPre();
|
||||
$where = $orwhere = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
|
||||
$post = $this->postdata;
|
||||
$search = isset($post['search']) ? $post['search'] : [];
|
||||
//预置搜索条件,只允许查询与自己完全相关的订单
|
||||
$where[] = ['=', 'from_uid', $this->user_id];
|
||||
$search['phone'] = $this->user_info->mobile;
|
||||
$where[] = ['=', 'from_mobile', $search['phone']];
|
||||
|
||||
if (isset($search['carno']) && !empty($search['carno'])) {
|
||||
$search['carno'] = trim($search['carno']);
|
||||
$where[] = ['LIKE', 'car_no', $search['carno']];
|
||||
}
|
||||
if (isset($search['phone']) && !empty($search['phone'])) {
|
||||
$search['phone'] = trim($search['phone']);
|
||||
$where[] = ['=', 'from_mobile', $search['phone']];
|
||||
}
|
||||
|
||||
if (isset($search['city']) && !empty($search['city'])) {
|
||||
$search['city'] = trim($search['city']);
|
||||
$where[] = ['LIKE', 'aim_city', $search['city']];
|
||||
}
|
||||
|
||||
$search['employee'] = isset($search['employee']) ? (int)$search['employee'] : '';
|
||||
$EmployeeModel = new AcEmployee();
|
||||
if (!empty($search['employee'])) {
|
||||
$where[] = ['=', 'employee_id', $search['employee']];
|
||||
$employee = $EmployeeModel->findOne($search['employee']);
|
||||
$search['employee_title'] = isset($employee->name) ? $employee->name : '';
|
||||
}
|
||||
$search['store_id'] = isset($search['store_id']) ? (int)$search['store_id'] : '';
|
||||
if (empty($search['sotre_id'])) {
|
||||
$search['store_id'] = isset($get['store_id']) ? (int)$get['store_id'] : 0;
|
||||
}
|
||||
$StoreModel = new AcStore();
|
||||
if (!empty($search['store_id'])) {
|
||||
$where[] = ['=', 'store_id', $search['store_id']];
|
||||
$store = $StoreModel->findOne($search['store_id']);
|
||||
$search['store_title'] = isset($store->title) ? $store->title : '';
|
||||
}
|
||||
|
||||
$search['start_province'] = isset($search['start_province']) ? trim($search['start_province']) : '';
|
||||
if (!empty($search['start_province'])) {
|
||||
$where[] = ['=', 'start_province', $search['start_province']];
|
||||
}
|
||||
$search['start_city'] = isset($search['start_city']) ? trim($search['start_city']) : '';
|
||||
if (!empty($search['start_city'])) {
|
||||
$where[] = ['LIKE', 'start_city', $search['start_city']];
|
||||
}
|
||||
$search['aim_province'] = isset($search['aim_province']) ? trim($search['aim_province']) : '';
|
||||
if (!empty($search['aim_province'])) {
|
||||
$where[] = ['=', 'aim_province', $search['aim_province']];
|
||||
}
|
||||
$search['aim_city'] = isset($search['aim_city']) ? trim($search['aim_city']) : '';
|
||||
if (!empty($search['aim_city'])) {
|
||||
$where[] = ['LIKE', 'aim_city', $search['aim_city']];
|
||||
}
|
||||
|
||||
$search['bind'] = isset($search['bind']) ? trim($search['bind']) : '';
|
||||
if (!empty($search['bind'])) {
|
||||
$where[] = ['LIKE', 'bind', $search['bind']];
|
||||
}
|
||||
if (isset($search['status_code']) && $search['status_code'] != 'all') {
|
||||
$search['status_code'] = (int)$search['status_code'];
|
||||
$where[] = ['=', 'status_code', $search['status_code']];
|
||||
} else {
|
||||
unset($search['status_code']);
|
||||
}
|
||||
|
||||
$deleted = 0;
|
||||
$where[] = ['=', 'deleted', $deleted];
|
||||
|
||||
$page = $this->page;
|
||||
$pageSize = $this->pageSize;
|
||||
$data = $model->find()->where($where)->andwhere($orwhere);
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $pageSize]);
|
||||
$pages->setPage($page - 1, TRUE); //设置分页的当前页面值
|
||||
$_orderby = 'update_at DESC,id DESC';
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
|
||||
return ['res' => $res, 'data' => $data];
|
||||
}
|
||||
|
||||
private function showOrder($orderRes, $data)
|
||||
{
|
||||
$status = Yii::$app->params['OrderPreStatus'];
|
||||
|
||||
$cids = $sids = $eids = $mids = [];
|
||||
if ($orderRes) {
|
||||
foreach ($orderRes as $r) {
|
||||
$sids[$r->store_id] = $r->store_id;
|
||||
$eids[$r->employee_id] = $r->employee_id;
|
||||
}
|
||||
}
|
||||
|
||||
$where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
|
||||
$model = new AcStore();
|
||||
$_stores = $model->find()->where(['in', 'id', $sids])->all();
|
||||
$stores = [];
|
||||
foreach ($_stores as $s) {
|
||||
$stores[$s->id] = $s->toArray();
|
||||
}
|
||||
unset($s);
|
||||
|
||||
$model = new AcEmployee();
|
||||
$employees = [];
|
||||
$_employees = $model->find()->where(['in', 'id', $eids])->indexBy('id')->all();
|
||||
foreach ($_employees as $s) {
|
||||
$employees[$s->id] = $s->toArray();
|
||||
}
|
||||
unset($s);
|
||||
|
||||
$orders = [];
|
||||
$unsets = ['pid', 'create_at', 'deleted', 'from_mid', 'car'];
|
||||
|
||||
foreach ($orderRes as $s) {
|
||||
$s = $s->toArray();
|
||||
foreach ($unsets as $us) {
|
||||
unset($s[$us]);
|
||||
}
|
||||
$s['price'] = !empty($s['price']) ? $s['price'] : '尚未报价';
|
||||
|
||||
$weekdays = [0 => '日', 1 => '一', 2 => '二', 3 => '三', 4 => '四', 5 => '五', 6 => '六'];
|
||||
$wk = date('w', $s['date']);
|
||||
$s['date_plan'] = date('Y-m-d ', $s['date']) . '星期' . $weekdays[$wk];
|
||||
|
||||
$s['from_province'] = isset($s['start_province']) ? Yii::$app->params['regionAreas'][$s['start_province']] : '';
|
||||
$s['to_province'] = isset($s['aim_province']) ? Yii::$app->params['regionAreas'][$s['aim_province']] : '';
|
||||
|
||||
$s['status'] = $status[$s['status_code']];
|
||||
$orders[] = $s;
|
||||
}
|
||||
unset($s);
|
||||
|
||||
$return = [];
|
||||
$return['code'] = 200;
|
||||
$return['msg'] = '订单查询成功!';
|
||||
$return['data'] = [
|
||||
'total' => $data->count(),
|
||||
'orders' => $orders,
|
||||
'employees' => $employees,
|
||||
'stores' => $stores,
|
||||
'page' => $this->page
|
||||
];
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function actionDetail()
|
||||
{
|
||||
$pid = $this->pid;
|
||||
$status = Yii::$app->params['OrderStatus'];
|
||||
$post = $this->postdata;
|
||||
|
||||
$id = isset($post['id']) ? $post['id'] : 0;
|
||||
if ($id <= 0) {
|
||||
$this->result('查询参数错误!');
|
||||
}
|
||||
$AcOrderPre = new AcOrderPre();
|
||||
$order = $AcOrderPre->findOne($id);
|
||||
$detail = $order->toArray();
|
||||
|
||||
if ($detail['store_id']) {
|
||||
$model = new AcStore();
|
||||
$store = $model->findOne($detail['store_id']);
|
||||
if ($store) {
|
||||
$detail['store_title'] = $store->title;
|
||||
}
|
||||
}
|
||||
|
||||
if ($detail['employee_id']) {
|
||||
$model = new AcEmployee();
|
||||
$employee = $model->findOne($detail['employee_id']);
|
||||
if ($employee) {
|
||||
$detail['employee_title'] = $employee->name;
|
||||
}
|
||||
}
|
||||
|
||||
$sn = '00000000000'; //11位
|
||||
$sn = substr($sn, 0, 11 - strlen($id));
|
||||
$sn .= $id;
|
||||
$detail['sn'] = $detail['sn'] ? $detail['sn'] : $sn;
|
||||
|
||||
$weekdays = [0 => '日', 1 => '一', 2 => '二', 3 => '三', 4 => '四', 5 => '五', 6 => '六'];
|
||||
$wk = date('w', $detail['date']);
|
||||
$detail['date_plan'] = date('Y-m-d 星期' . $weekdays[$wk], $detail['date']);
|
||||
$detail['remark'] = !empty($detail['remark']) ? htmlspecialchars_decode($detail['remark']) : '';
|
||||
$detail['car'] = !empty($detail['car']) ? htmlspecialchars_decode($detail['car']) : '';
|
||||
|
||||
$unsets = ['create_at', 'deleted', 'from_mid'];
|
||||
foreach ($unsets as $us) {
|
||||
unset($detail[$us]);
|
||||
}
|
||||
$this->result('查询成功!', $detail, 200);
|
||||
}
|
||||
|
||||
public function actionCancel()
|
||||
{
|
||||
$pid = $this->pid;
|
||||
$status = Yii::$app->params['OrderStatus'];
|
||||
$post = $this->postdata;
|
||||
|
||||
$id = isset($post['id']) ? $post['id'] : 0;
|
||||
if ($id <= 0) {
|
||||
$this->result('未指定订单!');
|
||||
}
|
||||
$AcOrderPre = new AcOrderPre();
|
||||
$order = $AcOrderPre->findOne($id);
|
||||
if ($order->from_uid != $this->user_id) {
|
||||
$this->result('非本人订单,不允许操作!');
|
||||
}
|
||||
if ($order->status_code <= 0 || $order->status_code >= 99) {
|
||||
$this->result('订单已取消或已经完成,不允许操作!');
|
||||
}
|
||||
$order->status_code = -1;
|
||||
$order->save();
|
||||
$this->result('已取消!', $order->toArray(), 200);
|
||||
}
|
||||
|
||||
public function actionCreate()
|
||||
{
|
||||
/**
|
||||
* 创建咨询单
|
||||
* @mid [int] 平台租户身份
|
||||
* @uid [int] 前端用户身份
|
||||
*/
|
||||
$get = Yii::$app->request->get();
|
||||
$post = $this->postdata;
|
||||
$pid = $this->pid;
|
||||
|
||||
//格式化数据 为空的项则不修改
|
||||
$data['from_uid'] = $this->user_id;
|
||||
//目标键=》POST键
|
||||
$cols = ['start_province' => 'start_province', 'start_city' => 'start_city', 'aim_province' => 'aim_province', 'aim_city' => 'aim_city',
|
||||
'car_title' => 'car_title', 'car_no' => 'car_no', 'price' => 'price',
|
||||
'bind' => 'bind', 'receptionist' => "receptionist",
|
||||
'from_name' => 'from_name', 'from_mobile' => 'from_mobile',
|
||||
];
|
||||
foreach ($cols as $col => $key) {
|
||||
if (isset($post[$key]) && $post[$key] != '') {
|
||||
$data[$col] = trim($post[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$cols = ['car_value' => 'car_value', 'from_gender' => 'from_gender'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = 0;
|
||||
if (isset($post[$key]) && $post[$key] != '') {
|
||||
$data[$col] = (int)$post[$key];
|
||||
}
|
||||
}
|
||||
|
||||
$cols = ['remark' => 'remark', 'car' => 'car'];
|
||||
foreach ($cols as $col => $key) {
|
||||
if (isset($post[$key]) && $post[$key] != '') {
|
||||
$data[$col] = htmlspecialchars($post[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/*@date: 1649952000000*/
|
||||
$data['date'] = isset($post['plan_date']) ? $post['plan_date'] / 1000 : strtotime('+7 day');
|
||||
// 计划时间,默认7天后
|
||||
|
||||
$mid = isset($post['mid']) ? (int)$post['mid'] : 0;
|
||||
$data['from_mid'] = $mid;
|
||||
|
||||
$data['status_code'] = 1; //订单处于创建待审核状态
|
||||
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
$data['pid'] = $pid;
|
||||
|
||||
$data['employee_id'] = isset($post['employee_id']) ? (int)$post['employee_id'] : 0;
|
||||
$data['store_id'] = isset($post['store_id']) ? (int)$post['store_id'] : 0;
|
||||
|
||||
//保存资料
|
||||
$AcOrderPre = new AcOrderPre();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcOrderPre->$key = $val;
|
||||
}
|
||||
|
||||
$res = $AcOrderPre->save();
|
||||
$id = $AcOrderPre->attributes['id']; //获取插入后id
|
||||
|
||||
if ($res) {
|
||||
$this->result('询单保存成功!', ['id' => $id], 200);
|
||||
} else {
|
||||
$this->result('询单保存失败!', [], 100);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
订单数据显示格式化
|
||||
*/
|
||||
|
||||
public function actionEdit()
|
||||
{
|
||||
/**
|
||||
* 更新咨询单
|
||||
* @mid [int] 平台租户身份
|
||||
* @uid [int] 前端用户身份
|
||||
*/
|
||||
$get = Yii::$app->request->get();
|
||||
$post = $this->postdata;
|
||||
$id = isset($post['id']) ? (int)$post['id'] : 0;
|
||||
if (!$id) {
|
||||
$this->result('未指定询价单!');
|
||||
}
|
||||
$model = new AcOrderPre();
|
||||
$detail = $model->findOne($id);
|
||||
if (!$detail) {
|
||||
$this->result('询价单信息不存在!');
|
||||
}
|
||||
if ($detail->pid != $this->pid) {
|
||||
$this->result('非法操作!');
|
||||
}
|
||||
if ($detail->from_uid != $this->user_id) {
|
||||
$this->result('非法操作,请检查订单归属!');
|
||||
}
|
||||
|
||||
//格式化数据 为空的项则不修改
|
||||
|
||||
//目标键=》POST键
|
||||
$cols = ['start_province' => 'start_province', 'start_city' => 'start_city', 'aim_province' => 'aim_province', 'aim_city' => 'aim_city',
|
||||
'car_title' => 'car_title', 'car_no' => 'car_no',
|
||||
'from_name' => 'from_name', 'from_mobile' => 'from_mobile',
|
||||
];
|
||||
foreach ($cols as $col => $key) {
|
||||
if (isset($post[$key]) && $post[$key] != '') {
|
||||
$detail->$col = trim($post[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$cols = ['car_value' => 'car_value', 'from_gender' => 'from_gender'];
|
||||
foreach ($cols as $col => $key) {
|
||||
if (isset($post[$key]) && $post[$key] != '') {
|
||||
$detail->$col = (int)$post[$key];
|
||||
}
|
||||
}
|
||||
|
||||
$cols = ['remark' => 'remark'];
|
||||
foreach ($cols as $col => $key) {
|
||||
if (isset($post[$key]) && $post[$key] != '') {
|
||||
$detail->$col = htmlspecialchars($post[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$detail->date = isset($post['plan_date']) ? $post['plan_date'] / 1000 : $detail->date;
|
||||
|
||||
$detail->status_code = 1; //标记订单处于创建待审核状态
|
||||
$detail->update_at = time();
|
||||
|
||||
//保存资料
|
||||
$res = $detail->save();
|
||||
|
||||
if ($res) {
|
||||
$this->result('询单保存成功!', ['id' => $id], 200);
|
||||
} else {
|
||||
$this->result('询单保存失败!', [], 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
+248
@@ -0,0 +1,248 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:39:14+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:19:45+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcPlat;
|
||||
|
||||
class PlatController extends Common
|
||||
{
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('../layouts/dev', []);
|
||||
}
|
||||
|
||||
public function actionList()
|
||||
{
|
||||
$model = new AcPlat();
|
||||
$search = $where = [];
|
||||
$where[] = 'and';
|
||||
if (isset($_POST['title']) && $_POST['title'] != '') {
|
||||
$search['title'] = $_POST['title'];
|
||||
$where[] = ['LIKE', 'title', $search['title']];
|
||||
}
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$data = $model->find()->where($where);
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '5']);
|
||||
$res = $data->orderby('orderby DESC')->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$plats = [];
|
||||
foreach ($res as $r) {
|
||||
$plats[$r->id] = $r->toArray();
|
||||
}
|
||||
return $this->render('list', [
|
||||
'plats' => $plats,
|
||||
'pager' => $pages,
|
||||
'search' => $search,
|
||||
'status' => $status
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionNew()
|
||||
{
|
||||
return $this->render('modify', []);
|
||||
}
|
||||
|
||||
public function actionEdit()
|
||||
{
|
||||
$model = new AcPlat();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$res = $model->findOne($id);
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
}
|
||||
return $this->render('modify', ['detail' => $res]);
|
||||
}
|
||||
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$data = [];
|
||||
$id = $post['id'];
|
||||
//目标键=》POST键
|
||||
$cols = ['title' => 'title', 'thumb' => 'thumb'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
$cols = ['orderby' => 'orderby', 'deleted' => 'deleted'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
$data['update_at'] = time();
|
||||
$data['create_at'] = $data['update_at'];
|
||||
|
||||
$model = new AcPlat();
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
if ($id) {
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $model->save();
|
||||
$id = $model->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '平台保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '平台保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
}
|
||||
|
||||
public function actionExt()
|
||||
{
|
||||
$session = Yii::$app->session;
|
||||
if (isset($_GET['pid']) && (int)$_GET['pid'] > 0) {
|
||||
$session->set('pid', (int)$_GET['pid']);
|
||||
}
|
||||
$pid = $session->get('pid');
|
||||
if (!$pid) {
|
||||
$url = Url::toRoute(['index/index', 'pid' => 0]);
|
||||
header('location:' . $url);
|
||||
exit;
|
||||
}
|
||||
|
||||
$model = new AcPlat();
|
||||
$res = $model->findOne($pid);
|
||||
$detail = [];
|
||||
if ($res) {
|
||||
$detail = json_decode($res->remark, TRUE);
|
||||
}
|
||||
return $this->render('ext', ['detail' => $detail]);
|
||||
}
|
||||
|
||||
public function actionExtsave()
|
||||
{
|
||||
$user_id = Yii::$app->user->identity->getId();
|
||||
if ($user_id != 1) {
|
||||
\Yii::$app->getSession()->setFlash('warning', '修改失败,平台配置仅支持超级管理员修改!');
|
||||
return $this->redirect(['plat/ext']);
|
||||
}
|
||||
$post = Yii::$app->request->post();
|
||||
$session = Yii::$app->session;
|
||||
$pid = $session->get('pid');
|
||||
|
||||
$data = [];
|
||||
//目标键=》POST键
|
||||
$cols = ['cw_phone' => 'cw_phone'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
$remark = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
$model = new AcPlat();
|
||||
$model->remark = $remark;
|
||||
$res = $model->updateAll(['remark' => $remark], ['id' => $pid]);
|
||||
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '参数保存成功!');
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '参数保存失败!');
|
||||
}
|
||||
return $this->redirect(['plat/ext']);
|
||||
}
|
||||
|
||||
public function actionDelete()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
|
||||
$model = new AcPlat();
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
$return['url'] = Url::toRoute('plat/list');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '平台删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '平台删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return));
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
|
||||
$model = new AcPlat();
|
||||
$res = $model->findOne($id);
|
||||
$return = [];
|
||||
$return['timeout'] = 1; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
$return['ajax'] = 1;
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
} else {
|
||||
$return['msg'] = '平台数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return));
|
||||
}
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'hide':
|
||||
$data['status_code'] = 0;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '平台隐藏成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'info'];
|
||||
} else {
|
||||
$return['msg'] = '平台隐藏失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$data['status_code'] = 1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '平台显示成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'default'];
|
||||
} else {
|
||||
$return['msg'] = '平台显示失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return));
|
||||
}
|
||||
}
|
||||
Executable
+362
@@ -0,0 +1,362 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:38:52+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:13:59+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use vendor\aliyun\dysms\Sms;
|
||||
use common\models\CSms;
|
||||
use common\models\CVcode;
|
||||
use addons\models\AcPlat;
|
||||
|
||||
class SmsController extends Common
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
$apis = [
|
||||
'vcode' => '获取短信验证码'
|
||||
];
|
||||
$this->result('您正使用CMTS-CLIENT系统短信管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
public function actionSend()
|
||||
{
|
||||
global $START_TIME;
|
||||
|
||||
$session = Yii::$app->session;
|
||||
|
||||
//数据取出方法
|
||||
$dataPost = Yii::$app->request->post(); //YII应用内的真实或模拟POST数据
|
||||
$dataGet = Yii::$app->request->get(); //YII应用内的真实或模拟GET数据
|
||||
$params = Yii::$app->params;
|
||||
|
||||
$config = array();
|
||||
$config['accessKeyId'] = isset($dataPost['accessKeyId']) ? $dataPost['accessKeyId'] : $params['aliDySms']['accessKeyId'];
|
||||
$config['accessKeySecret'] = isset($dataPost['accessKeySecret']) ? $dataPost['accessKeySecret'] : $params['aliDySms']['accessKeySecret'];
|
||||
$config['sign'] = isset($dataPost['sign']) ? $dataPost['sign'] : $params['aliDySms']['sign'];
|
||||
if ($config) {
|
||||
$session->set('sms::config', $config);
|
||||
} else {
|
||||
$config = $session->get('sms::config');
|
||||
}
|
||||
|
||||
$option = array();
|
||||
$sms = new Sms($option, $config);
|
||||
|
||||
$address = isset($dataPost['address']) ? $dataPost['address'] : '';
|
||||
if ($address) {
|
||||
$session->set('sms::address', $address);
|
||||
} else {
|
||||
$address = $session->get('sms::address');
|
||||
}
|
||||
|
||||
$tmpl = isset($dataPost['tmpl']) ? $dataPost['tmpl'] : '';
|
||||
if ($tmpl) {
|
||||
$session->set('sms::tmpl', $tmpl);
|
||||
} else {
|
||||
$tmpl = $session->get('sms::tmpl');
|
||||
}
|
||||
|
||||
$_guests = isset($dataPost['guests']) ? $dataPost['guests'] : '';
|
||||
if (!$_guests) {
|
||||
$guests = $session->get('sms::guests');
|
||||
} else {
|
||||
$_guests = explode("\r\n", $_guests);
|
||||
$guests = array();
|
||||
foreach ($_guests as $c) {
|
||||
$_c = explode(',', $c);
|
||||
if (count($_c) > 1) {
|
||||
$k = trim($_c[1]);
|
||||
$v = trim($_c[0]);
|
||||
$guests[$k] = $v;
|
||||
}
|
||||
}
|
||||
unset($_c);
|
||||
unset($k);
|
||||
unset($v);
|
||||
$guests = array_unique($guests);
|
||||
}
|
||||
|
||||
if (!$guests) {
|
||||
$i = (int)$session->get('sms::success');
|
||||
$session->set('sms::success', 0);
|
||||
$msg = $session->get('sms::msg');
|
||||
$session->set('sms::msg', '');
|
||||
$this->result('群发完成,共成功发送' . $i . '条;详情:' . $msg);
|
||||
}
|
||||
|
||||
$results = [];
|
||||
$msg = "";
|
||||
$content = [];
|
||||
$content['address'] = $address;
|
||||
$i = 0;
|
||||
$j = 50;
|
||||
|
||||
foreach ($guests as $p => $username) {
|
||||
$j--;
|
||||
$content['name'] = !empty($username) ? $username . '安诚托车' : '安诚捷顺运车';
|
||||
$result = $sms->send($p, $tmpl, $content);
|
||||
$results[$p] = $result;
|
||||
|
||||
if (!$result) {
|
||||
$msg .= "【" . $p . "】发送失败,接口提示:" . $sms->errors . "\r\n";
|
||||
} else if ($result->Code != 'OK') {
|
||||
$msg .= "【" . $p . "】发送失败,接口提示:" . $result->Message . "\r\n";
|
||||
} else {
|
||||
$i++;
|
||||
$msg .= "【" . $p . "】发送成功";
|
||||
}
|
||||
unset($guests[$p]);
|
||||
if ($j == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$session->set('sms::guests', $guests);
|
||||
|
||||
$i += (int)$session->get('sms::success');
|
||||
$session->set('sms::success', $i);
|
||||
$msg .= $session->get('sms::msg');
|
||||
$session->set('sms::msg', $msg);
|
||||
$this->result('群发完成,共成功发送' . $i . '条;详情:' . $msg);
|
||||
}
|
||||
|
||||
//发送验证码
|
||||
public function actionVcode()
|
||||
{
|
||||
$pid = $this->pid;
|
||||
$plat = AcPlat::findOne($pid);
|
||||
$platExt = json_decode($plat->remark, TRUE);
|
||||
|
||||
//数据取出方法
|
||||
$dataPost = $this->postdata; //YII应用内的真实或模拟POST数据
|
||||
$phone = $dataPost['phone'] ?? 0;
|
||||
//验证手机号
|
||||
$isPhone = FALSE;
|
||||
if ($phone) {
|
||||
$isPhone = preg_match('/^1\d{10}$/', $phone) ? TRUE : FALSE;
|
||||
}
|
||||
if (!$isPhone) {
|
||||
$this->result('手机号不正确,请确认');
|
||||
}
|
||||
// 手机号掩码
|
||||
$phoneMask = substr($phone, 0, 3) . str_repeat('*', strlen($phone) - 7) . substr($phone, -4);
|
||||
|
||||
$params = Yii::$app->params;
|
||||
$codetype = $dataPost['scence'] ?? 'vcode'; //验证码使用场景
|
||||
|
||||
$config = array();
|
||||
$config['accessKeyId'] = isset($dataPost['accessKeyId']) ? $dataPost['accessKeyId'] : $params['aliDySms']['accessKeyId'];
|
||||
$config['accessKeySecret'] = isset($dataPost['accessKeySecret']) ? $dataPost['accessKeySecret'] : $params['aliDySms']['accessKeySecret'];
|
||||
$config['sign'] = isset($dataPost['sign']) ? $dataPost['sign'] : $params['aliDySms']['sign'];
|
||||
|
||||
$option = array();
|
||||
$sms = new Sms($option, $config);
|
||||
$_time = time();
|
||||
$vcodeModel = new CVcode();
|
||||
//查询上次发送记录
|
||||
$where = [];
|
||||
$where['mobile'] = $phone;
|
||||
$where['deleted'] = 0;
|
||||
$where['type'] = $codetype;
|
||||
$res = $vcodeModel->find()->where($where)->one();
|
||||
if ($res) {
|
||||
if (($_time - $res->create_at) < 300) {
|
||||
//设置5分钟内,验证码仍然可用
|
||||
$code = $res->code;
|
||||
$msg = '上次发送的验证码仍然可用;请注意查看手机 ' . $phoneMask;
|
||||
$data = ['errorcode' => 2];
|
||||
if (YII_DEBUG) {
|
||||
$data['code'] = $code;
|
||||
}
|
||||
$this->result($msg, $data, 200);
|
||||
} else {
|
||||
$res->deleted = 1;
|
||||
$res->save();
|
||||
}
|
||||
}
|
||||
|
||||
$content = [];
|
||||
$code = mt_rand(1000, 9999);
|
||||
$content['code'] = $code;
|
||||
|
||||
//验证码准备入库
|
||||
$vcode = [];
|
||||
$vcode['code'] = $code;
|
||||
$vcode['type'] = $codetype;
|
||||
$vcode['mobile'] = $phone;
|
||||
$vcode['create_at'] = $_time;
|
||||
foreach ($vcode as $key => $val) {
|
||||
$vcodeModel->$key = $val;
|
||||
}
|
||||
$tmpls = $params['aliDySms']['tmpl'];
|
||||
switch ($codetype) {
|
||||
case 'reg':
|
||||
$tmpl = $tmpls['regVerify'];
|
||||
break;
|
||||
case 'login':
|
||||
$tmpl = $tmpls['loginVcode'];
|
||||
break;
|
||||
case 'info':
|
||||
$tmpl = $tmpls['infoChange'];
|
||||
break;
|
||||
case 'passwd':
|
||||
$tmpl = $tmpls['passwdChange'];
|
||||
break;
|
||||
case 'vcode':
|
||||
default:
|
||||
$tmpl = $tmpls['vcode'];
|
||||
break;
|
||||
}
|
||||
|
||||
// 发送前控制
|
||||
$host = yii::$app->request->hostName;
|
||||
$debug = $params['aliDySms']['debug'] ?? FALSE;
|
||||
$domains = $params['aliDySms']['domains'] ?? [];
|
||||
$sendable = FALSE;
|
||||
if (in_array($host, $domains) || $debug) {
|
||||
$sendable = TRUE;
|
||||
}
|
||||
$result = TRUE;
|
||||
if ($sendable) {
|
||||
$result = $sms->send($phone, $tmpl, $content);
|
||||
}
|
||||
|
||||
//保存发送记录
|
||||
$smsModel = new CSms();
|
||||
$smsdata = [];
|
||||
$sid = $params['siteId'];
|
||||
$smsdata['sid'] = (int)$sid;
|
||||
$smsdata['pid'] = $pid;
|
||||
$smsdata['uid'] = $this->user_id;
|
||||
$smsdata['mid'] = 0;
|
||||
$smsdata['mobile'] = $phone;
|
||||
$smsdata['content'] = json_encode($content, JSON_UNESCAPED_UNICODE);
|
||||
$smsdata['create_at'] = $_time;
|
||||
foreach ($smsdata as $key => $val) {
|
||||
$smsModel->$key = $val;
|
||||
}
|
||||
$smsModel->save();
|
||||
|
||||
$errorcode = 0;
|
||||
$msg = '';
|
||||
if (!$result) {
|
||||
$msg .= "发送失败,接口提示:" . $sms->errors;
|
||||
$errorcode = 3;
|
||||
} else if (is_array($result) && $result['Code'] != 'OK') {
|
||||
$msg .= "发送失败,接口提示:" . $result['Message'];
|
||||
$errorcode = 4;
|
||||
} else {
|
||||
$vcodeModel->save();
|
||||
$msg .= "发送成功";
|
||||
}
|
||||
$data = ['errorcode' => $errorcode];
|
||||
if (!$debug || YII_DEBUG) {
|
||||
$data['data'] = $content;
|
||||
}
|
||||
$this->result($msg, $data, 200);
|
||||
}
|
||||
|
||||
//发送给财务
|
||||
public function actionCaiwu()
|
||||
{
|
||||
$pid = $this->pid;
|
||||
$plat = AcPlat::findOne($pid);
|
||||
$platExt = json_decode($plat->remark, TRUE);
|
||||
|
||||
$phone = $platExt['cw_phone'];
|
||||
if (!$phone) {
|
||||
$this->result('还没有配置财务手机号,请联系站长管理员进行设置!', ['errorcode' => 1], 200);
|
||||
}
|
||||
|
||||
$vcodeModel = new CVcode();
|
||||
$codetype = 'caiwu';
|
||||
//查询上次发送记录
|
||||
$_time = time();
|
||||
$where = [];
|
||||
$where['mobile'] = $phone;
|
||||
$where['deleted'] = 0;
|
||||
$where['type'] = $codetype;
|
||||
$res = $vcodeModel->find()->where($where)->one();
|
||||
if ($res) {
|
||||
if (($_time - $res->create_at) < 7200) {
|
||||
//设置2小时内,验证码仍然可用
|
||||
$code = $res->code;
|
||||
$this->result('上次发送的验证码仍然可用;请注意查看财务手机!', ['errorcode' => 2], 200);
|
||||
} else {
|
||||
$res->deleted = 1;
|
||||
$res->save();
|
||||
}
|
||||
}
|
||||
|
||||
//数据取出方法
|
||||
$dataPost = $this->postdata; //YII应用内的真实或模拟POST数据
|
||||
$params = Yii::$app->params;
|
||||
|
||||
$content = [];
|
||||
$code = mt_rand(1000, 9999);
|
||||
$content['code'] = $code;
|
||||
$tmpl = $params['aliDySms']['tmpl']['cwVcode'];
|
||||
|
||||
//验证码准备入库
|
||||
$vcode = [];
|
||||
$vcode['code'] = $code;
|
||||
$vcode['type'] = $codetype;
|
||||
$vcode['mobile'] = $phone;
|
||||
$vcode['create_at'] = $_time;
|
||||
foreach ($vcode as $key => $val) {
|
||||
$vcodeModel->$key = $val;
|
||||
}
|
||||
|
||||
$config = array();
|
||||
$config['accessKeyId'] = isset($dataPost['accessKeyId']) ? $dataPost['accessKeyId'] : $params['aliDySms']['accessKeyId'];
|
||||
$config['accessKeySecret'] = isset($dataPost['accessKeySecret']) ? $dataPost['accessKeySecret'] : $params['aliDySms']['accessKeySecret'];
|
||||
$config['sign'] = isset($dataPost['sign']) ? $dataPost['sign'] : $params['aliDySms']['sign'];
|
||||
|
||||
$option = array();
|
||||
$sms = new Sms($option, $config);
|
||||
$result = $sms->send($phone, $tmpl, $content); //编排发送短信
|
||||
//保存发送记录
|
||||
$smsModel = new CSms();
|
||||
$smsdata = [];
|
||||
$sid = $params['siteId'];
|
||||
$smsdata['sid'] = (int)$sid;
|
||||
$smsdata['pid'] = $pid;
|
||||
$smsdata['uid'] = $this->user_id;
|
||||
$smsdata['mid'] = 0;
|
||||
$smsdata['mobile'] = $phone;
|
||||
$smsdata['content'] = json_encode($content, JSON_UNESCAPED_UNICODE);
|
||||
$smsdata['create_at'] = $_time;
|
||||
foreach ($smsdata as $key => $val) {
|
||||
$smsModel->$key = $val;
|
||||
}
|
||||
$smsModel->save();
|
||||
|
||||
$errorcode = 0;
|
||||
$msg = '';
|
||||
if (!$result) {
|
||||
$msg .= "发送失败,接口提示:" . $sms->errors;
|
||||
$errorcode = 3;
|
||||
} else if (is_array($result) && $result['Code'] != 'OK') {
|
||||
$msg .= "发送失败,接口提示:" . $result['Message'];
|
||||
$errorcode = 4;
|
||||
} else {
|
||||
$vcodeModel->save();
|
||||
$msg .= "发送成功";
|
||||
}
|
||||
$this->result($msg, ['errorcode' => $errorcode], 200);
|
||||
}
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-16T16:31:49+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:19:58+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcStore;
|
||||
|
||||
class StoreController extends Common
|
||||
{
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
$apis = [
|
||||
'list' => '网点清单',
|
||||
'detail' => '网点详情'
|
||||
];
|
||||
$this->result('您正使用CMTS系统网点管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
public function actionList()
|
||||
{
|
||||
$pid = $this->pid;
|
||||
$model = new AcStore();
|
||||
$where = [];
|
||||
$where['pid'] = $pid;
|
||||
$citys = Yii::$app->params['citys'];
|
||||
$post = $this->postdata;
|
||||
|
||||
$where['deleted'] = 0;
|
||||
$where['status_code'] = 1;
|
||||
$data = $model->find()->where($where);
|
||||
|
||||
$page = $this->page;
|
||||
$pageSize = $this->pageSize;
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $pageSize]);
|
||||
$pages->setPage($page - 1, TRUE); //设置分页的当前页面值
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
if (!$res) {
|
||||
$this->result('没有符合条件的结果');
|
||||
}
|
||||
$stores = [];
|
||||
foreach ($res as $k => $v) {
|
||||
$stores[$v->id] = $v->toArray();
|
||||
}
|
||||
$return = [];
|
||||
$return['data'] = [
|
||||
'stores' => $stores,
|
||||
'citys' => $citys,
|
||||
];
|
||||
$return['total'] = $data->count();
|
||||
$return['page'] = $this->page;
|
||||
$this->result('网点列表', $return, 200);
|
||||
}
|
||||
|
||||
public function actionSelect()
|
||||
{
|
||||
$model = new AcStore();
|
||||
$where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$citys = Yii::$app->params['citys'];
|
||||
$post = Yii::$app->request->post();
|
||||
|
||||
$where['deleted'] = 0;
|
||||
$where['status_code'] = 1;
|
||||
$data = $model->find()->where($where);
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2 = ['LIKE', 'title', $search['title']];
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = ['0' => '隐藏', '1' => '正常'];
|
||||
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'store';
|
||||
return $this->render('select', [
|
||||
'stores' => $res,
|
||||
'pager' => $pages,
|
||||
'citys' => $citys,
|
||||
'status' => $status,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
}
|
||||
}
|
||||
+422
@@ -0,0 +1,422 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:38:08+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:20:07+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcTruck;
|
||||
use addons\models\AcDriver;
|
||||
|
||||
class TruckController extends Common
|
||||
{
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('../layouts/dev', []);
|
||||
}
|
||||
|
||||
//板车列表
|
||||
public function actionList()
|
||||
{
|
||||
$AcTruck = new AcTruck();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'num_left', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $AcTruck->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['TruckStatus'];
|
||||
$AcDriver = new AcDriver();
|
||||
$where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$_drivers = $AcDriver->find()->where($where)->all();
|
||||
$drivers = [];
|
||||
foreach ($_drivers as $s) {
|
||||
$drivers[$s->id] = $s->toArray();
|
||||
}
|
||||
|
||||
return $this->render('list', [
|
||||
'trucks' => $res,
|
||||
'pager' => $pages,
|
||||
'drivers' => $drivers,
|
||||
'status' => $status,
|
||||
'search' => $search
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionSelect()
|
||||
{
|
||||
$AcTruck = new AcTruck();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'num_left', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $AcTruck->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['TruckStatus'];
|
||||
$AcDriver = new AcDriver();
|
||||
$where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$_drivers = $AcDriver->find()->where($where)->all();
|
||||
$drivers = [];
|
||||
foreach ($_drivers as $s) {
|
||||
$drivers[$s->id] = $s->toArray();
|
||||
}
|
||||
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'truck';
|
||||
return $this->render('select', [
|
||||
'trucks' => $res,
|
||||
'pager' => $pages,
|
||||
'drivers' => $drivers,
|
||||
'status' => $status,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionNew()
|
||||
{
|
||||
$status = Yii::$app->params['TruckStatus'];
|
||||
$AcTruck = new AcTruck();
|
||||
$AcTruck->status_code = 0;
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $AcTruck]);
|
||||
}
|
||||
|
||||
//编辑板车资料
|
||||
public function actionEdit()
|
||||
{
|
||||
$model = new AcTruck();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
}
|
||||
$AcDriver = new AcDriver();
|
||||
$driver = $AcDriver->find()->where(['id' => $res['driver_id']])->one();
|
||||
if ($driver) {
|
||||
$res['driver_title'] = $driver->name;
|
||||
}
|
||||
$driver2 = $AcDriver->find()->where(['id' => $res['driver2_id']])->one();
|
||||
if ($driver2) {
|
||||
$res['driver2_title'] = $driver2->name;
|
||||
}
|
||||
$status = Yii::$app->params['TruckStatus'];
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $res]);
|
||||
}
|
||||
|
||||
//保存板车资料
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['num_p' => 'num_p', 'num_area' => 'num_area', 'num_left' => 'num_left'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
//查询车牌号是否在库
|
||||
$hasTruck = AcTruck::find()->where(['num_p' => $data['num_p'], 'num_area' => $data['num_area'], 'num_left' => $data['num_left']])->one();
|
||||
if ($hasTruck) {
|
||||
if ($id && $id != $hasTruck->id) {
|
||||
\Yii::$app->getSession()->setFlash('danger', '保存失败,该车牌号已在库!');
|
||||
return $this->goBack();
|
||||
} else {
|
||||
$id = $hasTruck->id;
|
||||
}
|
||||
}
|
||||
|
||||
$cols = ['driver_id' => 'driver', 'driver2_id' => 'driver2', 'status_code' => 'status_code', 'max_cars' => 'max_cars', 'deleted' => 'deleted'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
$cols = ['remark' => 'editor'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? htmlspecialchars($post[$key]) : '';
|
||||
}
|
||||
$data['create_at'] = time();
|
||||
$data['update_at'] = $data['create_at'];
|
||||
// $data['status_code'] = 1;
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//保存板车资料
|
||||
$AcTruck = new AcTruck();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcTruck->$key = $val;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$AcTruck->id = $id;
|
||||
unset($data['create_at']);
|
||||
$res = $AcTruck->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcTruck->save();
|
||||
$id = $AcTruck->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '板车资料保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '板车资料保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
}
|
||||
|
||||
//删除板车
|
||||
public function actionDelete()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
|
||||
$model = new AcTruck();
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
$return['url'] = Url::toRoute('truck/list');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '板车删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '板车删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
|
||||
$model = new AcTruck();
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
$return = [];
|
||||
$return['timeout'] = 1; //3秒后自动跳转
|
||||
$return['ajax'] = 1;
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
} else {
|
||||
$return['msg'] = '板车数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'hide':
|
||||
$data['status_code'] = 0;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '板车停用标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'default'];
|
||||
} else {
|
||||
$return['msg'] = '板车停用标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$data['status_code'] = 1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '板车入库记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'primary'];
|
||||
} else {
|
||||
$return['msg'] = '板车入库标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'lock':
|
||||
$data['status_code'] = 99;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '板车锁定标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'danger'];
|
||||
} else {
|
||||
$return['msg'] = '板车锁定标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'repair':
|
||||
$data['status_code'] = 2;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '板车检修标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'warning'];
|
||||
} else {
|
||||
$return['msg'] = '板车检修标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'reset':
|
||||
$data['status_code'] = 2;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '板车保养标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'info'];
|
||||
} else {
|
||||
$return['msg'] = '板车保养标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'working':
|
||||
$data['status_code'] = 1;
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '板车恢复正常,标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'success'];
|
||||
} else {
|
||||
$return['msg'] = '板车恢复标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
//发车
|
||||
public function actionFache()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
|
||||
$AcTruck = new AcTruck();
|
||||
$truck = $AcTruck->findOne($id);
|
||||
if (!$truck) {
|
||||
$return['msg'] = '板车数据不存在';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($truck->status_code == 4) {
|
||||
$return = [];
|
||||
// $return['url'] = Url::toRoute('truckol/modify');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
$return['msg'] = '当前板车已在装车中,发车操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
} else if ($truck->status_code == 5) {
|
||||
$return = [];
|
||||
// $return['url'] = Url::toRoute('truckol/modify');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
$return['msg'] = '当前板车已在运输途中,发车操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
} else if ($truck->status_code != 1) {
|
||||
$return['msg'] = '当前板车状态不允许发车,请先确认板车已归为正常状态';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
$data['status_code'] = 4;
|
||||
foreach ($data as $key => $val) {
|
||||
$AcTruck->$key = $val;
|
||||
}
|
||||
$res = $AcTruck->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
// $return['url'] = Url::toRoute('truckol/modify');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '发车成功,请进行下一步操作';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '发车操作失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
//浏览板车资料
|
||||
public function actionDetail()
|
||||
{
|
||||
$model = new AcTruck();
|
||||
$id = Yii::$app->request->get('id');
|
||||
$res = $model->find()->where(['id' => $id])->one();
|
||||
if ($res) {
|
||||
$res = $res->toArray();
|
||||
}
|
||||
$AcDriver = new AcDriver();
|
||||
$driver = $AcDriver->find()->where(['id' => $res['driver_id']])->one();
|
||||
if ($driver) {
|
||||
$res['driver_title'] = $driver->name;
|
||||
$res['driver_mobile'] = $driver->mobile;
|
||||
}
|
||||
$driver2 = $AcDriver->find()->where(['id' => $res['driver2_id']])->one();
|
||||
if ($driver2) {
|
||||
$res['driver2_title'] = $driver2->name;
|
||||
$res['driver2_mobile'] = $driver2->mobile;
|
||||
}
|
||||
$status = Yii::$app->params['TruckStatus'];
|
||||
return $this->render('detail', ['status' => $status, 'detail' => $res]);
|
||||
}
|
||||
}
|
||||
+562
@@ -0,0 +1,562 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:38:28+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:20:02+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcTruck;
|
||||
use addons\models\AcDriver;
|
||||
use addons\models\AcTruckOnline;
|
||||
use addons\models\AcTruckCars;
|
||||
use addons\models\AcStore;
|
||||
use addons\models\AcCar;
|
||||
use addons\models\AcCarBrand;
|
||||
use addons\models\AcCarSeries;
|
||||
use addons\models\AcOrder;
|
||||
use addons\models\AcGps;
|
||||
use addons\models\AcGpsRoute;
|
||||
|
||||
class TruckcarController extends Common
|
||||
{
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('../layouts/dev', []);
|
||||
}
|
||||
|
||||
//所有装车记录列表
|
||||
public function actionList()
|
||||
{
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$post = Yii::$app->request->post();
|
||||
$online_id = Yii::$app->request->get('online_id'); //发车任务ID
|
||||
|
||||
$AcTruckCars = new AcTruckCars();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', Yii::$app->session->get('pid')];
|
||||
|
||||
$search = isset($post['search']) ? $post['search'] : [];
|
||||
$search['start_city'] = isset($search['start_city']) ? trim(htmlspecialchars_decode($search['start_city'])) : '';
|
||||
if (!empty($search['start_city'])) {
|
||||
$where[] = ['LIKE', 'from_city', $search['start_city']];
|
||||
}
|
||||
$search['aim_city'] = isset($search['aim_city']) ? trim(htmlspecialchars_decode($search['aim_city'])) : '';
|
||||
if (!empty($search['aim_city'])) {
|
||||
$where[] = ['LIKE', 'to_city', $search['aim_city']];
|
||||
}
|
||||
$search['car_id'] = isset($search['car_id']) ? (int)$search['car_id'] : 0;
|
||||
$CarModel = new AcCar();
|
||||
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['status_code'] = isset($search['status_code']) ? $search['status_code'] : 'all';
|
||||
if ($search['status_code'] != 'all') {
|
||||
$where[] = ['=', 'status_code', (int)$search['status_code']];
|
||||
}
|
||||
//按月份筛选
|
||||
$search['start_m'] = isset($search['start_m']) ? $search['start_m'] : '';
|
||||
if (!empty($search['start_m'])) {
|
||||
$start = strtotime($search['start_m']);
|
||||
$s = date("Y-m-d H:i:s", $start);
|
||||
$ldm = strtotime("last day of " . $s);
|
||||
$m = date("Y-m-d", $ldm) . " 23:59:59";
|
||||
$end = strtotime($m);
|
||||
$where[] = ['between', 'from_time', $start, $end];
|
||||
}
|
||||
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$data = $AcTruckCars->find()->where($where);
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby('status_code ASC,id DESC')->all();
|
||||
|
||||
$car_ids = [];
|
||||
foreach ($res as $r) {
|
||||
$car_ids[] = $r->car_id;
|
||||
}
|
||||
|
||||
$AcCar = new AcCar();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$where[] = ['IN', 'id', $car_ids];
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$cars = $AcCar->find()->where($where)->indexby('id')->all();
|
||||
|
||||
$status = Yii::$app->params['TruckCarsStatus'];
|
||||
|
||||
return $this->render('list', [
|
||||
'list' => $res,
|
||||
'pager' => $pages,
|
||||
'status' => $status,
|
||||
'cars' => $cars,
|
||||
'search' => $search
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionNew()
|
||||
{
|
||||
$status = Yii::$app->params['TruckCarsStatus'];
|
||||
$AcTruckCars = [];
|
||||
$AcTruckCars['status_code'] = 0;
|
||||
$online_id = Yii::$app->request->get('online_id'); //发车任务ID
|
||||
$AcTruckCars['online_id'] = $online_id;
|
||||
$order_id = Yii::$app->request->get('order_id'); //待承运订单ID
|
||||
$AcTruckCars['order_id'] = $order_id;
|
||||
$car_id = Yii::$app->request->get('car_id'); //待装客车ID
|
||||
$AcTruckCars['car_id'] = $car_id;
|
||||
return $this->render('create', ['status' => $status, 'detail' => $AcTruckCars]);
|
||||
}
|
||||
|
||||
//编辑客车上板信息
|
||||
public function actionEdit()
|
||||
{
|
||||
$id = Yii::$app->request->get('id'); //承运单ID
|
||||
$truck_id = $online_id = $store_id = $store2_id = 0;
|
||||
$truckCar = $truckol = [];
|
||||
|
||||
$AcTruckCars = new AcTruckCars();
|
||||
$res = $AcTruckCars->findOne($id);
|
||||
if ($res) {
|
||||
$truckCar = $res->toArray();
|
||||
$online_id = $res->online_id;
|
||||
$store2_id = $res->to_store;
|
||||
$store_id = $res->from_store;
|
||||
$order_id = $res->order_id;
|
||||
}
|
||||
|
||||
$AcOrder = new AcOrder();
|
||||
$order = $AcOrder->findOne($order_id);
|
||||
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$res = $AcTruckOnline->findOne($online_id);
|
||||
if ($res) {
|
||||
$truck_id = $res->truck_id;
|
||||
$truckol = $res->toArray();
|
||||
}
|
||||
|
||||
$AcTruck = new AcTruck();
|
||||
$truck = $AcTruck->findOne($truck_id);
|
||||
if (!$truck) {
|
||||
$post = Yii::$app->request->post();
|
||||
$return = [];
|
||||
$return['msg'] = '关联板车数据获取异常,发车任务编辑失败';
|
||||
$return['errorcode'] = 0;
|
||||
$return['url'] = Url::toRoute(['truck/list', $post]);
|
||||
$return['buttons'] = [
|
||||
['title' => '好的,我知道了', 'class' => 'info', 'url' => $return['url']]
|
||||
];
|
||||
$return['content'] = $return['msg'];
|
||||
$return['class'] = 'warning';
|
||||
Yii::$app->request->setBodyParams($return);
|
||||
return Yii::$app->runAction('index/msg');
|
||||
}
|
||||
$truckCar['truck_id'] = $truck_id;
|
||||
$truckCar['truck_title'] = $truck->num_p . $truck->num_area . $truck->num_left;
|
||||
$truckCar['truck_num'] = $truckCar['truck_title'] ? $truckCar['truck_title'] : $truckol['truck_num'];
|
||||
|
||||
$AcStore = new AcStore();
|
||||
$store = $AcStore->findOne($store_id);
|
||||
if ($store) {
|
||||
$truckCar['fromstore_title'] = $store->title;
|
||||
}
|
||||
$store2 = $AcStore->findOne($store2_id);
|
||||
if ($store2) {
|
||||
$truckCar['endstore_title'] = $store2->title;
|
||||
}
|
||||
|
||||
$AcDriver = new AcDriver();
|
||||
$driver = $AcDriver->find()->where(['id' => $truck->driver_id])->one();
|
||||
$truckCar['driver_title'] = $truckCar['driver_mobile'] = '';
|
||||
if ($driver) {
|
||||
$truckCar['driver_title'] = $driver->name;
|
||||
$truckCar['driver_mobile'] = $driver->mobile;
|
||||
}
|
||||
$truckCar['from_time'] = !empty($truckCar['from_time']) ? $truckCar['from_time'] : $truckol['from_date'];
|
||||
$truckCar['to_time'] = !empty($truckCar['to_time']) ? $truckCar['to_time'] : $truckol['end_date'];
|
||||
$from_city = $order->start_city;
|
||||
$truckCar['from_city'] = !empty($truckCar['from_city']) ? $truckCar['from_city'] : $from_city;
|
||||
$truckCar['from_city'] = $truckCar['from_city'] ? $truckCar['from_city'] : $truckol['from_city'];
|
||||
$end_city = $order->aim_city;
|
||||
$truckCar['to_city'] = !empty($truckCar['to_city']) ? $truckCar['to_city'] : $end_city;
|
||||
$truckCar['to_city'] = $truckCar['to_city'] ? $truckCar['to_city'] : $truckol['end_city'];
|
||||
$truckCar['driver_name'] = isset($truckCar['driver_name']) ? $truckCar['driver_name'] : $truckol['driver_name'];
|
||||
$truckCar['driver_mobiles'] = isset($truckCar['driver_mobiles']) ? $truckCar['driver_mobiles'] : $truckol['driver_mobiles'];
|
||||
$status = Yii::$app->params['TruckCarsStatus'];
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $truckCar]);
|
||||
}
|
||||
|
||||
//保存客车上板信息(直接指派方式)
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['from_city' => 'from_city', 'to_city' => 'to_city'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
|
||||
$cols = ['online_id' => 'online_id', 'from_store' => 'from_store', 'to_store' => 'to_store'];
|
||||
if (isset($_GET['debug']) && ($_GET['debug'] == 1)) {
|
||||
$cols['status_code'] = 'status_code';
|
||||
}
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
|
||||
/*出车计划判断*/
|
||||
$online_id = $data['online_id'];
|
||||
if (!$online_id) {
|
||||
$return['msg'] = '未关联板车出车计划信息,保存失败';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$truckol = $AcTruckOnline->findOne($online_id);
|
||||
if (!$truckol) {
|
||||
$return['msg'] = '未找到指定板车出车计划,保存失败';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
$key = 'remark';
|
||||
$data[$key] = isset($post[$key]) ? htmlspecialchars(trim($post[$key])) : '';
|
||||
|
||||
$_time = time();
|
||||
$key = 'to_time';
|
||||
if (isset($post[$key]) && $post[$key] != "") {
|
||||
$data[$key] = strtotime($post[$key]);
|
||||
}
|
||||
$key = 'from_time';
|
||||
if (isset($post[$key]) && $post[$key] != "") {
|
||||
$data[$key] = strtotime($post[$key]);
|
||||
}
|
||||
|
||||
if (!$id) {
|
||||
$data['create_at'] = $_time;
|
||||
}
|
||||
$data['update_at'] = $_time;
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//保存上板信息
|
||||
$AcTruckCars = new AcTruckCars();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcTruckCars->$key = $val;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$res = $AcTruckCars->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcTruckCars->save();
|
||||
$id = $AcTruckCars->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
//修改对应运单状态
|
||||
$_code = 0;
|
||||
if (isset($data['status_code'])) {
|
||||
if ($data['status_code'] == 1) {
|
||||
$_code = 2;
|
||||
} else if ($data['status_code'] == 99) {
|
||||
$_code = 3;
|
||||
}
|
||||
}
|
||||
|
||||
if ($_code) {
|
||||
$order_id = isset($post['order_id']) ? (int)$post['order_id'] : 0;
|
||||
if (!$order_id) {
|
||||
$car = $AcTruckCars->findOne($id);
|
||||
$order_id = $car->order_id;
|
||||
}
|
||||
$AcOrder = new AcOrder();
|
||||
$order = $AcOrder->findOne($order_id);
|
||||
$order->update_at = $_time;
|
||||
|
||||
$order->status_code = $_code;
|
||||
$order->save();
|
||||
}
|
||||
|
||||
\Yii::$app->getSession()->setFlash('success', '信息保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '信息保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
}
|
||||
|
||||
//保存客车上板信息(板车出车界面车辆管理方式)
|
||||
public function actionSave2()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['from_city' => 'from_city', 'to_city' => 'to_city'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
|
||||
$cols = ['online_id' => 'online_id', 'from_store' => 'from_store', 'to_store' => 'to_store', 'order_id' => 'order_id', 'car_id' => 'car_id'];
|
||||
if (isset($_GET['debug']) && ($_GET['debug'] == 1)) {
|
||||
$cols['status_code'] = 'status_code';
|
||||
}
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
|
||||
/*出车计划判断*/
|
||||
$online_id = $data['online_id'];
|
||||
if (!$online_id) {
|
||||
$return['msg'] = '未关联板车出车计划信息,保存失败';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$truckol = $AcTruckOnline->findOne($online_id);
|
||||
if (!$truckol) {
|
||||
$return['msg'] = '未找到指定板车出车计划,保存失败';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
$key = 'remark';
|
||||
$data[$key] = isset($post[$key]) ? htmlspecialchars(trim($post[$key])) : '';
|
||||
|
||||
$_time = time();
|
||||
$key = 'to_time';
|
||||
if (isset($post[$key]) && $post[$key] != "") {
|
||||
$data[$key] = strtotime($post[$key]);
|
||||
}
|
||||
$key = 'from_time';
|
||||
if (isset($post[$key]) && $post[$key] != "") {
|
||||
$data[$key] = strtotime($post[$key]);
|
||||
}
|
||||
|
||||
if (!$id) {
|
||||
$data['create_at'] = $_time;
|
||||
}
|
||||
$data['update_at'] = $_time;
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//保存上板信息
|
||||
$AcTruckCars = new AcTruckCars();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcTruckCars->$key = $val;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$res = $AcTruckCars->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcTruckCars->save();
|
||||
$id = $AcTruckCars->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
//修改对应运单状态
|
||||
$_code = 0;
|
||||
if (isset($data['status_code'])) {
|
||||
if ($data['status_code'] == 1) {
|
||||
$_code = 2;
|
||||
} else if ($data['status_code'] == 99) {
|
||||
$_code = 3;
|
||||
}
|
||||
}
|
||||
|
||||
if ($_code) {
|
||||
$order_id = isset($post['order_id']) ? (int)$post['order_id'] : 0;
|
||||
if (!$order_id) {
|
||||
$car = $AcTruckCars->findOne($id);
|
||||
$order_id = $car->order_id;
|
||||
}
|
||||
$AcOrder = new AcOrder();
|
||||
$order = $AcOrder->findOne($order_id);
|
||||
$order->update_at = $_time;
|
||||
|
||||
$order->status_code = $_code;
|
||||
$order->save();
|
||||
}
|
||||
|
||||
\Yii::$app->getSession()->setFlash('success', '信息保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '信息保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
}
|
||||
|
||||
//删除板车
|
||||
public function actionDelete()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
|
||||
$data = $return = [];
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
|
||||
$model = new AcTruckCars();
|
||||
$car = $model->findOne($id);
|
||||
if (!$car) {
|
||||
$return['msg'] = '数据不存在,删除失败';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($car->pid != $pid) {
|
||||
$return['msg'] = '非本平台数据,不允许操作';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($car->deleted != 0) {
|
||||
$return['msg'] = '数据已被删除过,操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
foreach ($data as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
|
||||
$model->id = $id;
|
||||
$res = $model->updateAll($data, ['id' => $id]);
|
||||
|
||||
|
||||
$return['url'] = Url::toRoute('truckcar/list');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '上板记录删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '上板记录删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
|
||||
$data = $return = [];
|
||||
$_time = time();
|
||||
$data['update_at'] = $_time;
|
||||
|
||||
$model = new AcTruckCars();
|
||||
$car = $model->findOne($id);
|
||||
if (!$car) {
|
||||
$return['msg'] = '数据不存在,删除失败';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($car->pid != $pid) {
|
||||
$return['msg'] = '非本平台数据,不允许操作';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($car->deleted != 0) {
|
||||
$return['msg'] = '数据已被删除,操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$online_id = $car->online_id;
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$truckol = $AcTruckOnline->findOne($online_id);
|
||||
$order_id = $car->order_id;
|
||||
$AcOrder = new AcOrder();
|
||||
$order = $AcOrder->findOne($order_id);
|
||||
|
||||
$return['timeout'] = 1; //n秒后自动跳转
|
||||
|
||||
$where = ['id' => $id];
|
||||
switch ($get['do']) {
|
||||
case 'intruck':
|
||||
if ($car->status_code != 0) {
|
||||
$return['msg'] = '当前运单并非待承运状态,操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$data['status_code'] = 1;
|
||||
$data['from_time'] = $_time;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
//增加板车一辆装车统计
|
||||
$truckol->update_at = $_time;
|
||||
$truckol->updateCounters(['cars' => 1]);
|
||||
$truckol->save();
|
||||
//修改对应订单的状态
|
||||
$order->update_at = $_time;
|
||||
$order->status_code = 2;
|
||||
$order->save();
|
||||
$return['msg'] = '客车上板标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'success'];
|
||||
} else {
|
||||
$return['msg'] = '客车上板标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'arrive':
|
||||
if ($car->status_code == 0) {
|
||||
$return['msg'] = '当前任务尚待承运,操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$data['status_code'] = 99;
|
||||
$data['to_time'] = $_time;
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
//修改对应订单的状态
|
||||
$order->update_at = $_time;
|
||||
$order->status_code = 3;
|
||||
$order->save();
|
||||
$return['msg'] = '客车运达标记记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'primary'];
|
||||
} else {
|
||||
$return['msg'] = '客车运达标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'fix':
|
||||
$data['status_code'] = 80;
|
||||
if ($car->status_code != 1) {
|
||||
$return['msg'] = '当前运单并非运输中状态,操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$res = $model->updateAll($data, $where);
|
||||
if ($res) {
|
||||
$return['msg'] = '客车运达标记记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'primary'];
|
||||
} else {
|
||||
$return['msg'] = '客车运达标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
+922
@@ -0,0 +1,922 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:37:46+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:20:12+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcTruck;
|
||||
use addons\models\AcDriver;
|
||||
use addons\models\AcTruckOnline;
|
||||
use addons\models\AcTruckCars;
|
||||
use addons\models\AcStore;
|
||||
use addons\models\AcCar;
|
||||
use addons\models\AcCarBrand;
|
||||
use addons\models\AcCarSeries;
|
||||
use addons\models\AcOrder;
|
||||
use addons\models\AcEmployee;
|
||||
use addons\models\AcGps;
|
||||
use addons\models\AcGpsRoute;
|
||||
|
||||
class TruckolController extends Common
|
||||
{
|
||||
//出车单
|
||||
public function actionIndex()
|
||||
{
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', Yii::$app->session->get('pid')];
|
||||
$where[] = ['>', 'status_code', 0];
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where[] = ['LIKE', 'num_left', $search['title']];
|
||||
}
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$data = $AcTruckOnline->find()->where($where);
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '10']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby('id DESC')->all();
|
||||
$status = Yii::$app->params['TruckOnlineStatus'];
|
||||
|
||||
$stores = [];
|
||||
$AcStore = new AcStore();
|
||||
if ($res) {
|
||||
$store_ids = [];
|
||||
foreach ($res as $r) {
|
||||
$store_ids[$r->from_store] = $r->from_store;
|
||||
$store_ids[$r->end_store] = $r->end_store;
|
||||
}
|
||||
array_unique($store_ids);
|
||||
$_stores = $AcStore->find()->where(['IN', 'id', $store_ids])->all();
|
||||
if ($_stores) {
|
||||
foreach ($_stores as $r) {
|
||||
$stores[$r->id] = $r->toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('index', [
|
||||
'list' => $res,
|
||||
'pager' => $pages,
|
||||
'status' => $status,
|
||||
'stores' => $stores,
|
||||
'search' => $search
|
||||
]);
|
||||
}
|
||||
|
||||
//在线板车列表(标记了发车状态——装车中的)
|
||||
public function actionList()
|
||||
{
|
||||
$AcTruck = new AcTruck();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', Yii::$app->session->get('pid')];
|
||||
$where[] = ['=', 'status_code', 4];
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where[] = ['LIKE', 'num_left', $search['title']];
|
||||
}
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$data = $AcTruck->find()->where($where);
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['TruckStatus'];
|
||||
$AcDriver = new AcDriver();
|
||||
$where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$_drivers = $AcDriver->find()->where($where)->all();
|
||||
$drivers = [];
|
||||
foreach ($_drivers as $s) {
|
||||
$drivers[$s->id] = $s->toArray();
|
||||
}
|
||||
|
||||
return $this->render('list', [
|
||||
'trucks' => $res,
|
||||
'pager' => $pages,
|
||||
'drivers' => $drivers,
|
||||
'status' => $status,
|
||||
'search' => $search
|
||||
]);
|
||||
}
|
||||
|
||||
//选择可装车的板车
|
||||
public function actionSelect()
|
||||
{
|
||||
$AcTruck = new AcTruck();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', Yii::$app->session->get('pid')];
|
||||
$where[] = ['=', 'status_code', 4];
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where[] = ['LIKE', 'num_left', $search['title']];
|
||||
}
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$data = $AcTruck->find()->where($where);
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
$status = Yii::$app->params['TruckStatus'];
|
||||
$AcDriver = new AcDriver();
|
||||
$where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$_drivers = $AcDriver->find()->where($where)->all();
|
||||
$drivers = [];
|
||||
foreach ($_drivers as $s) {
|
||||
$drivers[$s->id] = $s->toArray();
|
||||
}
|
||||
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'truckol';
|
||||
|
||||
return $this->render('select', [
|
||||
'trucks' => $res,
|
||||
'pager' => $pages,
|
||||
'drivers' => $drivers,
|
||||
'status' => $status,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionSelect2()
|
||||
{
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', Yii::$app->session->get('pid')];
|
||||
$where[] = ['>', 'status_code', 0];
|
||||
$post = Yii::$app->request->post();
|
||||
$search = [];
|
||||
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where[] = ['LIKE', 'num_left', $search['title']];
|
||||
}
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$data = $AcTruckOnline->find()->where($where);
|
||||
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '10']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby('id DESC')->all();
|
||||
$status = Yii::$app->params['TruckOnlineStatus'];
|
||||
|
||||
$stores = [];
|
||||
$AcStore = new AcStore();
|
||||
if ($res) {
|
||||
$store_ids = [];
|
||||
foreach ($res as $r) {
|
||||
$store_ids[$r->from_store] = $r->from_store;
|
||||
$store_ids[$r->end_store] = $r->end_store;
|
||||
}
|
||||
array_unique($store_ids);
|
||||
$_stores = $AcStore->find()->where(['IN', 'id', $store_ids])->all();
|
||||
if ($_stores) {
|
||||
foreach ($_stores as $r) {
|
||||
$stores[$r->id] = $r->toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'truckol';
|
||||
|
||||
return $this->render('select2', [
|
||||
'list' => $res,
|
||||
'pager' => $pages,
|
||||
'status' => $status,
|
||||
'stores' => $stores,
|
||||
'search' => $search,
|
||||
'callback' => $callback
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionNew()
|
||||
{
|
||||
$status = Yii::$app->params['TruckOnlineStatus'];
|
||||
$AcTruckOnline = [];
|
||||
$AcTruckOnline['status_code'] = 0;
|
||||
return $this->render('edit', ['status' => $status, 'detail' => $AcTruckOnline]);
|
||||
}
|
||||
|
||||
//编辑板车装车计划资料
|
||||
public function actionEdit()
|
||||
{
|
||||
// $id = Yii::$app->request->get('id'); //装车任务ID
|
||||
$id = 0;
|
||||
$truck_id = Yii::$app->request->get('truck_id'); //板车ID
|
||||
$store_id = $store2_id = 0;
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$AcTruck = new AcTruck();
|
||||
$truckol = [];
|
||||
|
||||
$truck = $AcTruck->findOne($truck_id);
|
||||
if (!$truck) {
|
||||
$post = Yii::$app->request->post();
|
||||
$return = [];
|
||||
$return['msg'] = '关联板车数据获取异常,发车任务编辑失败';
|
||||
$return['errorcode'] = 0;
|
||||
$return['url'] = Url::toRoute(['truck/list', $post]);
|
||||
$return['buttons'] = [
|
||||
['title' => '好的,我知道了', 'class' => 'info', 'url' => $return['url']]
|
||||
];
|
||||
$return['content'] = $return['msg'];
|
||||
$return['class'] = 'warning';
|
||||
Yii::$app->request->setBodyParams($return);
|
||||
return Yii::$app->runAction('index/msg');
|
||||
}
|
||||
if (!$id) {
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$where[] = ['=', 'truck_id', $truck_id];
|
||||
$where[] = ['<', 'status_code', 99];
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$res = $AcTruckOnline->find()->where($where)->orderby('id ASC')->one();
|
||||
if ($res) {
|
||||
$id = $res->id;
|
||||
$store_id = $res->from_store;
|
||||
$store2_id = $res->end_store;
|
||||
$truckol = $res->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
$truckol['truck_id'] = $truck_id;
|
||||
$truckol['truck_title'] = $truck->num_p . $truck->num_area . $truck->num_left;
|
||||
$truckol['truck_num'] = $truckol['truck_title'] ? $truckol['truck_title'] : $truckol['truck_num'];
|
||||
|
||||
$AcStore = new AcStore();
|
||||
$store = $AcStore->findOne($store_id);
|
||||
if ($store) {
|
||||
$truckol['fromstore_title'] = $store->title;
|
||||
}
|
||||
$store2 = $AcStore->findOne($store2_id);
|
||||
if ($store2) {
|
||||
$truckol['endstore_title'] = $store2->title;
|
||||
}
|
||||
|
||||
$AcDriver = new AcDriver();
|
||||
$driver = $AcDriver->find()->where(['id' => $truck->driver_id])->one();
|
||||
$truckol['driver_title'] = $truckol['driver_mobile'] = '';
|
||||
if ($driver) {
|
||||
$truckol['driver_title'] = $driver->name;
|
||||
$truckol['driver_mobile'] = $driver->mobile;
|
||||
}
|
||||
$truckol['driver_name'] = isset($truckol['driver_name']) ? $truckol['driver_name'] : $truckol['driver_title'];
|
||||
$truckol['driver_mobiles'] = isset($truckol['driver_mobiles']) ? $truckol['driver_mobiles'] : $truckol['driver_mobile'];
|
||||
$status = Yii::$app->params['TruckOnlineStatus'];
|
||||
return $this->render('edit', ['status' => $status, 'detail' => $truckol]);
|
||||
}
|
||||
|
||||
//更新板车装车任务资料
|
||||
public function actionModify()
|
||||
{
|
||||
$id = Yii::$app->request->get('id'); //装车任务ID
|
||||
// $truck_id = Yii::$app->request->get('truck_id'); //板车ID
|
||||
$truck_id = 0;
|
||||
$store_id = $store2_id = 0;
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$AcTruck = new AcTruck();
|
||||
$truckol = [];
|
||||
|
||||
$res = $AcTruckOnline->findOne($id);
|
||||
if ($res) {
|
||||
$truck_id = $res->truck_id;
|
||||
$store_id = $res->from_store;
|
||||
$store2_id = $res->end_store;
|
||||
$truckol = $res->toArray();
|
||||
}
|
||||
$truck = $AcTruck->findOne($truck_id);
|
||||
|
||||
if (!$truck) {
|
||||
$post = Yii::$app->request->post();
|
||||
$return = [];
|
||||
$return['msg'] = '关联板车数据获取异常,发车任务编辑失败';
|
||||
$return['errorcode'] = 0;
|
||||
$return['url'] = Url::toRoute(['truck/list', $post]);
|
||||
$return['buttons'] = [
|
||||
['title' => '好的,我知道了', 'class' => 'info', 'url' => $return['url']]
|
||||
];
|
||||
$return['content'] = $return['msg'];
|
||||
$return['class'] = 'warning';
|
||||
Yii::$app->request->setBodyParams($return);
|
||||
return Yii::$app->runAction('index/msg');
|
||||
}
|
||||
|
||||
$truckol['truck_id'] = $truck_id;
|
||||
$truckol['truck_title'] = $truck->num_p . $truck->num_area . $truck->num_left;
|
||||
$truckol['truck_num'] = $truckol['truck_title'] ? $truckol['truck_title'] : $truckol['truck_num'];
|
||||
|
||||
$AcStore = new AcStore();
|
||||
$store = $AcStore->findOne($store_id);
|
||||
if ($store) {
|
||||
$truckol['fromstore_title'] = $store->title;
|
||||
}
|
||||
$store2 = $AcStore->findOne($store2_id);
|
||||
if ($store2) {
|
||||
$truckol['endstore_title'] = $store2->title;
|
||||
}
|
||||
|
||||
$AcDriver = new AcDriver();
|
||||
$driver = $AcDriver->find()->where(['id' => $truck->driver_id])->one();
|
||||
$truckol['driver_title'] = $truckol['driver_mobile'] = '';
|
||||
if ($driver) {
|
||||
$truckol['driver_title'] = $driver->name;
|
||||
$truckol['driver_mobile'] = $driver->mobile;
|
||||
}
|
||||
$truckol['driver_name'] = isset($truckol['driver_name']) ? $truckol['driver_name'] : $truckol['driver_title'];
|
||||
$truckol['driver_mobiles'] = isset($truckol['driver_mobiles']) ? $truckol['driver_mobiles'] : $truckol['driver_mobile'];
|
||||
$status = Yii::$app->params['TruckOnlineStatus'];
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $truckol]);
|
||||
}
|
||||
|
||||
//保存装车基础资料
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['driver_name' => 'driver_name', 'driver_mobiles' => 'driver_mobiles', 'driver_idcard' => 'driver_idcard', 'truck_num' => 'truck_num', 'end_city' => 'end_city', 'from_city' => 'from_city'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
|
||||
$cols = ['truck_id' => 'truck_id', 'from_store' => 'from_store', 'end_store' => 'end_store'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
$key = 'status_code';
|
||||
if (isset($post[$key])) {
|
||||
$data[$key] = (int)$post[$key];
|
||||
}
|
||||
/*板车规则判断
|
||||
*一辆板车只能有一条可用装车任务表单
|
||||
**/
|
||||
$truck_id = $data['truck_id'];
|
||||
if (!$truck_id) {
|
||||
$return['msg'] = '未指定板车信息,保存失败';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$AcTruck = new AcTruck();
|
||||
$truck = $AcTruck->findOne($truck_id);
|
||||
if (!$truck) {
|
||||
$return['msg'] = '未找到指定板车,保存失败';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$where[] = ['=', 'truck_id', $truck_id];
|
||||
$where[] = ['<', 'status_code', 99];
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$truckol = $AcTruckOnline->find()->where($where)->orderby('id ASC')->one();
|
||||
if ($truckol) {
|
||||
if ($id != $truckol->id) {
|
||||
$return['msg'] = '该板车已有未完成的托运任务,不允许重复指派';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
$key = 'remark';
|
||||
$data[$key] = isset($post[$key]) ? htmlspecialchars(trim($post[$key])) : '';
|
||||
|
||||
$_time = time();
|
||||
$key = 'from_date';
|
||||
$data[$key] = isset($post[$key]) ? strtotime($post[$key]) : $_time;
|
||||
$key = 'end_date';
|
||||
if (isset($post[$key])) {
|
||||
$data[$key] = strtotime($post[$key]);
|
||||
}
|
||||
|
||||
if (!$id) {
|
||||
$data['create_at'] = $_time;
|
||||
}
|
||||
$data['update_at'] = $_time;;
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//保存板车资料
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcTruckOnline->$key = $val;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$res = $AcTruckOnline->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcTruckOnline->save();
|
||||
$id = $AcTruckOnline->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '信息保存成功!');
|
||||
return $this->redirect(['modify', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '信息保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
}
|
||||
|
||||
//随车车辆管理
|
||||
public function actionCars()
|
||||
{
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$id = Yii::$app->request->get('id'); //装车任务ID
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$truckol = [];
|
||||
$res = $AcTruckOnline->findOne($id);
|
||||
if (!$res) {
|
||||
$post = Yii::$app->request->post();
|
||||
$return = [];
|
||||
$return['msg'] = '发车任务记录获取失败,请重新获取';
|
||||
$return['errorcode'] = 0;
|
||||
$return['url'] = Url::toRoute(['truckol/list', $post]);
|
||||
$return['buttons'] = [
|
||||
['title' => '好的,我知道了', 'class' => 'info', 'url' => $return['url']]
|
||||
];
|
||||
$return['content'] = $return['msg'];
|
||||
$return['class'] = 'warning';
|
||||
Yii::$app->request->setBodyParams($return);
|
||||
return Yii::$app->runAction('index/msg');
|
||||
}
|
||||
|
||||
$truck_id = $res->truck_id;
|
||||
$store_id = $res->from_store;
|
||||
$store2_id = $res->end_store;
|
||||
$truckol = $res->toArray();
|
||||
|
||||
$AcTruck = new AcTruck();
|
||||
$truck = $AcTruck->findOne($truck_id);
|
||||
|
||||
$AcStore = new AcStore();
|
||||
$store = $AcStore->findOne($store_id);
|
||||
if ($store) {
|
||||
$truckol['fromstore_title'] = $store->title;
|
||||
}
|
||||
$store2 = $AcStore->findOne($store2_id);
|
||||
if ($store2) {
|
||||
$truckol['endstore_title'] = $store2->title;
|
||||
}
|
||||
|
||||
$online_id = $id;
|
||||
$AcTruckCars = new AcTruckCars();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$where[] = ['=', 'online_id', $online_id];
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$truckcars = $AcTruckCars->find()->where($where)->orderby('update_at DESC')->all();
|
||||
$carids = $orderids = [];
|
||||
if ($truckcars) {
|
||||
foreach ($truckcars as $t) {
|
||||
$carids[] = $t->car_id;
|
||||
$orderids[] = $t->order_id;
|
||||
}
|
||||
}
|
||||
|
||||
$AcCar = new AcCar();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$where[] = ['IN', 'id', $carids];
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$cars = $AcCar->find()->where($where)->indexby('id')->all();
|
||||
|
||||
$status = Yii::$app->params['TruckCarsStatus'];
|
||||
$truckOnLineStatus = Yii::$app->params['TruckOnlineStatus'];
|
||||
|
||||
return $this->render('cars', [
|
||||
'status' => $status,
|
||||
'truckOnLineStatus' => $truckOnLineStatus,
|
||||
'truckol' => $truckol,
|
||||
'cars' => $cars,
|
||||
'truckcars' => $truckcars
|
||||
]);
|
||||
}
|
||||
|
||||
//保存装车随车资料
|
||||
public function actionCarssave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$online_id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['car_id', 'order_id'];
|
||||
foreach ($cols as $key) {
|
||||
if (!isset($post[$key])) {
|
||||
$return['msg'] = '未传入的运单或车辆信息,保存失败';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
$car_ids = $post['car_id'];
|
||||
if (!is_array($car_ids)) {
|
||||
$return['msg'] = '传入的车辆数据不正确,保存失败';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$order_ids = $post['order_id'];
|
||||
if (!is_array($order_ids)) {
|
||||
$return['msg'] = '传入的运单数据不正确,保存失败';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if (count($car_ids) != count($order_ids)) {
|
||||
$return['msg'] = '传入的车辆数据与运单数据不匹配,保存失败';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
/*筛除已在运输中的运单及车辆数据 TBD*/
|
||||
|
||||
$AcTruckCars = new AcTruckCars();
|
||||
$cars = [];
|
||||
$_time = time();
|
||||
foreach ($car_ids as $k => $car_id) {
|
||||
$car = [];
|
||||
$car['pid'] = $pid;
|
||||
$car['online_id'] = $online_id;
|
||||
$car['car_id'] = $car_id;
|
||||
$car['order_id'] = $order_ids[$k];
|
||||
$car['create_at'] = $_time;
|
||||
$car['update_at'] = $_time;
|
||||
$cars[] = $car;
|
||||
$model = clone $AcTruckCars;
|
||||
foreach ($car as $key => $val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
$model->save();
|
||||
}
|
||||
|
||||
$return['msg'] = '操作完成,请刷新页面并检查数据';
|
||||
$return['errorcode'] = 200;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
//板车出发
|
||||
public function actionChufa()
|
||||
{
|
||||
$id = Yii::$app->request->get('id'); //装车任务ID
|
||||
$return = [];
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$truckol = [];
|
||||
$res = $AcTruckOnline->findOne($id);
|
||||
if (!$res) {
|
||||
$post = Yii::$app->request->post();
|
||||
$return['msg'] = '发车任务记录获取失败,请重新获取';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($res->status_code != 0) {
|
||||
$return['msg'] = '关联出车任务非“待出发”状态,操作失败';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$truck_id = $res->truck_id;
|
||||
$truckol = $res->toArray();
|
||||
|
||||
$AcTruck = new AcTruck();
|
||||
$truck = $AcTruck->findOne($truck_id);
|
||||
if (!$truck) {
|
||||
$return['msg'] = '关联板车数据获取异常,操作失败';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
/*更新数据*/
|
||||
$_time = time();
|
||||
$data = [];
|
||||
$data['update_at'] = $_time;
|
||||
$data['status_code'] = 1;
|
||||
$res = $AcTruckOnline->updateAll($data, ['id' => $id]);
|
||||
|
||||
$data = [];
|
||||
$data['update_at'] = $_time;
|
||||
$data['status_code'] = 5;
|
||||
$AcTruck->updateAll($data, ['id' => $truck_id]);
|
||||
|
||||
if ($res) {
|
||||
$return['msg'] = '出车任务出发标记操作成功';
|
||||
$return['errorcode'] = 200;
|
||||
} else {
|
||||
$return['msg'] = '出发标记操作失败';
|
||||
$return['errorcode'] = 100;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
//板车到达
|
||||
public function actionArrive()
|
||||
{
|
||||
$id = Yii::$app->request->get('id'); //装车任务ID
|
||||
$return = [];
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$truckol = [];
|
||||
$res = $AcTruckOnline->findOne($id);
|
||||
if (!$res) {
|
||||
$post = Yii::$app->request->post();
|
||||
$return['msg'] = '发车任务记录获取失败,请重新获取';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($res->status_code != 1) {
|
||||
$return['msg'] = '关联出车任务非“进行中”(在途)状态,操作失败';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
$truck_id = $res->truck_id;
|
||||
$truckol = $res->toArray();
|
||||
|
||||
$AcTruck = new AcTruck();
|
||||
$truck = $AcTruck->findOne($truck_id);
|
||||
if (!$truck) {
|
||||
$return['msg'] = '关联板车数据获取异常,操作失败';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
/*更新数据*/
|
||||
$_time = time();
|
||||
$data = [];
|
||||
$data['update_at'] = $_time;
|
||||
$data['status_code'] = 99;
|
||||
$res = $AcTruckOnline->updateAll($data, ['id' => $id]);
|
||||
|
||||
$data = [];
|
||||
$data['update_at'] = $_time;
|
||||
$data['status_code'] = 0;
|
||||
$AcTruck->updateAll($data, ['id' => $truck_id]);
|
||||
|
||||
if ($res) {
|
||||
$return['msg'] = '出车任务运达标记操作成功';
|
||||
$return['errorcode'] = 200;
|
||||
} else {
|
||||
$return['msg'] = '运达标记操作失败';
|
||||
$return['errorcode'] = 100;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
|
||||
//删除板车装车任务
|
||||
public function actionDelete()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$data = $where = [];
|
||||
$where['pid'] = Yii::$app->session->get('pid');
|
||||
$where['id'] = $id;
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = 1;
|
||||
|
||||
$model = new AcTruck();
|
||||
$res = $model->updateAll($data, $where);
|
||||
|
||||
$return = [];
|
||||
$return['url'] = Url::toRoute('truckol/index');
|
||||
$return['timeout'] = 3; //3秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '板车装车任务删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '板车装车任务删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
//打印出车单
|
||||
public function actionPrint()
|
||||
{
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$id = Yii::$app->request->get('id'); //装车任务ID
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$truckol = [];
|
||||
$res = $AcTruckOnline->findOne($id);
|
||||
if (!$res) {
|
||||
$post = Yii::$app->request->post();
|
||||
$return = [];
|
||||
$return['msg'] = '发车任务记录获取失败,请重新获取';
|
||||
$return['errorcode'] = 0;
|
||||
$return['url'] = Url::toRoute(['truckol/list', $post]);
|
||||
$return['buttons'] = [
|
||||
['title' => '好的,我知道了', 'class' => 'info', 'url' => $return['url']]
|
||||
];
|
||||
$return['content'] = $return['msg'];
|
||||
$return['class'] = 'warning';
|
||||
Yii::$app->request->setBodyParams($return);
|
||||
return Yii::$app->runAction('index/msg');
|
||||
}
|
||||
|
||||
$truck_id = $res->truck_id;
|
||||
$store_id = $res->from_store;
|
||||
$store2_id = $res->end_store;
|
||||
$truckol = $res->toArray();
|
||||
$AcTruck = new AcTruck();
|
||||
$truck = $AcTruck->findOne($truck_id);
|
||||
|
||||
$AcStore = new AcStore();
|
||||
$store = $AcStore->findOne($store_id);
|
||||
if ($store) {
|
||||
$truckol['fromstore_title'] = $store->title;
|
||||
}
|
||||
$store2 = $AcStore->findOne($store2_id);
|
||||
if ($store2) {
|
||||
$truckol['endstore_title'] = $store2->title;
|
||||
}
|
||||
|
||||
$online_id = $id;
|
||||
$AcTruckCars = new AcTruckCars();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$where[] = ['=', 'online_id', $online_id];
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$where[] = ['>', 'status_code', 0];
|
||||
$truckcars = $AcTruckCars->find()->where($where)->orderby('update_at DESC')->all();
|
||||
$carids = $orderids = [];
|
||||
if ($truckcars) {
|
||||
foreach ($truckcars as $t) {
|
||||
$carids[] = $t->car_id;
|
||||
$orderids[] = $t->order_id;
|
||||
}
|
||||
}
|
||||
|
||||
$counts = [];
|
||||
|
||||
$AcCar = new AcCar();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$where[] = ['IN', 'id', $carids];
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$cars = $AcCar->find()->where($where)->indexby('id')->all();
|
||||
|
||||
$AcOrder = new AcOrder();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$where[] = ['IN', 'id', $orderids];
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$orders = $AcOrder->find()->where($where)->indexby('id')->all();
|
||||
|
||||
$employee_ids = [];
|
||||
$count['fee_total'] = $count['pay_receive'] = 0;
|
||||
foreach ($orders as $v) {
|
||||
$employee_ids[] = $v->employee_id;
|
||||
$count['fee_total'] += $v->fee_total;
|
||||
$count['pay_receive'] += $v->pay_receive;
|
||||
}
|
||||
$AcEmployee = new AcEmployee();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$where[] = ['IN', 'id', $employee_ids];
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$employees = $AcEmployee->find()->where($where)->indexby('id')->all();
|
||||
|
||||
$count['cars'] = count($truckcars);
|
||||
|
||||
$status = Yii::$app->params['TruckCarsStatus'];
|
||||
$truckOnLineStatus = Yii::$app->params['TruckOnlineStatus'];
|
||||
return $this->render('print', [
|
||||
'status' => $status,
|
||||
'truckOnLineStatus' => $truckOnLineStatus,
|
||||
'truckol' => $truckol,
|
||||
'cars' => $cars,
|
||||
'orders' => $orders,
|
||||
'employees' => $employees,
|
||||
'truckcars' => $truckcars,
|
||||
'count' => $count
|
||||
]);
|
||||
}
|
||||
|
||||
//浏览详情
|
||||
public function actionDetail()
|
||||
{
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$id = Yii::$app->request->get('id'); //装车任务ID
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$truckol = [];
|
||||
$res = $AcTruckOnline->findOne($id);
|
||||
if (!$res) {
|
||||
$post = Yii::$app->request->post();
|
||||
$return = [];
|
||||
$return['msg'] = '发车任务记录获取失败,请重新获取';
|
||||
$return['errorcode'] = 0;
|
||||
$return['url'] = Url::toRoute(['truckol/list', $post]);
|
||||
$return['buttons'] = [
|
||||
['title' => '好的,我知道了', 'class' => 'info', 'url' => $return['url']]
|
||||
];
|
||||
$return['content'] = $return['msg'];
|
||||
$return['class'] = 'warning';
|
||||
Yii::$app->request->setBodyParams($return);
|
||||
return Yii::$app->runAction('index/msg');
|
||||
}
|
||||
|
||||
$truck_id = $res->truck_id;
|
||||
$store_id = $res->from_store;
|
||||
$store2_id = $res->end_store;
|
||||
$truckol = $res->toArray();
|
||||
$AcTruck = new AcTruck();
|
||||
$truck = $AcTruck->findOne($truck_id);
|
||||
|
||||
$AcStore = new AcStore();
|
||||
$store = $AcStore->findOne($store_id);
|
||||
if ($store) {
|
||||
$truckol['fromstore_title'] = $store->title;
|
||||
}
|
||||
$store2 = $AcStore->findOne($store2_id);
|
||||
if ($store2) {
|
||||
$truckol['endstore_title'] = $store2->title;
|
||||
}
|
||||
|
||||
$online_id = $id;
|
||||
$AcTruckCars = new AcTruckCars();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$where[] = ['=', 'online_id', $online_id];
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$where[] = ['>', 'status_code', 1];
|
||||
$truckcars = $AcTruckCars->find()->where($where)->orderby('update_at DESC')->all();
|
||||
$carids = $orderids = [];
|
||||
if ($truckcars) {
|
||||
foreach ($truckcars as $t) {
|
||||
$carids[] = $t->car_id;
|
||||
$orderids[] = $t->order_id;
|
||||
}
|
||||
}
|
||||
|
||||
$counts = [];
|
||||
|
||||
$AcCar = new AcCar();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$where[] = ['IN', 'id', $carids];
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$cars = $AcCar->find()->where($where)->indexby('id')->all();
|
||||
|
||||
$AcOrder = new AcOrder();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$where[] = ['IN', 'id', $orderids];
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$orders = $AcOrder->find()->where($where)->indexby('id')->all();
|
||||
|
||||
$employee_ids = [];
|
||||
$count['fee_total'] = $count['pay_receive'] = 0;
|
||||
foreach ($orders as $v) {
|
||||
$employee_ids[] = $v->employee_id;
|
||||
$count['fee_total'] += $v->fee_total;
|
||||
$count['pay_receive'] += $v->pay_receive;
|
||||
}
|
||||
$AcEmployee = new AcEmployee();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$where[] = ['IN', 'id', $employee_ids];
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$employees = $AcEmployee->find()->where($where)->indexby('id')->all();
|
||||
|
||||
$count['cars'] = count($truckcars);
|
||||
|
||||
$status = Yii::$app->params['TruckCarsStatus'];
|
||||
$truckOnLineStatus = Yii::$app->params['TruckOnlineStatus'];
|
||||
return $this->render('detail', [
|
||||
'status' => $status,
|
||||
'truckOnLineStatus' => $truckOnLineStatus,
|
||||
'truckol' => $truckol,
|
||||
'cars' => $cars,
|
||||
'orders' => $orders,
|
||||
'employees' => $employees,
|
||||
'truckcars' => $truckcars,
|
||||
'count' => $count
|
||||
]);
|
||||
}
|
||||
}
|
||||
+378
@@ -0,0 +1,378 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:37:26+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:20:16+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcTruck;
|
||||
use addons\models\AcDriver;
|
||||
use addons\models\AcTruckOnline;
|
||||
use addons\models\AcTruckCars;
|
||||
use addons\models\AcStore;
|
||||
use addons\models\AcCar;
|
||||
use addons\models\AcCarBrand;
|
||||
use addons\models\AcCarSeries;
|
||||
use addons\models\AcOrder;
|
||||
use addons\models\AcGps;
|
||||
use addons\models\AcGpsRoute;
|
||||
use addons\models\AcTruckRoute;
|
||||
|
||||
class TruckrouteController extends Common
|
||||
{
|
||||
//替代常规的_construct 析构函数;其他方法调用前执行
|
||||
public function init()
|
||||
{
|
||||
$session = Yii::$app->session;
|
||||
if (isset($_GET['pid']) && (int)$_GET['pid'] > 0) {
|
||||
$session->set('pid', (int)$_GET['pid']);
|
||||
}
|
||||
$pid = $session->get('pid');
|
||||
if (!$pid) {
|
||||
return Yii::$app->response->redirect(['index/index']);
|
||||
}
|
||||
$online_id = Yii::$app->request->get('online_id'); //发车任务ID
|
||||
if (!$online_id) {
|
||||
$online_id = $session->get('online_id');
|
||||
} else {
|
||||
$session->set('online_id', $online_id);
|
||||
}
|
||||
if (!$online_id) {
|
||||
$post = Yii::$app->request->post();
|
||||
$return = [];
|
||||
$return['msg'] = '请先选择好要查看的出车大板';
|
||||
$return['errorcode'] = 0;
|
||||
$return['url'] = Url::toRoute(['truckol/index', $post]);
|
||||
$return['buttons'] = [
|
||||
['title' => '好的,我知道了', 'class' => 'info', 'url' => $return['url']]
|
||||
];
|
||||
$return['content'] = $return['msg'];
|
||||
$return['class'] = 'warning';
|
||||
Yii::$app->request->setBodyParams($return);
|
||||
return Yii::$app->runAction('index/msg');
|
||||
}
|
||||
$truckol = $session->get('truckOnline');
|
||||
$AcTruckOnline = new AcTruckOnline();
|
||||
$res = TRUE;
|
||||
if (!$truckol) {
|
||||
$res = $AcTruckOnline->findOne($online_id);
|
||||
if ($res) {
|
||||
$truck_id = $res->truck_id;
|
||||
$store_id = $res->from_store;
|
||||
$store2_id = $res->end_store;
|
||||
$truckol = $res->toArray();
|
||||
|
||||
$AcStore = new AcStore();
|
||||
$store = $AcStore->findOne($store_id);
|
||||
if ($store) {
|
||||
$truckol['fromstore_title'] = $store->title;
|
||||
}
|
||||
$store2 = $AcStore->findOne($store2_id);
|
||||
if ($store2) {
|
||||
$truckol['endstore_title'] = $store2->title;
|
||||
}
|
||||
$session->set('truckOnline', $truckol);
|
||||
}
|
||||
}
|
||||
if ($online_id != $truckol['id']) {
|
||||
$res = $AcTruckOnline->findOne($online_id);
|
||||
if ($res) {
|
||||
$truck_id = $res->truck_id;
|
||||
$store_id = $res->from_store;
|
||||
$store2_id = $res->end_store;
|
||||
$truckol = $res->toArray();
|
||||
|
||||
$AcStore = new AcStore();
|
||||
$store = $AcStore->findOne($store_id);
|
||||
if ($store) {
|
||||
$truckol['fromstore_title'] = $store->title;
|
||||
}
|
||||
$store2 = $AcStore->findOne($store2_id);
|
||||
if ($store2) {
|
||||
$truckol['endstore_title'] = $store2->title;
|
||||
}
|
||||
$session->set('truckOnline', $truckol);
|
||||
}
|
||||
}
|
||||
if (!$res) {
|
||||
$post = Yii::$app->request->post();
|
||||
$return = [];
|
||||
$return['msg'] = '请先选择好要查看的出车大板';
|
||||
$return['errorcode'] = 0;
|
||||
$return['url'] = Url::toRoute(['truckol/index', $post]);
|
||||
$return['buttons'] = [
|
||||
['title' => '好的,我知道了', 'class' => 'info', 'url' => $return['url']]
|
||||
];
|
||||
$return['content'] = $return['msg'];
|
||||
$return['class'] = 'warning';
|
||||
Yii::$app->request->setBodyParams($return);
|
||||
return Yii::$app->runAction('index/msg');
|
||||
}
|
||||
}
|
||||
|
||||
//主界面
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('../layouts/dev', []);
|
||||
}
|
||||
|
||||
//所有板车位置记录列表
|
||||
public function actionList()
|
||||
{
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$post = Yii::$app->request->post();
|
||||
$online_id = Yii::$app->session->get('online_id'); //发车任务ID
|
||||
$truckol = Yii::$app->session->get('truckOnline'); //发车任务
|
||||
|
||||
$AcTruckRoute = new AcTruckRoute();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', Yii::$app->session->get('pid')];
|
||||
if ($online_id) {
|
||||
$where[] = ['=', 'online_id', $online_id];
|
||||
}
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$data = $AcTruckRoute->find()->where($where)->orderby('orderby ASC,id DESC');
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '20']);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
||||
|
||||
$truck_ids = [];
|
||||
foreach ($res as $r) {
|
||||
$truck_ids[] = $r->truck_id;
|
||||
}
|
||||
|
||||
$AcTruck = new AcTruck();
|
||||
$where = [];
|
||||
$where[] = 'and';
|
||||
$where[] = ['=', 'pid', $pid];
|
||||
$where[] = ['IN', 'id', $truck_ids];
|
||||
$where[] = ['=', 'deleted', 0];
|
||||
$trucks = $AcTruck->find()->where($where)->indexby('id')->all();
|
||||
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
|
||||
return $this->render('list', [
|
||||
'list' => $res,
|
||||
'pager' => $pages,
|
||||
'status' => $status,
|
||||
'trucks' => $trucks,
|
||||
'online_id' => $online_id,
|
||||
'truckol' => $truckol
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionNew()
|
||||
{
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$AcTruckRoute = [];
|
||||
$AcTruckRoute['status_code'] = 0;
|
||||
$online_id = Yii::$app->session->get('online_id'); //发车任务ID
|
||||
$truckol = Yii::$app->session->get('truckOnline'); //发车任务
|
||||
|
||||
$AcTruckRoute['truck_id'] = $truckol['truck_id'];
|
||||
$AcTruckRoute['truck_num'] = $truckol['truck_num'];
|
||||
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $AcTruckRoute, 'online_id' => $online_id, 'truckol' => $truckol]);
|
||||
}
|
||||
|
||||
//编辑板车位置信息
|
||||
public function actionEdit()
|
||||
{
|
||||
$id = Yii::$app->request->get('id'); //记录ID
|
||||
$online_id = Yii::$app->session->get('online_id'); //发车任务ID
|
||||
$truckol = Yii::$app->session->get('truckOnline'); //发车任务
|
||||
|
||||
$AcTruckRoute = new AcTruckRoute();
|
||||
$route = $AcTruckRoute->findOne($id);
|
||||
if (!$route) {
|
||||
$post = Yii::$app->request->post();
|
||||
$return = [];
|
||||
$return['msg'] = '位置记录数据获取异常,请重新选择获取';
|
||||
$return['errorcode'] = 0;
|
||||
$return['url'] = '';
|
||||
$return['buttons'] = [
|
||||
['title' => '好的,我知道了', 'class' => 'info', 'url' => $return['url']]
|
||||
];
|
||||
$return['content'] = $return['msg'];
|
||||
$return['class'] = 'warning';
|
||||
Yii::$app->request->setBodyParams($return);
|
||||
return Yii::$app->runAction('index/msg');
|
||||
}
|
||||
$route = $route->toArray();
|
||||
$route['truck_id'] = $truckol['truck_id'];
|
||||
$route['online_id'] = $online_id;
|
||||
$route['truck_num'] = $truckol['truck_num'];
|
||||
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
return $this->render('modify', ['status' => $status, 'detail' => $route, 'online_id' => $online_id, 'truckol' => $truckol]);
|
||||
}
|
||||
|
||||
//保存位置记录信息
|
||||
public function actionSave()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$post['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$online_id = Yii::$app->session->get('online_id');
|
||||
$truckol = Yii::$app->session->get('truckOnline'); //发车任务
|
||||
$data = [];
|
||||
$data['truck_id'] = $truckol['truck_id'];
|
||||
$data['online_id'] = $online_id;
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$cols = ['longt' => 'lng', 'lat' => 'lat', 'addr' => 'addr'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
||||
}
|
||||
|
||||
$cols = ['orderby' => 'orderby', 'status_code' => 'status_code'];
|
||||
foreach ($cols as $col => $key) {
|
||||
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
||||
}
|
||||
|
||||
$_time = time();
|
||||
$key = 'update_at';
|
||||
$data[$key] = isset($post[$key]) ? strtotime($post[$key]) : $_time;
|
||||
|
||||
if (!$id) {
|
||||
$data['create_at'] = $_time;
|
||||
}
|
||||
$data['pid'] = $pid;
|
||||
|
||||
//保存位置资料
|
||||
$AcTruckRoute = new AcTruckRoute();
|
||||
foreach ($data as $key => $val) {
|
||||
$AcTruckRoute->$key = $val;
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$res = $AcTruckRoute->updateAll($data, ['id' => $id]);
|
||||
} else {
|
||||
$res = $AcTruckRoute->save();
|
||||
$id = $AcTruckRoute->attributes['id']; //获取插入后id
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
\Yii::$app->getSession()->setFlash('success', '信息保存成功!');
|
||||
return $this->redirect(['edit', 'id' => $id]);
|
||||
} else {
|
||||
\Yii::$app->getSession()->setFlash('warning', '信息保存失败!');
|
||||
return $this->goBack();
|
||||
}
|
||||
}
|
||||
|
||||
//删除记录
|
||||
public function actionDelete()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$return = [];
|
||||
|
||||
$model = new AcTruckRoute();
|
||||
$route = $model->findOne($id);
|
||||
if (!$route) {
|
||||
$return['msg'] = '数据不存在,删除失败';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($route->pid != $pid) {
|
||||
$return['msg'] = '非本平台数据,不允许操作';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($route->deleted != 0) {
|
||||
$return['msg'] = '数据已被删除过,操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
$route->deleted = 1;
|
||||
$res = $route->save();
|
||||
|
||||
$return['url'] = '';
|
||||
$return['timeout'] = 1; //n秒后自动跳转
|
||||
$return['status'] = 0;
|
||||
if ($res) {
|
||||
$return['msg'] = '位置记录删除成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = $id;
|
||||
} else {
|
||||
$return['msg'] = '位置记录删除失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$get = Yii::$app->request->get();
|
||||
$post = Yii::$app->request->post();
|
||||
$id = (int)$get['id'];
|
||||
$pid = Yii::$app->session->get('pid');
|
||||
$return = [];
|
||||
|
||||
$model = new AcTruckRoute();
|
||||
$route = $model->findOne($id);
|
||||
if (!$route) {
|
||||
$return['msg'] = '数据不存在,删除失败';
|
||||
$return['errorcode'] = 404;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
if ($route->pid != $pid) {
|
||||
$return['msg'] = '非本平台数据,不允许操作';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
if ($route->deleted != 0) {
|
||||
$return['msg'] = '数据已被删除,操作无效';
|
||||
$return['errorcode'] = 400;
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
$return['timeout'] = 1; //n秒后自动跳转
|
||||
$res = TRUE;
|
||||
switch ($get['do']) {
|
||||
case 'show':
|
||||
if ($route->status_code != 1) {
|
||||
$route->status_code = 1;
|
||||
$res = $route->save();
|
||||
}
|
||||
if ($res) {
|
||||
$return['msg'] = '记录显示标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'success'];
|
||||
} else {
|
||||
$return['msg'] = '客车上板标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
case 'hide':
|
||||
if ($route->status_code != 0) {
|
||||
$route->status_code = 0;
|
||||
$res = $route->save();
|
||||
}
|
||||
if ($res) {
|
||||
$return['msg'] = '记录隐藏标记成功';
|
||||
$return['errorcode'] = 200;
|
||||
$return['data'] = ['css' => 'success'];
|
||||
} else {
|
||||
$return['msg'] = '客车上板标记失败';
|
||||
$return['errorcode'] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
+379
@@ -0,0 +1,379 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-10T01:13:34+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:20:25+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\web\UploadedFile;
|
||||
use common\models\CAttachment;
|
||||
use backend\controllers\Common;
|
||||
|
||||
class UploadController extends Common
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
$apis = [
|
||||
'image' => '上传图片(单传)',
|
||||
];
|
||||
$this->result('您正使用CMTS系统文件上传接口!', $apis, 200);
|
||||
}
|
||||
|
||||
public function actionImage()
|
||||
{
|
||||
$post = $this->postdata;
|
||||
$model = new CAttachment();
|
||||
$file = UploadedFile::getInstanceByName('file');
|
||||
//{error: 0
|
||||
// name: "e8.png"
|
||||
// size: 5362
|
||||
// tempName: "/Applications/XAMPP/xamppfiles/temp/phpG8vgnV"
|
||||
// type: "image/png"}
|
||||
// 构建目录
|
||||
$attachDir = Yii::getAlias('@upload'); //附件所在目录
|
||||
|
||||
$targetDir = "/pics"; //开始构建目标转存目录
|
||||
if (!file_exists($attachDir . $targetDir)) {
|
||||
@mkdir($attachDir . $targetDir);
|
||||
}
|
||||
|
||||
$siteId = $this->site_id;
|
||||
$targetDir .= '/' . $siteId;
|
||||
if (!file_exists($attachDir . $targetDir)) {
|
||||
@mkdir($attachDir . $targetDir);
|
||||
}
|
||||
|
||||
$pid = $this->pid;
|
||||
$targetDir .= '/' . $pid;
|
||||
if (!file_exists($attachDir . $targetDir)) {
|
||||
@mkdir($attachDir . $targetDir);
|
||||
}
|
||||
|
||||
$timeDir = date('Ym');
|
||||
$targetDir .= "/" . $timeDir;
|
||||
if (!file_exists($attachDir . $targetDir)) {
|
||||
@mkdir($attachDir . $targetDir);
|
||||
}
|
||||
|
||||
//处理请求的文件信息
|
||||
$title = isset($file->name) ? $file->name : md5(TIMESTAMP . rand(1, 99)) . '.jpg'; //文件原名
|
||||
//取后缀名
|
||||
$_filetype = explode('/', $file->type);
|
||||
$suffix = strtolower($_filetype[1]);
|
||||
//重新命名以便转存
|
||||
$newName = date('dHis', TIMESTAMP) . '_' . md5($title);
|
||||
$newFile = $attachDir . $targetDir . "/" . $newName . "." . $suffix;
|
||||
|
||||
$res = $file->saveAs($newFile, TRUE);
|
||||
|
||||
//文件入库
|
||||
//POST数据处理
|
||||
$member_id = 0;
|
||||
if (isset($post['mid']) && (int)$post['mid'] > 0) {
|
||||
$member_id = (int)$post['mid'];
|
||||
}
|
||||
$options = '';
|
||||
if (isset($post['options'])) {
|
||||
$options = json_encode($options, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT);
|
||||
}
|
||||
$model = new CAttachment();
|
||||
$model->siteid = $siteId;
|
||||
$model->pid = $this->pid;
|
||||
$model->uid = $this->user_id;
|
||||
$model->mid = $member_id;
|
||||
$model->type = 0; //附件类型,0图片1视频2音频3表格4文档5PPT888证书999其他
|
||||
$model->status_code = 1;
|
||||
$model->title = $title;
|
||||
$model->filesize = $file->size;
|
||||
$model->route = $targetDir . "/" . $newName . "." . $suffix;
|
||||
$model->options = $options;
|
||||
$model->update_at = $model->create_at = time();
|
||||
$model->save();
|
||||
$id = $model->attributes['id']; //获取插入后id
|
||||
$this->result('上传成功', ['id' => $id, 'path' => $model->route], 200);
|
||||
}
|
||||
|
||||
public function actionImages()
|
||||
{
|
||||
$post = $this->postdata;
|
||||
$model = new CAttachment();
|
||||
$files = UploadedFile::getInstancesByName('files');
|
||||
// 构建目录
|
||||
$attachDir = Yii::getAlias('@upload'); //附件所在目录
|
||||
|
||||
$targetDir = "/pics"; //开始构建目标转存目录
|
||||
if (!file_exists($attachDir . $targetDir)) {
|
||||
@mkdir($attachDir . $targetDir);
|
||||
}
|
||||
|
||||
$siteId = $this->site_id;
|
||||
$targetDir .= '/' . $siteId;
|
||||
if (!file_exists($attachDir . $targetDir)) {
|
||||
@mkdir($attachDir . $targetDir);
|
||||
}
|
||||
|
||||
$pid = $this->pid;
|
||||
$targetDir .= '/' . $pid;
|
||||
if (!file_exists($attachDir . $targetDir)) {
|
||||
@mkdir($attachDir . $targetDir);
|
||||
}
|
||||
|
||||
$timeDir = date('Ym');
|
||||
$targetDir .= "/" . $timeDir;
|
||||
if (!file_exists($attachDir . $targetDir)) {
|
||||
@mkdir($attachDir . $targetDir);
|
||||
}
|
||||
|
||||
//处理请求的文件信息
|
||||
//POST数据处理
|
||||
$member_id = 0;
|
||||
if (isset($post['mid']) && (int)$post['mid'] > 0) {
|
||||
$member_id = (int)$post['mid'];
|
||||
}
|
||||
$options = '';
|
||||
if (isset($post['options'])) {
|
||||
$options = json_encode($options, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT);
|
||||
}
|
||||
|
||||
$attachModel = new CAttachment();
|
||||
$ids = $paths = $datas = [];
|
||||
foreach ($files as $file) {
|
||||
$tkey = microtime();
|
||||
$title = isset($file->name) ? $file->name : md5($tkey . rand(1, 99)) . '.jpg'; //文件原名
|
||||
//取后缀名
|
||||
$_filetype = explode('/', $file->type);
|
||||
$suffix = strtolower($_filetype[1]);
|
||||
//重新命名以便转存
|
||||
$newName = date('dHis', TIMESTAMP) . '_' . md5($title);
|
||||
$newFile = $attachDir . $targetDir . "/" . $newName . "." . $suffix;
|
||||
|
||||
$res = $file->saveAs($newFile, TRUE);
|
||||
|
||||
//文件入库
|
||||
$model = clone $attachModel;
|
||||
$model->siteid = $siteId;
|
||||
$model->pid = $this->pid;
|
||||
$model->uid = $this->user_id;
|
||||
$model->mid = $member_id;
|
||||
$model->type = 0; //附件类型,0图片1视频2音频3表格4文档5PPT888证书999其他
|
||||
$model->status_code = 1;
|
||||
$model->title = $title;
|
||||
$model->filesize = $file->size;
|
||||
$model->route = $targetDir . "/" . $newName . "." . $suffix;
|
||||
$model->options = $options;
|
||||
$model->update_at = $model->create_at = time();
|
||||
$model->save();
|
||||
$id = $model->attributes['id']; //获取插入后id
|
||||
$ids[$id] = $id;
|
||||
$paths[$id] = $model->route;
|
||||
}
|
||||
|
||||
$this->result('上传成功', ['ids' => $ids, 'paths' => $paths], 200);
|
||||
}
|
||||
|
||||
public function save_image()
|
||||
{
|
||||
$post = Yii::$app->request->post();
|
||||
$model = new CAttachment();
|
||||
$files = UploadedFile::getInstanceByName('files');
|
||||
//{error: 0
|
||||
// name: "e8.png"
|
||||
// size: 5362
|
||||
// tempName: "/Applications/XAMPP/xamppfiles/temp/phpG8vgnV"
|
||||
// type: "image/png"}
|
||||
// 构建目录
|
||||
$attachDir = Yii::getAlias('@upload'); //附件所在目录
|
||||
|
||||
$targetDir = "/pics"; //开始构建目标转存目录
|
||||
if (!file_exists($attachDir . $targetDir)) {
|
||||
@mkdir($attachDir . $targetDir);
|
||||
}
|
||||
|
||||
$siteId = $this->site_id;
|
||||
$targetDir .= '/' . $siteId;
|
||||
if (!file_exists($attachDir . $targetDir)) {
|
||||
@mkdir($attachDir . $targetDir);
|
||||
}
|
||||
|
||||
$pid = $this->pid;
|
||||
$targetDir .= '/' . $pid;
|
||||
if (!file_exists($attachDir . $targetDir)) {
|
||||
@mkdir($attachDir . $targetDir);
|
||||
}
|
||||
|
||||
$timeDir = date('Ym');
|
||||
$targetDir .= "/" . $timeDir;
|
||||
if (!file_exists($attachDir . $targetDir)) {
|
||||
@mkdir($attachDir . $targetDir);
|
||||
}
|
||||
|
||||
//处理请求的文件信息
|
||||
$title = isset($file->name) ? $file->name : md5(TIMESTAMP . rand(1, 99)) . '.jpg'; //文件原名
|
||||
//取后缀名
|
||||
$_filetype = explode('/', $file->type);
|
||||
$suffix = strtolower($_filetype[1]);
|
||||
//重新命名以便转存
|
||||
$newName = date('dHis', TIMESTAMP) . '_' . md5($title);
|
||||
$newFile = $attachDir . $targetDir . "/" . $newName . "." . $suffix;
|
||||
|
||||
$res = $file->saveAs($newFile, TRUE);
|
||||
|
||||
//文件入库
|
||||
//POST数据处理
|
||||
$post = Yii::$app->request->post();
|
||||
$member_id = 0;
|
||||
if (isset($post['mid']) && (int)$post['mid'] > 0) {
|
||||
$member_id = (int)$post['mid'];
|
||||
}
|
||||
$options = '';
|
||||
if (isset($post['options'])) {
|
||||
$options = json_encode($options, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT);
|
||||
}
|
||||
$model = new CAttachment();
|
||||
$model->siteid = $siteId;
|
||||
$model->pid = $this->pid;
|
||||
$model->uid = $this->user_id;
|
||||
$model->mid = $member_id;
|
||||
$model->type = 0; //附件类型,0图片1视频2音频3表格4文档5PPT888证书999其他
|
||||
$model->status_code = 1;
|
||||
$model->title = $title;
|
||||
$model->filesize = $file->size;
|
||||
$model->route = $targetDir . "/" . $newName . "." . $suffix;
|
||||
$model->options = $options;
|
||||
$model->update_at = $model->create_at = time();
|
||||
$model->save();
|
||||
$id = $model->attributes['id']; //获取插入后id
|
||||
$this->result('上传成功', ['id' => $id, 'path' => $model->route], 200);
|
||||
}
|
||||
}
|
||||
|
||||
/*多图上传时的数据示例
|
||||
array(7) {
|
||||
[0]=>
|
||||
object(yii\web\UploadedFile)#60 (6) {
|
||||
["name"]=>
|
||||
string(18) "file-1652511550195"
|
||||
["tempName"]=>
|
||||
string(45) "/Applications/XAMPP/xamppfiles/temp/phpJvR1FV"
|
||||
["type"]=>
|
||||
string(9) "text/html"
|
||||
["size"]=>
|
||||
int(425)
|
||||
["error"]=>
|
||||
int(0)
|
||||
["_tempResource":"yii\web\UploadedFile":private]=>
|
||||
array(0) {
|
||||
}
|
||||
}
|
||||
[1]=>
|
||||
object(yii\web\UploadedFile)#62 (6) {
|
||||
["name"]=>
|
||||
string(18) "file-1652511550195"
|
||||
["tempName"]=>
|
||||
string(45) "/Applications/XAMPP/xamppfiles/temp/phpzIuYVB"
|
||||
["type"]=>
|
||||
string(9) "text/html"
|
||||
["size"]=>
|
||||
int(425)
|
||||
["error"]=>
|
||||
int(0)
|
||||
["_tempResource":"yii\web\UploadedFile":private]=>
|
||||
array(0) {
|
||||
}
|
||||
}
|
||||
[2]=>
|
||||
object(yii\web\UploadedFile)#63 (6) {
|
||||
["name"]=>
|
||||
string(18) "file-1652511550195"
|
||||
["tempName"]=>
|
||||
string(45) "/Applications/XAMPP/xamppfiles/temp/phpUHXR4W"
|
||||
["type"]=>
|
||||
string(9) "text/html"
|
||||
["size"]=>
|
||||
int(425)
|
||||
["error"]=>
|
||||
int(0)
|
||||
["_tempResource":"yii\web\UploadedFile":private]=>
|
||||
array(0) {
|
||||
}
|
||||
}
|
||||
[3]=>
|
||||
object(yii\web\UploadedFile)#64 (6) {
|
||||
["name"]=>
|
||||
string(18) "file-1652511550195"
|
||||
["tempName"]=>
|
||||
string(45) "/Applications/XAMPP/xamppfiles/temp/phpEa5Q93"
|
||||
["type"]=>
|
||||
string(9) "text/html"
|
||||
["size"]=>
|
||||
int(425)
|
||||
["error"]=>
|
||||
int(0)
|
||||
["_tempResource":"yii\web\UploadedFile":private]=>
|
||||
array(0) {
|
||||
}
|
||||
}
|
||||
[4]=>
|
||||
object(yii\web\UploadedFile)#65 (6) {
|
||||
["name"]=>
|
||||
string(18) "file-1652511550195"
|
||||
["tempName"]=>
|
||||
string(45) "/Applications/XAMPP/xamppfiles/temp/phpEDfHIr"
|
||||
["type"]=>
|
||||
string(9) "text/html"
|
||||
["size"]=>
|
||||
int(425)
|
||||
["error"]=>
|
||||
int(0)
|
||||
["_tempResource":"yii\web\UploadedFile":private]=>
|
||||
array(0) {
|
||||
}
|
||||
}
|
||||
[5]=>
|
||||
object(yii\web\UploadedFile)#66 (6) {
|
||||
["name"]=>
|
||||
string(18) "file-1652511550195"
|
||||
["tempName"]=>
|
||||
string(45) "/Applications/XAMPP/xamppfiles/temp/phpiLqBVZ"
|
||||
["type"]=>
|
||||
string(9) "text/html"
|
||||
["size"]=>
|
||||
int(425)
|
||||
["error"]=>
|
||||
int(0)
|
||||
["_tempResource":"yii\web\UploadedFile":private]=>
|
||||
array(0) {
|
||||
}
|
||||
}
|
||||
[6]=>
|
||||
object(yii\web\UploadedFile)#67 (6) {
|
||||
["name"]=>
|
||||
string(18) "file-1652511550195"
|
||||
["tempName"]=>
|
||||
string(45) "/Applications/XAMPP/xamppfiles/temp/php5rqzIk"
|
||||
["type"]=>
|
||||
string(9) "text/html"
|
||||
["size"]=>
|
||||
int(425)
|
||||
["error"]=>
|
||||
int(0)
|
||||
["_tempResource":"yii\web\UploadedFile":private]=>
|
||||
array(0) {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
# @Author: 嗨噜客(三亚) <fm453>
|
||||
# @Date: 2022-05-22T07:37:06+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2024-08-09T09:20:36+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace api\controllers\gm\v1;
|
||||
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\helpers\Url;
|
||||
use addons\models\AcWeituoren;
|
||||
use common\models\Member as User;
|
||||
use addons\models\AcUserExt;
|
||||
|
||||
class WeituorenController extends Common
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
// $this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
$apis = [
|
||||
'list' => '搜索委托单位清单',
|
||||
'detail' => '委托单位详情'
|
||||
];
|
||||
$this->result('您正使用CMTS系统委托单位管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
//列表
|
||||
public function actionList()
|
||||
{
|
||||
$pid = $this->pid;
|
||||
$return = [];
|
||||
$model = new AcWeituoren();
|
||||
$where = $where2 = [];
|
||||
$where2[] = 'and';
|
||||
$where['pid'] = $pid;
|
||||
$post = $this->postdata;
|
||||
$search = isset($post['search']) ? $post['search'] : NULL;
|
||||
if (!$search) {
|
||||
$search = [];
|
||||
}
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = ['LIKE', 'company', $search['title']];
|
||||
}
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->asArray()->where($where); //asArray() 放在find后,可让查询结果以数组形式呈现
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
|
||||
$page = $this->page;
|
||||
$pageSize = $this->pageSize;
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $pageSize]);
|
||||
$pages->setPage($page - 1, TRUE); //设置分页的当前页面值
|
||||
$_orderby = 'orderby DESC,id ASC';
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderby($_orderby)->all();
|
||||
if (!$res) {
|
||||
$this->result('没有符合条件的结果');
|
||||
}
|
||||
|
||||
$status = Yii::$app->params['CommonStatus'];
|
||||
$return['code'] = 200;
|
||||
$return['msg'] = '委托单位查询成功!';
|
||||
$return['data'] = ['total' => $data->count(),
|
||||
'data' => [
|
||||
'weituoren' => $res
|
||||
],
|
||||
'page' => $this->page];
|
||||
exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT));
|
||||
}
|
||||
|
||||
public function actionDetail()
|
||||
{
|
||||
$pid = $this->pid;
|
||||
$post = $this->postdata;
|
||||
|
||||
$id = isset($post['id']) ? $post['id'] : 0;
|
||||
if ($id <= 0) {
|
||||
$this->result('查询参数错误!');
|
||||
}
|
||||
$model = new AcWeituoren();
|
||||
$weituo = $model->findOne($id);
|
||||
$detail = $weituo->toArray();
|
||||
|
||||
$this->result('查询成功!', $detail, 200);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user