| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607 |
- <?php
- namespace hd\controllers;
- use biz\shop\classes\ShopClass;
- use biz\sj\services\MerchantExtendService;
- use bizGhs\admin\classes\AdminClass;
- use bizGhs\custom\classes\CustomClass;
- use bizHd\admin\classes\ShopAdminClass;
- use bizHd\custom\classes\CustomClass as HdCustomClass;
- use bizHd\custom\classes\HdClass;
- use bizHd\merchant\classes\SjClass;
- use bizHd\merchant\services\ShopService;
- use bizHd\purchase\classes\PurchaseClass;
- use bizHd\saas\services\RegionService;
- use bizHd\shop\classes\ShopExtClass;
- use common\components\dict;
- use common\components\dirUtil;
- use common\components\imgUtil;
- use common\components\stringUtil;
- use common\components\util;
- use common\components\wxUtil;
- use Yii;
- class ShopController extends BaseController
- {
- public $guestAccess = ['all', 'gathering-img-url', 'check-shop'];
- public function actionModifySjName()
- {
- $get = Yii::$app->request->get();
- $adminId = $this->adminId;
- $staff = $this->shopAdmin;
- if ($staff->founder != 2 && $adminId != 4) {
- util::fail('老板才能改店名');
- }
- $name = $get['name'] ?? '';
- if (empty($name)) {
- util::fail('请填写名称');
- }
- //开启事务
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $shop = $this->shop;
- $shop->merchantName = $name;
- $shop->save();
- $sj = SjClass::getById($shop->sjId, true);
- if (empty($sj)) {
- util::fail('门店信息缺失呢');
- }
- $sj->name = $name;
- $sj->save();
- $fullName = $shop->shopName == '首店' ? $name : $name . ' ' . $shop->shopName;
- $shopId = $shop->id;
- HdClass::updateByCondition(['shopId' => $shopId], ['name' => $fullName]);
- CustomClass::updateByCondition(['shopId' => $shopId], ['originName' => $fullName]);
- $transaction->commit();
- util::complete('修改成功');
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::error("修改门店名称失败:" . $exception->getMessage());
- util::fail('修改门店名称失败');
- }
- }
- //我的可以进入的门店 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' => 1], null, 'id,shopName,merchantName,sjId,mainId,ptStyle', 'id');
- }
- $adminId = $this->adminId ?? 0;
- $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' => 1], null, 'id,shopName,merchantName,sjId,mainId,ptStyle', 'id');
- if (!empty($addShopList)) {
- foreach ($addShopList as $addShop) {
- $addShopId = $addShop['id'] ?? 0;
- if (isset($shopList[$addShopId]) == false) {
- $shopList[$addShopId] = $addShop;
- }
- }
- }
- }
- $list = array_values($shopList);
- util::success(['list' => $list]);
- }
- //是否开启完整功能 ssh 20230226
- public function actionChangeOnlyCg()
- {
- $shop = $this->shop;
- $get = Yii::$app->request->get();
- $onlyCg = $get['onlyCg'] ?? 1;
- $shop->onlyCg = $onlyCg;
- $shop->save();
- util::complete('操作成功');
- }
- public function actionCheckShop()
- {
- $get = Yii::$app->request->get();
- $mobile = $get['mobile'] ?? '';
- if(empty($mobile)){
- util::success(['has' => 0]);
- }
- $shop = ShopClass::getByCondition(['mobile' => $mobile], true);
- if (!empty($shop)) {
- util::success(['has' => 1]);
- }
- util::success(['has' => 0]);
- }
- //获取当前门店信息 ssh 2021.3.27
- public function actionCurrentShop()
- {
- $shopExt = ShopExtClass::getByCondition(['shopId' => $this->shop->id], false, false, 'reachVip');
- $shop = $this->shop->attributes;
- $shop['reachVip'] = $shopExt['reachVip'];
- util::success($shop);
- }
- //门店列表 ssh 20202.2.29
- public function actionList()
- {
- $where = [];
- $where['sjId'] = $this->sjId;
- $where['delStatus'] = 0;
- $list = \bizHd\shop\classes\ShopClass::getShopList($where);
- util::success($list);
- }
- //更新门店 ssh 2020.2.29
- public function actionUpdate()
- {
- $data = Yii::$app->request->post();
- $data['sjId'] = $this->sjId;
- $id = isset($data['id']) ? $data['id'] : 0;
- unset($data['id']);
- $data['meetNum'] = isset($data['meetNum']) ? intval($data['meetNum']) : 0;
- $data['meetAmount'] = isset($data['meetAmount']) ? floatval($data['meetAmount']) : 0;
- $data['cutAmount'] = isset($data['cutAmount']) ? floatval($data['cutAmount']) : 0;
- $shop = ShopService::getById($id);
- ShopClass::valid($shop, $this->sjId);
- $data['img'] = isset($data['img']) && is_array($data['img']) ? json_encode($data['img']) : '';
- //手机号具有唯一性,暂时不允许修改 --- 同批发端 app-ghs/controllers/ShopController.php 保持一致
- unset($data['mobile']);
- // 添加事务处理
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- ShopClass::updateShop($shop, $data);
- $transaction->commit();
- util::complete();
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::error("更新门店失败:" . $exception->getMessage());
- util::fail('更新门店失败');
- }
- }
- //修改门店营业时间
- 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::getShopInfo($shopId);
- if (empty($shop)) {
- util::fail('门店不存在');
- }
- ShopClass::valid($shop, $this->sjId);
- ShopClass::updateOpenTime($shop, $post);
- util::complete('修改成功');
- }
- public function actionAdd()
- {
- $data = Yii::$app->request->post();
- $data['sjId'] = $this->sjId;
- $data['shopId'] = $this->shopId;
- if (isset($data['shopName']) == false || empty($data['shopName'])) {
- util::fail('请填写门店名称');
- }
- $sj = $this->sj;
- $sjName = $sj->name ?? '';
- $data['merchantName'] = $sjName;
- $ptStyle = $sj->style ?? dict::getDict('ptStyle', 'hd');
- $data['ptStyle'] = $ptStyle;
- $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;
- \bizHd\shop\classes\ShopClass::addMainShop($data, $this->shop, $this->sj);
- $transaction->commit();
- util::complete();
- } catch (\Exception $exception) {
- $transaction->rollBack();
- util::fail();
- }
- }
- //切换门店 lqh 2021.1.31
- public function actionToggleShop()
- {
- $adminId = $this->adminId;
- $mainId = $this->mainId;
- //多处要同步修改,关键词 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 = \biz\shop\classes\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('没有找到门店30');
- }
- $res = \bizHd\admin\classes\AdminClass::toggleShop($this->admin, $newShop, $this->sjId, $this->shopAdmin);
- if ($deviceId != '') {
- //设备登录状态更新
- $oldDevice = \bizHd\device\classes\HdDeviceClass::getByCondition(['shopId' => $this->shopId, 'deviceId' => $deviceId], true);
- if ($oldDevice) {
- $oldDevice->status = 0;
- $oldDevice->save();
- }
- $newLoginDevice = \bizHd\device\classes\HdDeviceClass::getByCondition(['shopId' => $newShopId, 'deviceId' => $deviceId], true);
- if ($newLoginDevice) {
- $newLoginDevice->status = 1;
- $newLoginDevice->save();
- }
- }
- util::success($res);
- }
- //网页端使用,下载微信和支付宝收款码 ssh 20250821
- public function actionGatheringCode()
- {
- $id = Yii::$app->request->get('id', 0);
- $shop = ShopService::getById($id, true);
- if (empty($shop)) {
- util::fail('没有找到门店31');
- }
- ShopClass::valid($shop->attributes, $this->sjId);
- $imgUrl = ShopClass::generateGatheringCode($this->sjId, $id);
- $shopName = $shop->shopName ?? '';
- $file = fopen($imgUrl, "rb");
- Header("Content-type: application/octet-stream ");
- Header("Accept-Ranges: bytes ");
- Header("Content-Disposition: attachment;filename={$shopName}收款码.jpg");
- $contents = "";
- while (!feof($file)) {
- $contents .= fread($file, 8192);
- }
- echo $contents;
- fclose($file);
- }
- //小程序端使用,下载收款码 ssh 20250821
- public function actionMiniGatheringCode()
- {
- $shop = $this->shop;
- $shopId = $shop->id;
- $imgUrl = ShopClass::generateGatheringCode($this->sjId, $shopId);
- util::success(['imgUrl' => $imgUrl]);
- }
- //获取二维码
- public function actionGetGatheringCodeUrl()
- {
- $id = Yii::$app->request->get('id', 0);
- $shop = ShopService::getById($id, true);
- if (empty($shop)) {
- util::fail('没有找到门店32');
- }
- ShopClass::valid($shop->attributes, $this->sjId);
- $imgUrl = Yii::$app->params['hdHost'] . '/auth/gathering-img-url?id=' . $id;
- util::success(['url' => $imgUrl]);
- }
- public function actionGatheringImgUrl()
- {
- $id = Yii::$app->request->get('id', 0);
- $shop = ShopService::getById($id, true);
- if (empty($shop)) {
- util::fail('没有找到门店33');
- }
- $sjId = $shop->sjId;
- $imgUrl = ShopClass::generateGatheringCode($sjId, $id);
- $fileResource = file_get_contents($imgUrl);
- header('Content-type: image/jpeg');
- echo $fileResource;
- }
- //获取小程序的收款码 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);
- ShopService::valid($shop, $this->sjId);
- $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj->attributes, $id);
- $file = dirUtil::getImgDir() . $applyMemberCode;
- if (file_exists($file) == false) {
- util::fail('没有找到注册会员码');
- }
- $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.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);
- ShopService::valid($shop, $this->sjId);
- $applyMemberCode = wxUtil::generateMemberCode($this->sj->attributes, $id);
- $file = dirUtil::getImgDir() . $applyMemberCode;
- if (file_exists($file) == false) {
- util::fail('没有找到注册会员码');
- }
- $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);
- util::fail('功能开发中');
- $shop = ShopService::getById($id);
- ShopService::valid($shop, $this->sjId);
- ShopService::deleteShop($shop);
- util::complete();
- }
- //获取门店详情 ssh 2021.4.23
- public function actionDetail()
- {
- $shopId = Yii::$app->request->get('shopId');
- if (empty($shopId)) {
- $shopId = $this->shopId;
- }
- $shop = ShopClass::getShopInfo($shopId);
- $shop['hasMap'] = dict::getDict('hasMap'); //添加 hasMap 属性(字典中的 hasMap)
- util::success(['info' => $shop]);
- }
- //提现信息更新 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;
- $shopId = $shopAdmin->shopId ?? 0;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能操作');
- }
- ShopClass::updateById($shopId, ['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();
- }
- //获取所有门店lqh 2021.1.31
- public function actionAll()
- {
- $res = [];
- $shopAdmin = isset($this->shopAdmin) && !empty($this->shopAdmin) ? $this->shopAdmin->attributes : [];
- if (isset($shopAdmin['super']) && $shopAdmin['super'] == 1) {
- $res = ShopClass::getAllShop($this->sjId);
- }
- util::success($res);
- }
- //获取采购时的支付方式 ssh 20211004
- public function actionGetCgPayWay()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $cg = PurchaseClass::getById($id, true);
- PurchaseClass::valid($cg, $this->shopId);
- $customId = $cg->customId ?? 0;
- $custom = CustomClass::getById($customId);
- $hasDebtPay = $custom['debt'] ?? 0;
- //预订单不能欠款
- if ($cg->book == 1) {
- $hasDebtPay = 0;
- }
- $current = time();
- $cgDeadTime = strtotime($cg->deadline);
- //让客户在失效前$aheadTime秒要支付,这样回调通知时订单才不会过期状态
- $aheadTime = dict::getDict('order_online_pay_has_ahead_time');
- $count = $cgDeadTime - $current - $aheadTime;
- $data = [];
- $data['balance'] = $this->shop->balance ?? 0;
- $data['count'] = $count;
- $data['hasDebtPay'] = $hasDebtPay;
- util::success($data);
- }
- //地区 ssh 20220606
- public function actionRegion()
- {
- $regionTree = RegionService::tree();
- util::success(['region' => $regionTree]);
- }
- //散客门店详情 ssh 20211007
- public function actionKjCustom()
- {
- $defaultCustomId = $this->shop->defaultCustomId ?? 0;
- $custom = [];
- if (!empty($defaultCustomId)) {
- $custom = HdCustomClass::getById($defaultCustomId);
- $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 actionKjCustomSet()
- {
- $id = Yii::$app->request->get('id', 0);
- $custom = HdCustomClass::getById($id, true);
- if (empty($custom)) {
- util::fail('没有找到客户');
- }
- if ($custom->shopId != $this->shopId) {
- util::fail('客户不属于当前门店');
- }
- $shop = $this->shop;
- $shop->defaultCustomId = $id;
- $shop->save();
- util::complete('修改成功');
- }
- public function actionUpdateShopAvatar()
- {
- $data = Yii::$app->request->post();
- $id = isset($data['id']) ? $data['id'] : 0;
- $shop = ShopClass::getById($id, true, 'id, sjId, avatar');
- ShopService::valid($shop, $this->sjId);
- if (isset($data['avatar']) && $data['avatar'] != '') {
- $shop->avatar = $data['avatar'];
- $re = $shop->save();
- if ($re) {
- \bizGhs\custom\classes\CustomClass::updateByCondition(['shopId' => $id], [
- 'avatar' => $data['avatar']
- ]);
- util::complete('头像修改完成');
- }
- util::fail('头像修改失败');
- }
- util::fail('头像参数出错');
- }
- //获取充值设置
- public function actionGetRechargeSetting()
- {
- $shopId = $this->shop->id;
- $shop = ShopClass::getById($shopId, false, 'rechargeWeal');
- $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'reachVip');
- $return = [
- 'rechargeRule' => $shop['rechargeWeal'] == 3 ? 2 : $shop['rechargeWeal'],
- 'isVipMember' => $shopExt['reachVip'] > 0 ? 1 : 0,
- 'vipAmount' => $shopExt['reachVip'],
- 'hbPayable' => $shop['rechargeWeal'] == 2 ? 1 : 0,
- ];
- util::success($return);
- }
- //充值设置
- public function actionSaveRechargeSetting()
- {
- $data = Yii::$app->request->post();
- $rechargeWeal = intval($data['rechargeRule']);
- $isVipMember = intval($data['isVipMember']);
- if ($isVipMember == 1 && $data['vipAmount'] >= 0.01) {
- $reachVip = floatval($data['vipAmount']);
- } else {
- $reachVip = 0;
- }
- $hbPayable = intval($data['hbPayable']);
- if ($rechargeWeal == 2 && $hbPayable == 0) {
- $rechargeWeal = 3;
- }
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能操作');
- }
- $shopId = $this->shop->id;
- ShopClass::updateById($shopId, ['rechargeWeal' => $rechargeWeal]);
- ShopExtClass::updateByCondition(['shopId' => $shopId], ['reachVip' => $reachVip]);
- util::complete('充值设置成功');
- }
- }
|