MEnterprise.Class.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * 企业管理Model
  4. * Created by PhpStorm.
  5. * User: 小威
  6. * Date: 2020/03/19
  7. * Time: 18:24
  8. */
  9. namespace JinDouYun\Model\Manage;
  10. use Exception;
  11. use JinDouYun\Dao\Oem\DOem;
  12. use Mall\Framework\Core\ErrorCode;
  13. use Mall\Framework\Core\StatusCode;
  14. use Mall\Framework\Core\ResultWrapper;
  15. use Jindouyun\Cache\EnterpriseCache;
  16. use JinDouYun\Dao\Enterprise\DEnterprise;
  17. use JinDouYun\Dao\Enterprise\DEnterpriseCategory;
  18. use JinDouYun\Model\Shop\MShop;
  19. use JinDouYun\Model\Department\MStaff;
  20. class MEnterprise
  21. {
  22. private $objDEnterprise;
  23. private $objDEnterpriseCategory;
  24. public function __construct()
  25. {
  26. $this->objDEnterprise = new DEnterprise('default');
  27. $this->objDEnterpriseCategory = new DEnterpriseCategory('default');
  28. $this->objDEnterprise->setTable($this->objDEnterprise->get_Table().'_1');
  29. }
  30. /**
  31. * 企业列表
  32. * @return ResultWrapper
  33. * @throws Exception
  34. */
  35. public function getAllEnterprise($selectParams=[])
  36. {
  37. $selectParams['deleteStatus'] = StatusCode::$standard;
  38. $limit = isset($selectParams['limit'])?$selectParams['limit']:10;
  39. $offset = isset($selectParams['offset'])?$selectParams['offset']:0;
  40. unset($selectParams['limit']);
  41. unset($selectParams['offset']);
  42. // 查询所有企业数据
  43. $dbResult = $this->objDEnterprise->select($selectParams,'*','createTime DESC',$limit,$offset);
  44. if($dbResult === false){
  45. return ResultWrapper::fail($this->objDEnterprise->error(), ErrorCode::$dberror);
  46. }
  47. if(empty($dbResult)){
  48. return ResultWrapper::success($dbResult);
  49. }
  50. $enterpriseData = $dbResult;
  51. unset($dbResult);
  52. // 获取所有企业类别
  53. $dbResult = $this->objDEnterpriseCategory->select(['deleteStatus' => StatusCode::$standard]);
  54. if($dbResult === false){
  55. return ResultWrapper::fail($this->objDEnterpriseCategory->error(), ErrorCode::$dberror);
  56. }
  57. if(empty($dbResult)){
  58. return ResultWrapper::fail('企业类别为空', ErrorCode::$paramError);
  59. }
  60. $formatCategory = [];
  61. foreach($dbResult as $value){
  62. $formatCategory[$value['id']] = $value['name'];
  63. }
  64. // 格式化企业数据
  65. $objMStaff = new MStaff();
  66. $objDOem = new DOem();
  67. $objDOem->setTable('qianniao_oem_1');
  68. foreach($enterpriseData as &$value){
  69. //获取企业下员工总数
  70. $modelResult = $objMStaff->getStaffTotalByEnterpriseId($value['id']);
  71. if(!$modelResult->isSuccess()){
  72. return ResultWrapper::fail($modelResult->getData(), $modelResult->getData());
  73. }
  74. $value['staffTotal'] = $modelResult->getData();
  75. //获取企业下商铺总数
  76. $objMShop = new MShop($value['id'], '');
  77. unset($modelResult);
  78. $modelResult = $objMShop->getShopTotalByEnterpriseId($value['id']);
  79. if(!$modelResult->isSuccess()){
  80. return ResultWrapper::fail($modelResult->getData(), $modelResult->getData());
  81. }
  82. $value['shopTotal'] = $modelResult->getData();
  83. //企业类别
  84. $value['categoryName'] = getArrayItem($formatCategory, $value['categoryId'], '');
  85. //到期状态
  86. if($value['expireTime'] < time()){
  87. $value['expireStatus'] = StatusCode::$delete;
  88. }else{
  89. $value['expireStatus'] = StatusCode::$standard;
  90. }
  91. //oem表的余额
  92. $value['balance'] = $objDOem->get_field('balance',['enterpriseId'=>$value['id']]);
  93. $value['balance'] = empty($value['balance']) ? "0.00" : $value['balance'];
  94. }
  95. $total = $this->objDEnterprise->count($selectParams);
  96. $return = [
  97. 'enterpriseData' => $enterpriseData,
  98. 'total' => ($total) ? intval($total) : 0,
  99. ];
  100. return ResultWrapper::success($return);
  101. }
  102. /**
  103. * 企业编辑
  104. * @param $params
  105. * @return ResultWrapper
  106. */
  107. public function updateEnterprise($params)
  108. {
  109. $id = $params['id'];
  110. unset($params['id']);
  111. $dbResult = $this->objDEnterprise->update(['expireTime' => $params['expireTime'], 'updateTime' => time()], ['id' => $id]);
  112. if($dbResult === false){
  113. return ResultWrapper::fail($this->objDEnterprise->error(), ErrorCode::$dberror);
  114. }
  115. return ResultWrapper::success($dbResult);
  116. }
  117. }