Enterprise.Class.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <?php
  2. /**
  3. * 企业管理Controller
  4. * Created by PhpStorm.
  5. * User: 小威
  6. * Date: 2019/11/04
  7. * Time: 11:50
  8. */
  9. namespace JinDouYun\Controller\Enterprise;
  10. use JinDouYun\Dao\Department\DStaff;
  11. use JinDouYun\Model\Order\MOrderReturn;
  12. use Mall\Framework\Core\ErrorCode;
  13. use JinDouYun\Controller\BaseController;
  14. use JinDouYun\Cache\EnterpriseCache;
  15. use JinDouYun\Cache\OverviewCache;
  16. use JinDouYun\Cache\CustomerCache;
  17. use JinDouYun\Model\Order\MOrder;
  18. use JinDouYun\Model\Stock\MInventoryOut;
  19. use JinDouYun\Model\Stock\MInventory;
  20. use JinDouYun\Model\Enterprise\MEnterprise;
  21. use JinDouYun\Model\Finance\MReceived;
  22. use JinDouYun\Model\Finance\MReceive;
  23. use JinDouYun\Model\Finance\MPay;
  24. use JinDouYun\Model\Customer\MCustomer;
  25. use JinDouYun\Model\Purchase\MSupplier;
  26. use JinDouYun\Model\GoodsCategory\MGoodsCategory;
  27. use JinDouYun\Model\GoodsManage\MGoodsBasic;
  28. use Mall\Framework\Core\StatusCode;
  29. class Enterprise extends BaseController
  30. {
  31. private $objMEnterprise;
  32. private $objEnterpriseCache;
  33. private $objOverviewCache;
  34. private $objMReceived;
  35. private $objMReceive;
  36. private $objMPay;
  37. private $objMCustomer;
  38. private $objMSupplier;
  39. private $objMGoodsCategory;
  40. private $objMGoodsBasic;
  41. public function __construct($isCheckAcl = true, $isMustLogin = true)
  42. {
  43. parent::__construct($isCheckAcl, $isMustLogin);
  44. $this->objMEnterprise = new MEnterprise();
  45. $this->objEnterpriseCache = new EnterpriseCache();
  46. $this->objOverviewCache = new OverviewCache();
  47. $this->objMReceived = new MReceived($this->onlineEnterpriseId, $this->onlineUserId);
  48. $this->objMReceive = new MReceive($this->onlineEnterpriseId, $this->onlineUserId);
  49. $this->objMPay = new MPay($this->onlineEnterpriseId, $this->onlineUserId);
  50. $this->objMCustomer = new MCustomer($this->onlineEnterpriseId, $this->onlineUserId);
  51. $this->objMSupplier = new MSupplier($this->onlineUserId, $this->onlineEnterpriseId);
  52. $this->objMGoodsCategory = new MGoodsCategory($this->onlineUserId, $this->onlineEnterpriseId);
  53. $this->objMGoodsBasic = new MGoodsBasic($this->onlineUserId, $this->onlineEnterpriseId);
  54. }
  55. /**
  56. * 获取参数
  57. *
  58. * @return array
  59. */
  60. public function commonFieldFilter()
  61. {
  62. $params = $this->request->getRawJson();
  63. if (empty($params)) {
  64. $this->sendOutput('参数为空', ErrorCode::$paramError);
  65. }
  66. $EnterpriseData = [
  67. "userCenterId" => $this->onlineUserId, //客户id
  68. "enterpriseName" => isset($params['enterpriseName']) ? $params['enterpriseName'] : '', //企业名称
  69. "contact" => isset($params['contact']) ? $params['contact'] : '', //联系人
  70. "mobile" => isset($params['mobile']) ? $params['mobile'] : '', //联系电话
  71. "provinceCode" => isset($params['provinceCode']) ? $params['provinceCode'] : '', //省份编码
  72. "cityCode" => isset($params['cityCode']) ? $params['cityCode'] : '', //城市编码
  73. "districtCode" => isset($params['districtCode']) ? $params['districtCode'] : '', //区县编码
  74. "address" => isset($params['address']) ? $params['address'] : '', //详细地址
  75. "categoryId" => isset($params['categoryId']) ? $params['categoryId'] : 0, //企业类别
  76. "startTime" => isset($params['startTime']) ? $params['startTime'] : time(), //营业时间
  77. "expireTime" =>strtotime( isset($params['expireTime']) ? $params['expireTime'] : time()), //到期时间
  78. "logo" => isset($params['logo']) ? $params['logo'] : '', //企业logo
  79. ];
  80. //必填项
  81. foreach ($EnterpriseData as $key => $value) {
  82. if (empty($value) && $value !== 0) {
  83. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  84. }
  85. }
  86. //选填项
  87. $EnterpriseData['brandName'] = isset($params['brandName']) ? $params['brandName'] : '';
  88. $EnterpriseData['isoem'] = isset($params['isoem']) ? $params['isoem'] : StatusCode::$delete; //确认企业贴牌 4是确认,5是其他
  89. $EnterpriseData['updateTime'] = time();
  90. return $EnterpriseData;
  91. }
  92. /**
  93. * 企业删除
  94. * @throws
  95. */
  96. public function deleteEnterprise()
  97. {
  98. $params = $this->request->getRawJson();
  99. $params['enterpriseId'] = $this->onlineEnterpriseId;
  100. $params['userCenterId'] = $this->onlineUserId;
  101. //获取参数
  102. //获取参数
  103. $result = $this->objMEnterprise->deleteEnterprise($params);
  104. //删除redis里的企业id和用户id的关联
  105. $this->objEnterpriseCache->deleteEnterprise($params['userCenterId'], $params['enterpriseId']);
  106. if ($result->isSuccess()) {
  107. parent::sendOutput($result->getData());
  108. } else {
  109. parent::sendOutput($result->getData(), $result->getErrorCode());
  110. }
  111. }
  112. /**
  113. * 企业修改
  114. * @throws \Exception
  115. */
  116. public function updateEnterprise()
  117. {
  118. $params['id'] = $this->onlineEnterpriseId;
  119. $EnterpriseData = $this->commonFieldFilter();
  120. $result = $this->objMEnterprise->updateEnterprise($EnterpriseData, $params);
  121. if ($result->isSuccess()) {
  122. parent::sendOutput($result->getData());
  123. } else {
  124. parent::sendOutput($result->getData(), $result->getErrorCode());
  125. }
  126. }
  127. /**
  128. * 企业详情
  129. * @throws \Exception
  130. */
  131. public function getEnterpriseInfo()
  132. {
  133. $params['enterpriseId'] = $this->onlineEnterpriseId;
  134. $params['userCenterId'] = $this->onlineUserId;
  135. $result = $this->objMEnterprise->getEnterpriseInfo($params);
  136. if ($result->isSuccess()) {
  137. parent::sendOutput($result->getData());
  138. } else {
  139. parent::sendOutput($result->getData(), $result->getErrorCode());
  140. }
  141. }
  142. /**
  143. * 获取当前登录员工信息
  144. */
  145. public function getStaffByToken()
  146. {
  147. $roleType = $this->request->param('request_id');
  148. if (empty($roleType)) {
  149. $this->sendOutput('参数为空', ErrorCode::$paramError);
  150. }
  151. $params['roleType'] = $roleType;
  152. $params['userCenterId'] = $this->onlineUserId;
  153. $params['enterpriseId'] = $this->onlineEnterpriseId;
  154. $params['shopId'] = $this->shopId;
  155. $result = $this->objMEnterprise->getStaffByToken($params);
  156. if ($result->isSuccess()) {
  157. parent::sendOutput($result->getData());
  158. } else {
  159. parent::sendOutput($result->getData(), $result->getErrorCode());
  160. }
  161. }
  162. /**
  163. * 首页概况
  164. * @throws \Exception
  165. */
  166. public function overview()
  167. {
  168. $params = $this->request->getRawJson();
  169. //经营概况:是否查找全店或指定店铺
  170. $businessOverviewShopId = isset($params['businessOverviewShopId']) ? $params['businessOverviewShopId'] : '';
  171. $ranking = isset($params['ranking']) ? $params['ranking'] : '1';//销量排行,销额排行
  172. //类目排行:是否查找全店或指定店铺
  173. $categoryRankingShopId = isset($params['categoryRankingShopId']) ? $params['categoryRankingShopId'] : '';
  174. //商品排行:是否查找全店或指定店铺
  175. $goodsRankingShopId = isset($params['goodsRankingShopId']) ? $params['goodsRankingShopId'] : '';
  176. //供应商排行:是否查找全店或指定店铺
  177. $supplierRankingShopId = isset($params['supplierRankingShopId']) ? $params['supplierRankingShopId'] : '';
  178. $objMInventory = new MInventory($this->onlineEnterpriseId, $this->onlineUserId);
  179. $objCustomerCache = new CustomerCache();
  180. $objMOrder = new MOrder($this->onlineUserId, $this->onlineEnterpriseId);
  181. $objMInventoryOut = new MInventoryOut($this->onlineEnterpriseId, $this->onlineUserId);
  182. // 统计订单未出库总数
  183. $modelResult = $objMInventoryOut->statisticsCountInventoryOut($businessOverviewShopId);
  184. if(!$modelResult->isSuccess()){
  185. parent::sendOutput($modelResult->getData(),$modelResult->getErrorCode());
  186. }
  187. $objMOrderReturn = new MOrderReturn($this->onlineEnterpriseId,$this->onlineUserId);
  188. $result = $objMOrderReturn->getSubRetMoneyToday(['shopId' => $businessOverviewShopId]);
  189. if (!$result->isSuccess()){
  190. parent::sendOutput($result->getData(),$result->getErrorCode());
  191. }
  192. $subRetMoney = $result->getData();
  193. $numberUser = $this->objMCustomer->getNumberUser()->getData();
  194. if (!$numberUser['totalCount']){
  195. $numberUser['valid']=0;
  196. $numberUser['void']=0;
  197. }
  198. $orderNumOfNotOutOfStock = $modelResult->getData();
  199. $data = [
  200. 'aggregateStatistics' => [
  201. 'totalShouldReceive' => $this->objMCustomer->getTotalShouldReceive(),//应收账款,先取redis,不存在,取数据库
  202. 'totalShouldPay' => $this->objMSupplier->getTotalShouldPay(),//应付账款
  203. 'numberOfProductsInStock' => $objMInventory->statistics()['numberOfProductsInStock'],//库存商品数
  204. 'totalMoneyOfInventory' => $objMInventory->statistics()['totalMoneyOfInventory'],//库存总金额
  205. 'customerTotalNum' => $numberUser,//客户总数
  206. ],
  207. //经营概况
  208. 'businessOverview' => [
  209. 'orderTotalMoney' => bcsub($objMOrder->businessOverview('orderTotalMoney', $businessOverviewShopId),$subRetMoney,2),//今日下单金额,所有订单不分状态
  210. 'orderConfirmedMoney' => bcsub($objMOrder->businessOverview('orderConfirmedMoney', $businessOverviewShopId),$subRetMoney,2),//营业额:被确认以后的所有状态的订单总额
  211. 'todayGrossProfit' => bcsub($objMOrder->businessOverview('todayGrossProfit', $businessOverviewShopId),$subRetMoney,2),//今日毛利:被确认的订单的:售价减去成本之和
  212. 'todayReceivedMoney' => $this->objMReceived->getTodayReceivedMoney($businessOverviewShopId),//今日收款
  213. 'todayNewCustomerNum' => $this->objMCustomer->getTodayCustomerTotalNum($businessOverviewShopId),//今日新增客户
  214. 'todayConfirmedOrderNum' => $objMOrder->businessOverview('todayConfirmedOrderNum', $businessOverviewShopId),//今日订单:被确认以后的所有状态的订单总数
  215. 'todayConfirmedOrderCustomerNum' => $objMOrder->getTodayCustomerOrderNum($businessOverviewShopId),//下单客户:被确认以后的所有状态的订单对应的客户总数
  216. //'customerAverageMoney' => $objMOrder->customerAverageMoney('customerAverageMoney', $businessOverviewShopId),//客单价:被确认以后的所有状态的订单总额/订单总数
  217. 'customerAverageMoney' => $objMOrder->getTodayOrder($businessOverviewShopId),//客单价:今日确认下单的总金额数除以今日下单的总客户数
  218. //业务流程改为 所有未出库订单 所以查询方式改变
  219. 'orderNumOfNotOutOfStock' => $orderNumOfNotOutOfStock,
  220. 'todayCanceledOrder' => $objMOrder->businessOverview('todayCanceledOrder', $businessOverviewShopId),//今日取消订单
  221. ],
  222. //排行榜:销量排行/销额排行
  223. 'ranking' => [
  224. //类目排行
  225. 'categoryRanking' => $this->objMGoodsCategory->todayCategoryRanking($ranking, $categoryRankingShopId),
  226. //商品排行
  227. 'goodsRanking' => $this->objMGoodsBasic->todayGoodsRanking($ranking, $goodsRankingShopId),
  228. //客户排行
  229. 'customerRanking' => $this->objMCustomer->todayCustomerRanking($ranking),
  230. //供应商排行
  231. 'supplierRanking' => $this->objMSupplier->todaySupplierRanking($ranking, $supplierRankingShopId),
  232. ],
  233. //近7天订单趋势
  234. 'chartData' => $this->objOverviewCache->getOrderTrend($this->onlineEnterpriseId)
  235. ];
  236. parent::sendOutput($data);
  237. }
  238. }