request->get(); $adminId = $this->adminId; if (getenv('YII_ENV') == 'production') { if ($adminId != 4) { util::fail('请联系管理员修改'); } } else { if ($adminId != 919) { util::fail('请联系管理员修改'); } } $name = $get['name'] ?? ''; if (empty($name)) { util::fail('请填写名称'); } $shop = $this->shop; $shop->merchantName = $name; $shop->save(); $sjId = $shop->sjId; $sj = MerchantClass::getById($sjId, true); if (empty($sj)) { util::fail('门店信息缺失呢'); } $sj->name = $name; $sj->save(); $fullName = $shop->shopName == '首店' ? $name : $name . ' ' . $shop->shopName; $shopId = $shop->id; $py = stringUtil::py($fullName); GhsClass::updateByCondition(['shopId' => $shopId], ['name' => $fullName, 'py' => $py]); util::complete('修改成功'); } //小程序端使用,下载收款码 ssh 20250821 public function actionMiniGatheringCode() { $shop = $this->shop; $lsShopId = $shop->lsShopId ?? 0; if (empty($lsShopId)) { util::fail('没有零售店ID'); } $lsShop = ShopClass::getById($lsShopId, true); if (empty($lsShop)) { util::fail('没有零售店呢'); } $sjId = $lsShop->sjId ?? 0; $imgUrl = \biz\shop\classes\ShopClass::generateGatheringCode($sjId, $lsShopId); util::success(['imgUrl' => $imgUrl]); } //修改客户微信二维码 ssh 20240714 public function actionChangeWx() { $get = Yii::$app->request->get(); $url = $get['url'] ?? ''; $shop = $this->shop; $shop->superWx = $url; $shop->save(); util::complete('修改成功'); } //我的可以进入的门店 ssh 20230424 public function actionMyShop() { $staff = $this->shopAdmin; $shopList = []; if (isset($staff->super) && $staff->super == 1) { $sjId = $this->sjId ?? 0; $shopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'ptStyle' => 2], null, 'id,shopName,merchantName,sjId,mainId,ptStyle', 'id'); } $adminId = $this->adminId; $staffList = ShopAdminClass::getAllByCondition(['adminId' => $adminId], null, '*', null, true); $mainIdList = []; if (!empty($staffList)) { foreach ($staffList as $staff) { $isPt = $staff->isPt ?? 0; $delStatus = $staff->delStatus ?? 0; //$super = $staff->super ?? 0; $mainId = $staff->mainId ?? 0; if ($isPt == 0 && $delStatus == 0) { $mainIdList[] = $mainId; } } } if (!empty($mainIdList)) { $addShopList = ShopClass::getAllByCondition(['mainId' => ['in', $mainIdList], 'ptStyle' => 2], null, 'id,shopName,merchantName,sjId,mainId,ptStyle', 'id'); if (!empty($addShopList)) { foreach ($addShopList as $addShop) { $addShopId = $addShop['id'] ?? 0; if (!isset($shopList[$addShopId])) { $shopList[$addShopId] = $addShop; } } } } $list = array_values($shopList); util::success(['list' => $list]); } //绑定零售店 ssh 20220430 public function actionBindLsShop() { $id = Yii::$app->request->get('id'); $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); util::fail('此方法已停用,如需启用请确认有没问题'); try { $shop = $this->shop ?? []; $lsShopId = $shop->lsShopId ?? 0; if (!empty($lsShopId)) { util::fail('您已经绑定过了'); } ShopClass::bindLsShopByCustomId($shop, $id, $this->adminId); $transaction->commit(); util::complete(); } catch (\Exception $exception) { $transaction->rollBack(); util::fail('绑定失败'); } } //预订设置 ssh 20220324 public function actionBookSet() { $get = Yii::$app->request->get(); $presell = $get['presell'] ?? 0; $this->shop->presell = $presell; $this->shop->save(); util::complete(); } //当前门店信息 public function actionInfo() { $shop = $this->shop ?? []; util::success($shop); } //获取当前门店信息 ssh 2021.3.27 public function actionCurrentShop() { $main = $this->shop; util::success($main); } //门店列表 ssh 2021.1.14 public function actionList() { $where = []; $where['sjId'] = $this->sjId; $where['delStatus'] = 0; $list = ShopClass::getShopList($where); util::success($list); } //更新门店 ssh 2020.2.29 public function actionUpdate() { $post = Yii::$app->request->post(); $post['sjId'] = $this->sjId; $id = $post['id'] ?? 0; $shop = ShopService::getById($id); if (empty($shop)) { util::fail('没有找到门店,编号657701'); } $staff = $this->shopAdmin; if (!isset($staff->finance) || $staff->finance == 0) { //花掌柜的小石,源花汇的小吕和小吴,没有财务权限也要能修改门店 if (!in_array($this->adminId, [4, 11961, 11976])) { util::fail('没有修改门店权限'); } } if (!isset($staff->super) || $staff->super == 0) { //花掌柜的小石,源花汇的小吕和小吴,没有改库存改价格权限也要能修改门店 if (!in_array($this->adminId, [4, 11961, 11976])) { util::fail('没有修改门店权限哦'); } } if ($this->mainId == 59421) { if (!in_array($this->adminId, [4])) { util::fail('已停用,请联系管理员'); } } $post['meetNum'] = isset($post['meetNum']) && !empty($post['meetNum']) ? $post['meetNum'] : 0; $post['meetAmount'] = isset($post['meetAmount']) && !empty($post['meetAmount']) ? $post['meetAmount'] : 0; $post['cutAmount'] = isset($post['cutAmount']) && !empty($post['cutAmount']) ? $post['cutAmount'] : 0; ShopClass::valid($shop, $this->sjId); //手机号具有唯一性,暂时不允许修改 --- 同零售端 app-hd/controllers/ShopController.php 保持一致 unset($post['mobile']); $post['img'] = isset($post['img']) && is_array($post['img']) ? json_encode($post['img']) : ''; \biz\shop\classes\ShopClass::updateShop($shop, $post); util::complete(); } // 更新门店头像 public function actionUpdateAvatar() { $post = Yii::$app->request->post(); $shopId = $post['shopId']; if ($post['shopId'] != $this->shopId or $this->mainId == 0) { util::fail('不是您的门店'); } $avatar = $post['avatar']; if ($avatar == '') { util::fail('头像地址不能为空'); } $shop = ShopClass::getById($shopId, true); $shop->avatar = $avatar; $shop->save(); $ptStyle = $shop['ptStyle'] ?? dict::getDict('ptStyle', 'hd'); $update = ['avatar' => $avatar]; $where = ['mainId' => $this->mainId]; if ($ptStyle == dict::getDict('ptStyle', 'ghs')) { GhsClass::updateByCondition($where, $update); } else { util::fail('门店头像更新失败,平台类型错误'); } $shopImg = imgUtil::groupImg($shop->avatar); $smallShopImg = imgUtil::groupImg($shop->avatar) . "?x-oss-process=image/resize,m_fill,h_80,w_80"; util::success(['shopImg' => $shopImg, 'smallShopImg' => $smallShopImg], '门店头像更新成功'); } //修改门店营业时间 public function actionUpdateOpenTime() { $post = Yii::$app->request->post(); $shopId = intval($post['shopId'] ?? $post['id'] ?? 0); if ($shopId <= 0) { $shopId = intval($this->shopId); } if ($shopId != intval($this->shopId)) { util::fail('不是您的门店'); } $shop = ShopClass::getById($shopId); if (empty($shop)) { util::fail('门店不存在'); } \biz\shop\classes\ShopClass::valid($shop, $this->sjId); \biz\shop\classes\ShopClass::updateOpenTime($shop, $post); util::complete('修改成功'); } //添加门店 ssh 2021.1.14 public function actionAdd() { $shop = $this->shop; $default = $shop->default ?? 0; if ($default == 0) { util::fail('当前直营分店,请切回总店添加'); } $adminId = $this->adminId; $ptSuperAdminId = \biz\admin\classes\AdminClass::getPtSuperAdminId(); if ($adminId != $shop->adminId && $adminId != $ptSuperAdminId) { util::fail('本店超管才能添加门店'); } $mainId = $this->mainId; if (getenv('YII_ENV') == 'production') { if ($mainId == 42490) { util::fail('无法建分店,请联系石头'); } } else { if ($mainId == 644) { util::fail('无法建分店,请联系石头'); } } $data = Yii::$app->request->post(); $data['sjId'] = $this->sjId; $data['shopId'] = $this->shopId; $data['adminId'] = $this->adminId; if (isset($data['shopName']) == false || empty($data['shopName'])) { util::fail('请填写门店名称'); } $sj = $this->sj; $sjName = $sj->name ?? ''; $ptStyle = $sj->style ?? dict::getDict('ptStyle', 'hd'); $data['ptStyle'] = $ptStyle; $data['merchantName'] = $sjName; $data['default'] = 0; $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $mobile = $data['mobile'] ?? 0; if (stringUtil::isMobile($mobile) == false) { util::fail('请填写正确手机号'); } $adminInfo = ['name' => $mobile, 'mobile' => $mobile]; $fromApp = dict::getDict('userSourceGetId', 'app', 'id'); $admin = AdminClass::replaceAdmin($adminInfo, $fromApp); $adminId = $admin['id'] ?? 0; $data['adminId'] = $adminId; ShopClass::addMainShop($data, $this->shop, $this->sj); $transaction->commit(); util::complete(); } catch (\Exception $exception) { $transaction->rollBack(); util::fail(); } } //PC下载微信和支付宝收款码 ssh 2020.2.29 public function actionGatheringCode() { $id = Yii::$app->request->get('id', 0); $shop = ShopService::getById($id); ShopClass::valid($shop, $this->sjId); $gatheringCode = ShopClass::generateGatheringCode($this->sjId, $id); $file = dirUtil::getImgDir() . $gatheringCode; if (file_exists($file) == false) { util::fail('没有找到收款码'); } if (httpUtil::isMiniProgram()) { $imgUrl = imgUtil::getPrefix() . $gatheringCode; util::success(['imgUrl' => $imgUrl]); } $fileName = "门店({$id})收款码.jpg"; $contentType = 'image/jpeg'; header("Cache-control: private"); header("Content-type: $contentType"); //设置要下载的文件类型 header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小 header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名 readfile($file); } //PC获取小程序的收款码 ssh public function actionGatheringMiniCode() { $id = Yii::$app->request->get('id', 0); $extend = MerchantExtendService::getBySjId($this->sjId); if ($extend['miniAuth'] == 0) { util::fail('您的小程序还没有授权'); } $shop = ShopService::getById($id); ShopClass::valid($shop, $this->sjId); $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj->attributes, $id); $file = dirUtil::getImgDir() . $applyMemberCode; if (file_exists($file) == false) { util::fail('没有找到注册会员码'); } if (httpUtil::isMiniProgram()) { $imgUrl = imgUtil::getPrefix() . $applyMemberCode; util::success(['imgUrl' => $imgUrl]); } $fileName = "门店({$id})小程序收款码.jpg"; $contentType = 'image/jpeg'; header("Cache-control: private"); header("Content-type: $contentType"); //设置要下载的文件类型 header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小 header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名 readfile($file); } //PC下载会员注册码 ssh 2020.2.29 public function actionApplyMemberCode() { $id = Yii::$app->request->get('id', 0); $extend = MerchantExtendService::getBySjId($this->sjId); if ($extend['miniAuth'] == 0) { util::fail('您的小程序还没有授权'); } $shop = ShopService::getById($id); ShopClass::valid($shop, $this->sjId); $applyMemberCode = wxUtil::generateMemberCode($this->sj->attributes, $id); $file = dirUtil::getImgDir() . $applyMemberCode; if (file_exists($file) == false) { util::fail('没有找到注册会员码'); } if (httpUtil::isMiniProgram()) { $imgUrl = imgUtil::getPrefix() . $applyMemberCode; util::success(['imgUrl' => $imgUrl]); } $fileName = "注册会员码{$id}.jpg"; $contentType = 'image/jpeg'; header("Cache-control: private"); header("Content-type: $contentType"); //设置要下载的文件类型 header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小 header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名 readfile($file); } //删除门店 ssh 2020.3.1 public function actionDelete() { util::fail('禁止操作'); $id = Yii::$app->request->get('id', 0); $shop = ShopService::getById($id); ShopClass::valid($shop, $this->sjId); ShopClass::deleteShop($shop); util::complete(); } //获取所有门店lqh 2021.1.31 public function actionAll() { $res = ShopClass::getAllShop($this->sjId); util::success($res); } //切换门店 lqh 2021.1.31 public function actionToggleShop() { $mainId = $this->mainId; $adminId = $this->adminId; //多处要同步修改,关键词 no_allow_toggle_shop if (getenv('YII_ENV') == 'production') { //安海恋善不允许切换门店 if (in_array($mainId, [44759, 56314, 56315, 56452])) { if (in_array($adminId, [54630, 54723])) { util::fail('专用账号,不允许切换门店'); } } //惠雅南城不允许切换门店 if ($mainId == 52 && $adminId == 3539) { util::fail('收银专用账号,不允许切换门店'); } //惠雅莞城不允许切换门店 if ($mainId == 1459 && $adminId == 2812) { util::fail('收银专用账号,不允许切换门店'); } //淘花里中山店 if ($mainId == 16948 && $adminId == 17908) { util::fail('收银专用账号,不允许切换门店'); } //淘花里小榄店 if ($mainId == 72057 && $adminId == 69792) { util::fail('收银专用账号,不允许切换门店'); } } $shopAdmin = $this->shopAdmin; $switchShop = ShopAdminClass::hasSwitchShopRight($shopAdmin); if ($switchShop == 0) { util::fail('不能切换门店'); } $newShopId = Yii::$app->request->post('shopId', 0); $deviceId = Yii::$app->request->post('deviceId', ''); $newShop = ShopClass::getById($newShopId, true); if (empty($newShop)) { util::fail('没有找到门店66'); } $res = AdminClass::toggleShop($this->admin, $newShop, $this->sjId, $this->shopAdmin); if ($deviceId != '') { //设备登录状态更新 $oldDevice = \bizGhs\device\classes\GhsDeviceClass::getByCondition(['shopId'=>$this->shopId, 'deviceId'=>$deviceId], true); if ($oldDevice) { $oldDevice->status = 0; $oldDevice->save(); } $newLoginDevice = \bizGhs\device\classes\GhsDeviceClass::getByCondition(['shopId'=>$newShop, 'deviceId'=>$deviceId], true); if ($newLoginDevice) { $newLoginDevice->status = 1; $newLoginDevice->save(); } } util::success($res); } //提现信息更新 ssh 2021.3.23 public function actionCashUpdate() { $get = Yii::$app->request->get(); $cashAccount = $get['cashAccount'] ?? ''; $cashName = $get['cashName'] ?? ''; $cashBank = $get['cashBank'] ?? ''; if (empty($cashName)) { util::fail('请填写姓名'); } if (empty($cashAccount)) { util::fail('请填写银行卡号'); } if (empty($cashBank)) { util::fail('请输入开户行'); } $shopAdmin = $this->shopAdmin; $mainId = $shopAdmin->mainId ?? 0; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('超管才能操作'); } MainClass::updateById($mainId, ['cashAccount' => $cashAccount, 'cashName' => $cashName, 'cashBank' => $cashBank]); $shop = $this->shop; $sjName = $shop->merchantName ?? ''; $shopName = $shop->shopName ?? ''; //noticeUtil::push("{$sjName}-{$shopName} 修改提现账号,{$cashName} {$cashAccount} {$cashBank}", '15280215347'); util::complete(); } //获取门店详情 ssh 2021.4.23 public function actionDetail() { $shopId = Yii::$app->request->get('shopId'); if (empty($shopId)) { $shopId = $this->shopId; } $shop = ShopClass::getById($shopId, true); if ($shop->mainId != $this->mainId) { //这个注释不能打开,因为首店可能修改其它分店信息 //util::fail('无法查看'); } $shop = $shop->toArray(); $shop['hasMap'] = dict::getDict('hasMap'); //添加 hasMap 属性(字典中的 hasMap) util::success(['info' => $shop]); } //获取平台所有的供货商门店 ssh 20210908 public function actionGetPtGhsShop() { $hasSale = Yii::$app->request->get('hasSale', 0); $name = Yii::$app->request->get('name', ''); $arr = ['ptStyle' => 2, 'live' => 1]; if (!empty($name)) { $arr['merchantName'] = ['like', $name]; $hasSale = 0; } $shopList = ShopClass::getAllByCondition($arr, 'id asc', '*'); $totalSale = 0; $totalShopNum = 0; $totalBalance = 0; if (!empty($shopList)) { foreach ($shopList as $key => $shop) { $mainId = $shop['mainId'] ?? 0; $main = MainClass::getById($mainId, true); $balance = $main->balance ?? 0; if (!empty($name) || $hasSale == 0) { $incomeList = []; } else { $respond = StatSaleClass::profile($mainId); $incomeList = $respond['income'] ?? []; } $todaySale = 0; if (!empty($incomeList)) { foreach ($incomeList as $item) { //调拨出库暂时不算到收入里去 if (isset($item['id']) && $item['id'] == 'allot') { continue; } $todaySale = bcadd($todaySale, $item['amount'], 2); } } $shopList[$key]['balance'] = $balance; $shopList[$key]['todaySale'] = $todaySale; $count = CustomClass::getCount(['ownMainId' => $mainId]); $count = $count > 0 ? $count : 0; $shopList[$key]['shopNum'] = $count; if ($hasSale == 1 && $todaySale <= 0) { unset($shopList[$key]); } $totalSale = bcadd($totalSale, $todaySale, 2); $totalSale = floatval($totalSale); $totalBalance = bcadd($totalBalance, $balance, 2); $totalBalance = floatval($totalBalance); $totalShopNum = bcadd($totalShopNum, $count); } $shopList = arrayUtil::arraySort($shopList, 'todaySale'); } util::success(['list' => $shopList, 'totalSale' => $totalSale, 'totalBalance' => $totalBalance, 'totalShopNum' => $totalShopNum]); } //切换门店 ssh 20220624 public function actionSwitchGhsShop() { $shopId = Yii::$app->request->get('shopId', 0); $shop = ShopClass::getById($shopId, true); if (empty($shop)) { util::fail('没有找到门店67'); } $shopAdmin = $this->shopAdmin; $admin = $this->admin; $adminId = $this->adminId ?? 0; if (getenv('YII_ENV') == 'production') { if (in_array($adminId, [4]) == false) { util::fail('开发中'); } } else { if (in_array($adminId, [919]) == false) { util::fail('开发中'); } } ShopAdminClass::changeShopAddRelate($shopAdmin, $shop, 1); $admin->currentGhsShopId = $shopId; $lsShopId = $shop->lsShopId ?? 0; $admin->currentShopId = $lsShopId; $admin->save(); util::complete(); } //散客门店详情 ssh 20211007 public function actionSkCustom() { $skCustomId = $this->shop->skCustomId ?? 0; $custom = []; if (!empty($skCustomId)) { $custom = CustomClass::getById($skCustomId); $avatar = $custom['avatar'] ?? ''; $custom['avatar'] = imgUtil::groupImg($avatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130"; } util::success(['custom' => $custom]); } //散客门店设置 public function actionSkCustomSet() { $id = Yii::$app->request->get('id', 0); $custom = CustomClass::getById($id, true); CustomClass::valid($custom, $this->shopId); $this->shop->skCustomId = $id; $this->shop->save(); util::complete('修改成功'); } //运费模式和运费成本设置 ssh 20211014 public function actionUpdateCgModel() { $get = Yii::$app->request->get(); $cgModel = $get['cgModel'] ?? 0; $cgPerCost = $get['cgPerCost'] ?? 0; if ($cgModel == 1) { if (is_numeric($cgPerCost) == false || $cgPerCost < 0) { util::fail('请输入运费成本'); } $this->shop->cgPerCost = $cgPerCost; } $this->shop->cgModel = $cgModel; $this->shop->save(); util::complete('修改成功'); } //地区 ssh 20220606 public function actionRegion() { $regionTree = RegionService::tree(); util::success(['region' => $regionTree]); } //获取购买须知信息 public function actionPurchaseGuide() { $shopId = intval($this->shopId); if ($shopId <= 0) { util::fail('门店数据错误'); } $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, shopId, purchaseGuide,purchaseGuideText'); if ($shopExt['purchaseGuide'] > 0) { $picText = PicTextClass::getById($shopExt['purchaseGuide'], false, 'id, title'); $shopExt['title'] = $picText['title'] ?? ''; } $shop = $this->shop; util::success(['shopExt' => $shopExt, 'shop' => $shop]); } }