123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- /**
- * Created by PhpStorm.
- * User: kang
- * Date: 2021/4/14
- * Time: 9:36
- */
- namespace JinDouYun\Model\System;
- use JinDouYun\Dao\System\DDriver;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use Mall\Framework\Core\ResultWrapper;
- use JinDouYun\Model\MBaseModel;
- class MDriver extends MBaseModel
- {
- private $objDDriver;
- private $enterpriseId;
- private $userCenterId;
-
- public function __construct($enterpriseId, $userCenterId)
- {
- $this->enterpriseId = $enterpriseId;
- $this->userCenterId = $userCenterId;
- parent::__construct($this->enterpriseId, $this->userCenterId);
-
- $this->objDDriver = new DDriver('default');
- }
-
- /**
- * 添加司机信息
- * @param $params
- * @return ResultWrapper
- * @throws Exception
- */
- public function addDriver($params)
- {
- $dbResult = $this->objDDriver->get(['phone' => $params['phone']]);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDDriver->error(), ErrorCode::$dberror);
- }
- if(!empty($dbResult)){
- return ResultWrapper::fail('该司机号码已存在', ErrorCode::$paramError);
- }
- unset($dbResult);
- $dbResult = $this->objDDriver->insert($params);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDDriver->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
-
- }
-
- /**
- * 获取指定司机信息
- */
- public function getDriverInfo($driverId)
- {
- if(isset($driverId) && !empty($driverId)){
- $where = [
- 'id'=> $driverId,
- 'deleteStatus'=> StatusCode::$standard
- ];
- }
- $dbResult = $this->objDDriver->get($where);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDDriver->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
-
- }
-
- /**
- * 编辑司机信息
- *
- * @return ResultWrapper
- */
- public function editDriver($params)
- {
- if( empty($params['id']) ){
- return ResultWrapper::fail('没有指定要修改的司机信息', ErrorCode::$paramError);
- }
- $driverId = $params['id'];
- unset($params['id']);
- $dbResult = $this->objDDriver->update($params, $driverId);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDDriver->error(), ErrorCode::$dberror);
- }else{
- return ResultWrapper::success($dbResult);
- }
- }
-
- /**
- * 删除司机信息
- *
- * @return ResultWrapper
- */
- public function delDriver($driverId)
- {
- $updateData = [
- 'deleteStatus' => StatusCode::$delete,
- ];
- $dbResult = $this->objDDriver->update($updateData, 'id ='.$driverId. ' and enterpriseId ='.$this->enterpriseId);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDDriver->error(), ErrorCode::$dberror);
- }else{
- return ResultWrapper::success($dbResult);
- }
- }
-
- /**
- * 获取后台所有司机信息列表
- * @param array $selectParams 过滤条件
- * @return ResultWrapper
- */
- public function getAllDriver($selectParams)
- {
- $limit = $selectParams['limit'];
- unset($selectParams['limit']);
- $offset = $selectParams['offset'];
- unset($selectParams['offset']);
- $selectParams['deleteStatus'] = StatusCode::$standard;
- $selectParams['enterpriseId'] = $this->enterpriseId;
-
- $dbResult = $this->objDDriver->select($selectParams, '*', 'createTime desc',$limit,$offset);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDDriver->error(), ErrorCode::$dberror);
- }
- $total = $this->objDDriver->count($selectParams);
-
- $return = [
- 'data' => $dbResult,
- 'total' => ($total)?intval($total):0,
- ];
- return ResultWrapper::success($return);
- }
-
- /**
- * 启用司机(不分页)
- * @return ResultWrapper
- */
- public function getAllOpenDriver()
- {
- $selectParams['deleteStatus'] = StatusCode::$standard;
- $selectParams['state'] = StatusCode::$standard;
- $selectParams['enterpriseId'] = $this->enterpriseId;
- $dbResult = $this->objDDriver->select($selectParams, '*', 'createTime desc');
- if($dbResult === false){
- return ResultWrapper::fail($this->objDDriver->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 获取司机数据
- * @param array $where
- * @param string $fields
- * @param false $isOne
- * @return ResultWrapper
- */
- public function getDriverData($where = [], $fields = '*', $isOne = false)
- {
- $where['enterpriseId'] = $this->enterpriseId;
- $where['deleteStatus'] = StatusCode::$standard;
- if($isOne){
- $dbResult = $this->objDDriver->get($where, $fields);
- }else{
- $dbResult = $this->objDDriver->select($where, $fields);
- }
- if($dbResult === false){
- return ResultWrapper::fail($this->objDDriver->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 修改司机数据
- * @param $update
- * @param $where
- * @return ResultWrapper
- */
- public function updateDriverData($update, $where)
- {
- $where['enterpriseId'] = $this->enterpriseId;
- $dbResult = $this->objDDriver->update($update, $where);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDDriver->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
-
- }
|