123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- /**
- * 企业管理Model
- * Created by PhpStorm.
- * User: 小威
- * Date: 2020/03/19
- * Time: 18:24
- */
- namespace JinDouYun\Model\Manage;
- use Exception;
- use JinDouYun\Dao\Oem\DOem;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use Mall\Framework\Core\ResultWrapper;
- use Jindouyun\Cache\EnterpriseCache;
- use JinDouYun\Dao\Enterprise\DEnterprise;
- use JinDouYun\Dao\Enterprise\DEnterpriseCategory;
- use JinDouYun\Model\Shop\MShop;
- use JinDouYun\Model\Department\MStaff;
- class MEnterprise
- {
- private $objDEnterprise;
- private $objDEnterpriseCategory;
- public function __construct()
- {
- $this->objDEnterprise = new DEnterprise('default');
- $this->objDEnterpriseCategory = new DEnterpriseCategory('default');
- $this->objDEnterprise->setTable($this->objDEnterprise->get_Table().'_1');
- }
- /**
- * 企业列表
- * @return ResultWrapper
- * @throws Exception
- */
- public function getAllEnterprise($selectParams=[])
- {
- $selectParams['deleteStatus'] = StatusCode::$standard;
- $limit = isset($selectParams['limit'])?$selectParams['limit']:10;
- $offset = isset($selectParams['offset'])?$selectParams['offset']:0;
- unset($selectParams['limit']);
- unset($selectParams['offset']);
- // 查询所有企业数据
- $dbResult = $this->objDEnterprise->select($selectParams,'*','createTime DESC',$limit,$offset);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDEnterprise->error(), ErrorCode::$dberror);
- }
- if(empty($dbResult)){
- return ResultWrapper::success($dbResult);
- }
- $enterpriseData = $dbResult;
- unset($dbResult);
- // 获取所有企业类别
- $dbResult = $this->objDEnterpriseCategory->select(['deleteStatus' => StatusCode::$standard]);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDEnterpriseCategory->error(), ErrorCode::$dberror);
- }
- if(empty($dbResult)){
- return ResultWrapper::fail('企业类别为空', ErrorCode::$paramError);
- }
- $formatCategory = [];
- foreach($dbResult as $value){
- $formatCategory[$value['id']] = $value['name'];
- }
- // 格式化企业数据
- $objMStaff = new MStaff();
- $objDOem = new DOem();
- $objDOem->setTable('qianniao_oem_1');
- foreach($enterpriseData as &$value){
- //获取企业下员工总数
- $modelResult = $objMStaff->getStaffTotalByEnterpriseId($value['id']);
- if(!$modelResult->isSuccess()){
- return ResultWrapper::fail($modelResult->getData(), $modelResult->getData());
- }
- $value['staffTotal'] = $modelResult->getData();
- //获取企业下商铺总数
- $objMShop = new MShop($value['id'], '');
- unset($modelResult);
- $modelResult = $objMShop->getShopTotalByEnterpriseId($value['id']);
- if(!$modelResult->isSuccess()){
- return ResultWrapper::fail($modelResult->getData(), $modelResult->getData());
- }
- $value['shopTotal'] = $modelResult->getData();
- //企业类别
- $value['categoryName'] = getArrayItem($formatCategory, $value['categoryId'], '');
- //到期状态
- if($value['expireTime'] < time()){
- $value['expireStatus'] = StatusCode::$delete;
- }else{
- $value['expireStatus'] = StatusCode::$standard;
- }
- //oem表的余额
- $value['balance'] = $objDOem->get_field('balance',['enterpriseId'=>$value['id']]);
- $value['balance'] = empty($value['balance']) ? "0.00" : $value['balance'];
- }
- $total = $this->objDEnterprise->count($selectParams);
- $return = [
- 'enterpriseData' => $enterpriseData,
- 'total' => ($total) ? intval($total) : 0,
- ];
- return ResultWrapper::success($return);
- }
- /**
- * 企业编辑
- * @param $params
- * @return ResultWrapper
- */
- public function updateEnterprise($params)
- {
- $id = $params['id'];
- unset($params['id']);
- $dbResult = $this->objDEnterprise->update(['expireTime' => $params['expireTime'], 'updateTime' => time()], ['id' => $id]);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDEnterprise->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- }
|