UserEnterprise.Class.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. /**
  3. * 用户中心企业管理Controller
  4. * Created by PhpStorm.
  5. * User: 小威
  6. * Date: 2019/11/04
  7. * Time: 16:50
  8. */
  9. namespace JinDouYun\Controller\Enterprise;
  10. use JinDouYun\Model\GoodsManage\MUnits;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\ResultWrapper;
  13. use Mall\Framework\Core\StatusCode;
  14. use JinDouYun\Cache\EnterpriseCache;
  15. use JinDouYun\Controller\BaseController;
  16. use JinDouYun\Model\Enterprise\MEnterprise;
  17. use JinDouYun\Model\Department\MStaff;
  18. use JinDouYun\Model\Department\MRoleAcl;
  19. use JinDouYun\Model\UserCenter\MUserCenterRegister;
  20. class UserEnterprise extends BaseController
  21. {
  22. private $objMEnterprise;
  23. private $objEnterpriseCache;
  24. private $objMUserCenterRegister;
  25. public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken = false)
  26. {
  27. parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
  28. $this->objMEnterprise = new MEnterprise();
  29. $this->objEnterpriseCache = new EnterpriseCache();
  30. }
  31. /**
  32. * 获取参数
  33. *
  34. * @return array
  35. */
  36. public function commonFieldFilter()
  37. {
  38. $params = $this->request->getRawJson();
  39. if (empty($params)) {
  40. $this->sendOutput('参数为空', ErrorCode::$paramError);
  41. }
  42. $EnterpriseData = [
  43. "userCenterId" => $this->onlineUserId, //客户id
  44. "enterpriseName" => isset($params['enterpriseName']) ? $params['enterpriseName'] : '', //企业名称
  45. "contact" => isset($params['contact']) ? $params['contact'] : '', //联系人
  46. "mobile" => isset($params['mobile']) ? $params['mobile'] : '', //联系电话
  47. "provinceCode" => isset($params['provinceCode']) ? $params['provinceCode'] : '', //省份编码
  48. "cityCode" => isset($params['cityCode']) ? $params['cityCode'] : '', //城市编码
  49. "districtCode" => isset($params['districtCode']) ? $params['districtCode'] : '', //区县编码
  50. "address" => isset($params['address']) ? $params['address'] : '', //详细地址
  51. //"categoryId" => isset($params['categoryId']) ? $params['categoryId'] : '', //企业类别
  52. //"startTime" => isset($params['startTime']) ? $params['startTime'] : '', //营业时间
  53. //"endTime" => isset($params['endTime']) ? $params['endTime'] : '', //停业时间
  54. "logo" => isset($params['logo']) ? $params['logo'] : '', //企业logo
  55. "scope" => isset($params['scope']) ? $params['scope'] : '', //企业经营类型4单店铺 5多店铺
  56. ];
  57. //必填项
  58. foreach ($EnterpriseData as $key => $value) {
  59. if (empty($value) && $value !== 0) {
  60. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  61. }
  62. }
  63. //选填项
  64. $EnterpriseData['brandName'] = isset($params['brandName']) ? $params['brandName'] : '';
  65. $EnterpriseData['updateTime'] = time();
  66. return $EnterpriseData;
  67. }
  68. /**
  69. * 企业添加
  70. * @throws \Exception
  71. */
  72. public function addEnterprise()
  73. {
  74. $EnterpriseData = $this->commonFieldFilter();
  75. $result = $this->objMEnterprise->addEnterprise($EnterpriseData, $this->authorization);
  76. $content=$result->getData();
  77. if ($result->isSuccess()) {
  78. $returnData = $result->getData();
  79. //存储企业token和企业id
  80. $this->objEnterpriseCache->enterpriseIdAndTokenCache($returnData['enterpriseId'], $returnData['token']);
  81. //关联userId和企业id,权限校验需要
  82. $this->objEnterpriseCache->cacheUserCenterIdAndEnterpriseId($this->onlineUserId, StatusCode::$roleType['admin'],$returnData['enterpriseId']);
  83. //创建默认门店
  84. $res = $this->objMEnterprise->autoCreateData($content["userCenterId"], $returnData['enterpriseId']);
  85. //自动创建单位
  86. new MUnits($content["userCenterId"],$returnData['enterpriseId']);
  87. parent::sendOutput($result->getData());
  88. } else {
  89. parent::sendOutput($result->getData(), $result->getErrorCode());
  90. }
  91. }
  92. /**
  93. * 修改密码
  94. */
  95. public function updateUserCenterData()
  96. {
  97. $params = $this->request->getRawJson();
  98. if(empty($params)){
  99. parent::sendOutput('参数为空', ErrorCode::$paramError);
  100. }
  101. $updateData = [
  102. 'oldPassword' => isset($params['oldPassword']) ? $params['oldPassword'] : '',
  103. 'newPassword' => isset($params['newPassword']) ? $params['newPassword'] : '',
  104. 'rePassword' => isset($params['rePassword']) ? $params['rePassword'] : ''
  105. ];
  106. foreach($updateData as $key => $value){
  107. if(empty($value)){
  108. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  109. }
  110. }
  111. if($updateData['newPassword'] !== $updateData['rePassword']){
  112. parent::sendOutput('两次输入密码不一致', ErrorCode::$paramError);
  113. }
  114. $where = ['id' => $this->onlineUserId];
  115. $modelResult = $this->objMEnterprise->updateUserCenterData($updateData, $where);
  116. if(!$modelResult->isSuccess()){
  117. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  118. }
  119. parent::sendOutput($modelResult->getData());
  120. }
  121. /**
  122. * 企业列表
  123. * @throws \Exception
  124. */
  125. public function getAllEnterprise()
  126. {
  127. $result = $this->objMEnterprise->getAllEnterprise($this->onlineUserId);
  128. if ($result->isSuccess()) {
  129. parent::sendOutput($result->getData());
  130. } else {
  131. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  132. }
  133. }
  134. /**
  135. * 获取当前登录用户的角色对应的操作权限
  136. */
  137. public function getAclList() {
  138. parent::__construct(false, true, true);
  139. $roleType = $this->request->param('request_id');
  140. if(empty($roleType)){
  141. $this->sendOutput('参数为空', ErrorCode::$paramError);
  142. }
  143. $aclData = ['isAdministrator'=>false, 'custom'=>[], 'dataField'=>[] ];
  144. //判断是否可以进入企业
  145. // switch ($roleType){
  146. // case StatusCode::$roleType['admin']:
  147. // //企业创建者进入
  148. // $aclData['isAdministrator'] = true;
  149. // break;
  150. // case StatusCode::$roleType['staff']:
  151. // //员工进入
  152. // $objMStaff = new MStaff($this->onlineEnterpriseId,$this->onlineUserId);
  153. // $modelResult = $objMStaff->getStaffData(['userCenterId' => $this->onlineUserId]);
  154. // if(!$modelResult->isSuccess()){
  155. // return ResultWrapper::fail($modelResult->getData(), $modelResult->getErrorCode());
  156. // }
  157. // $staff = $modelResult->getData();
  158. // if($staff['shopId'] == 0){
  159. // $aclData['isAdministrator'] = true;
  160. // }
  161. // break;
  162. // case StatusCode::$roleType['merchant']:
  163. // //商户进入
  164. // $aclData['isAdministrator'] = true;
  165. // break;
  166. // default:
  167. // $this->sendOutput('参数错误', ErrorCode::$paramError);
  168. // break;
  169. // }
  170. if($roleType == StatusCode::$roleType['admin']) {
  171. $aclData = [
  172. 'isAdministrator' => true,
  173. 'custom' => [],
  174. 'dataField'=>[],
  175. ];
  176. }
  177. if($roleType == StatusCode::$roleType['staff']) {
  178. //获取当前用户对应的角色的权限
  179. $objMRoleAcl = new MRoleAcl($this->onlineEnterpriseId);
  180. $aclResult = $objMRoleAcl->getRoleAclByUserCenterId($this->onlineUserId);
  181. parent::sendOutput($aclResult->getData());
  182. }
  183. parent::sendOutput($aclData);
  184. }
  185. /**
  186. * 自动创建
  187. * @throws \Exception
  188. */
  189. public function autoCreateData()
  190. {
  191. $data = $this->request->getRawJson();
  192. if(empty($data) || !isset($data['enterpriseId']) || !isset($data['userCenterId'])){
  193. echo '参数错误';
  194. return;
  195. }
  196. $result = $this->objMEnterprise->autoCreateData($data['userCenterId'], $data['enterpriseId']);
  197. if(!$result->isSuccess()){
  198. echo $result->getData();
  199. return;
  200. }
  201. //自动创建单位
  202. new MUnits($data['userCenterId'],$data['enterpriseId']);
  203. echo '执行成功^^';
  204. }
  205. }