BusinessController.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2021/9/22
  8. * Time: 13:37
  9. */
  10. namespace business\admin\controllers;
  11. use app\common\facades\Setting;
  12. use app\common\models\Member;
  13. use app\common\services\Session;
  14. use business\common\models\BusinessApply;
  15. use business\common\models\Department;
  16. use business\common\models\ManagerList;
  17. use business\common\models\PlatLog;
  18. use business\common\models\Staff;
  19. use business\common\services\BusinessService;
  20. use business\common\services\SettingService;
  21. use business\common\controllers\components\BaseController;
  22. use business\common\models\Business as BusinessModel;
  23. use Illuminate\Support\Facades\Schema;
  24. use Yunshop\YunSign\common\models\CompanyAccount;
  25. use Yunshop\YunSign\common\models\PersonAccount;
  26. class BusinessController extends BaseController
  27. {
  28. /*
  29. * 公用信息接口
  30. */
  31. public function getBusinessCommonData()
  32. {
  33. $member = Member::uniacid()->select('nickname', 'realname', 'avatar', 'uid', 'mobile')->find(\YunShop::app()->getMemberId());
  34. $right = [];
  35. if (\request()->is_business) {
  36. if (!$business_id = SettingService::getBusinessId()) {
  37. return $this->errorJson(BusinessService::BUSINESS_LIST_MSG, BusinessService::getBusinessListReturn());
  38. }
  39. $right = BusinessService::checkBusinessRight();
  40. }
  41. if (request()->is_person) {
  42. $right = BusinessService::checkPersonRight();
  43. }
  44. return $this->successJson('成功', [
  45. 'member' => $member,
  46. 'identity' => $right['identity'] ?: 0,
  47. 'tab' => $right['page'] ?: [],
  48. 'page_route' => $right['page_route'] ?: [],
  49. 'plat_setting' => array_merge(\Yunshop\BusinessPc\services\SettingService::getSetting(), \Yunshop\BusinessPc\services\SettingService::getCustomerSetting()),
  50. 'business' => [
  51. 'business_name' => $right['business_name'] ?: '',
  52. 'business_id' => $right['business_id'] ?: 0,
  53. 'uniacid' => \YunShop::app()->uniacid,
  54. ],
  55. 'pos_goods_id'=>app('plugins')->isEnabled('shop-pos') && ($pos_goods_id = \Yunshop\ShopPos\services\SettingService::getSetting()['bind_goods_id']) ? $pos_goods_id : 0,
  56. ]);
  57. }
  58. public function pluginEnabled()
  59. {
  60. $auth_plugins = SettingService::getEnablePlugins(SettingService::getBusinessId());
  61. $project_manager = app('plugins')->isEnabled('project-manager') && in_array('ProjectManager', $auth_plugins);
  62. $data['project_manager'] = $project_manager?1:0;
  63. return $this->successJson('权限',$data);
  64. }
  65. /*
  66. * 管理企业
  67. */
  68. public function manageBusiness()
  69. {
  70. if (request()->identity_type) {//个人空间
  71. $plat_log = PlatLog::where('uid', \YunShop::app()->getMemberId())->first();
  72. if ($plat_log) {
  73. $plat_log->update([
  74. 'final_plat_id' => 0,
  75. ]);
  76. } else {
  77. $create_arr = [
  78. 'uniacid' => \YunShop::app()->uniacid,
  79. 'uid' => \YunShop::app()->getMemberId(),
  80. 'final_plat_id' => 0,
  81. ];
  82. PlatLog::create($create_arr);
  83. }
  84. Session::clear('business_id');
  85. return $this->successJson('成功');
  86. }
  87. $business_id = \request()->id ?: 0;
  88. $res = BusinessService::checkBusinessRight($business_id);
  89. if (!$res['identity']) {
  90. return $this->errorJson('无权管理该企业');
  91. }
  92. SettingService::setBusinessId($business_id);
  93. return $this->successJson('成功');
  94. }
  95. /*
  96. * 企业管理列表
  97. */
  98. public function businessList()
  99. {
  100. $uid = \YunShop::app()->getMemberId();
  101. $where = [
  102. ['status', BusinessModel::STATUS_NORMAL],
  103. ['member_uid', $uid]
  104. ];
  105. $creater_id_list = BusinessModel::uniacid()->where($where)->pluck('id')->toArray(); // 查询为创始人的企业id
  106. $manager_id_list = ManagerList::where('uid', $uid)->pluck('business_id')->toArray(); // 查询为管理员的企业id
  107. $staff_id_list = Staff::where('uid', $uid)->where('disabled', 0)->pluck('business_id')->toArray(); //查询为员工的企业id
  108. $owner_id_list = [];
  109. if (app('plugins')->isEnabled('yun-sign') && Schema::hasColumn('yz_yun_sign_company_account', 'cid')) {
  110. $owner_id_list = CompanyAccount::where('uid', $uid)->pluck('cid')->toArray(); // 查询为法人的企业id
  111. }
  112. $platform_list = BusinessService::formPlatList($creater_id_list, $owner_id_list, $manager_id_list, $staff_id_list); //组装企业列表
  113. $final_plat_id = PlatLog::getPlatLogId(); // 获取用户最后进行管理的企业
  114. return $this->successJson('成功', [
  115. 'platform_list' => $platform_list,
  116. 'final_plat_id' => $final_plat_id
  117. ]);
  118. }
  119. /*
  120. * 创建企业
  121. */
  122. public function addBussiness()
  123. {
  124. $request = \request();
  125. if (!$request->name) {
  126. return $this->errorJson('请输入企业名');
  127. }
  128. if (!$request->logo_img) {
  129. return $this->errorJson('请上传企业logo');
  130. }
  131. if (!SettingService::needExamine()){
  132. $business = BusinessModel::create([
  133. 'uniacid' => \YunShop::app()->uniacid,
  134. 'member_uid' => \YunShop::app()->getMemberId(),
  135. 'name' => trim($request->name),
  136. 'logo_img' => trim($request->logo_img),
  137. 'auth_plugins' => serialize((Setting::get('plugin.work-wechat-platform.auth_plugins') ?: [])),
  138. ]);
  139. if (!$business) {
  140. return $this->errorJson('创建企业失败');
  141. }
  142. Department::create([
  143. 'uniacid' => \YunShop::app()->uniacid,
  144. 'business_id' => $business->id,
  145. 'name' => $business->name,
  146. 'en_name' => '',
  147. 'level' => 1,
  148. 'parent_id' => 0,
  149. 'wechat_department_id' => 0,
  150. 'order' => 9999
  151. ]);
  152. }else{
  153. BusinessApply::create([
  154. 'uniacid' => \YunShop::app()->uniacid,
  155. 'uid' => \YunShop::app()->getMemberId(),
  156. 'name' => trim($request->name),
  157. 'logo_img' => trim($request->logo_img),
  158. 'status'=>BusinessApply::STATUS_WAIT,
  159. ]);
  160. }
  161. return $this->successJson('提交申请成功,请等待平台审核');
  162. }
  163. }