| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <?php
- namespace bizGhs\merchant\classes;
- use bizGhs\cp\classes\CpClass;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\shop\classes\MainClass;
- use bizGhs\shop\classes\ShopAdminClass;
- use bizHd\ad\classes\AdClass;
- use bizHd\goods\classes\CategoryClass;
- use bizHd\goods\classes\GoodsSettingClass;
- use bizHd\merchant\services\SjService;
- use bizHd\saas\classes\ApplyClass;
- use common\components\dict;
- use common\components\httpUtil;
- use common\components\qrCodeUtil;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- use bizHd\base\classes\BaseClass;
- use common\components\imgUtil;
- class ShopClass extends BaseClass
- {
- public static $baseFile = '\bizGhs\merchant\models\Shop';
- public static function addMainShop($data, $oldGhsShop, $sj)
- {
- if (isset($oldGhsShop->lsShopId) == false || empty($oldGhsShop->lsShopId)) {
- util::fail('本店请先绑定零售店');
- }
- $mobile = $data['mobile'] ?? 0;
- if (empty($mobile) || stringUtil::isMobile($mobile) == false) {
- util::fail('请输入正确手机号');
- }
- $hasShop = ShopClass::getByCondition(['mobile' => $mobile], true);
- if (!empty($hasShop)) {
- util::fail('手机号已经使用');
- }
- $hasApply = ApplyClass::getByCondition(['mobile' => $mobile], true);
- if (!empty($hasApply)) {
- util::fail('手机号已注册过');
- }
- $defaultShopId = $sj['defaultShopId'] ?? 0;
- $defaultShop = ShopClass::getById($defaultShopId, true);
- if (empty($defaultShop)) {
- util::fail('没有找到门店76');
- }
- $oldMainId = $defaultShop->mainId ?? 0;
- if (empty($oldMainId)) {
- util::fail('没有找到main信息');
- }
- //创建main和复制花材
- $main = MainClass::addMainCopyItem($oldMainId);
- $mainId = $main->id ?? 0;
- //复制产品
- // $copyKey = 'copy_old_cp_to_new_cp';
- // $copyValue = json_encode(['oldMainId' => $oldMainId, 'newMainId' => $mainId]);
- // Yii::$app->redis->executeCommand('LPUSH', [$copyKey, $copyValue]);
- $data['mainId'] = $mainId;
- $newGhsShop = \bizGhs\shop\classes\ShopClass::addShop($data);
- $lsOldShop = ShopClass::getById($oldGhsShop->lsShopId, true);
- $data['sjId'] = $lsOldShop->sjId ?? 0;
- $data['ptStyle'] = dict::getDict('ptStyle', 'hd');
- $newLsShop = \bizHd\shop\classes\ShopClass::addShop($data);
- $newLsShop->pfShopId = $newGhsShop->id ?? 0;
- $newLsShop->save();
- $newGhsShop->lsShopId = $newLsShop->id ?? 0;
- $newGhsShop->save();
- return $newGhsShop;
- }
- //组装门店基本信息 ssh 2019.12.2
- public static function groupBaseInfo($list)
- {
- foreach ($list as $key => $val) {
- $shortAvatar = $val['avatar'] ?? '';
- $list[$key]['avatar'] = imgUtil::groupImg($shortAvatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
- if (empty($val['img'])) {
- $list[$key]['img'] = [];
- $list[$key]['imgUrl'] = [];
- continue;
- }
- $list[$key]['img'] = json_decode($val['img'], true);
- if (isset($list[$key]['img']) && is_array($list[$key]['img'])) {
- foreach ($list[$key]['img'] as $img) {
- $list[$key]['imgUrl'][] = imgUtil::groupImg($img);
- }
- }
- }
- return $list;
- }
- public static function getShopList($where)
- {
- $list = self::getList('*', $where, 'addTime DESC');
- $list['list'] = self::groupBaseInfo($list['list']);
- return $list;
- }
- //获取商家默认的门店ID ssh 2020.1.19
- public static function getDefaultShopId($merchant)
- {
- return isset($merchant['defaultShopId']) ? $merchant['defaultShopId'] : 0;
- }
- //取商家所有门店 ssh 2020.2.29
- public static function getAllShop($sjId)
- {
- return self::getAllByCondition(['sjId' => $sjId], null, 'id,shopName,avatar');
- }
- //验证权限 ssh 2021.1.14
- public static function valid($shop, $sjId)
- {
- if (isset($shop['sjId']) && $shop['sjId'] == $sjId) {
- return true;
- }
- util::fail('您无法访问此店铺');
- }
- //删除门店 ssh 2020.3.1
- public static function deleteShop($shop)
- {
- if (isset($shop['default']) && $shop['default'] == 1) {
- util::fail('默认门店不允许删除');
- }
- $id = $shop['id'];
- self::updateById($id, ['delStatus' => 1]);
- }
- //生成收款码 ssh 2021.1.14
- public static function generateGatheringCode($sjId, $shopId)
- {
- $url = Yii::$app->params['ghsDomain'] . "/#/pages/pay/index?account={$sjId}&shopId=" . $shopId;
- //强制转成https
- $url = httpUtil::becomeHttps($url);
- $gatheringCode = qrCodeUtil::generateGatheringQrCode($url, $sjId, $shopId, '', 10);
- return $gatheringCode;
- }
- //绑定零售店 ssh 20220430
- public static function bindLsShopByCustomId($ghsShop, $id, $adminId)
- {
- $ghsShopId = $ghsShop->id ?? 0;
- $ghsMainId = $ghsShop->mainId ?? 0;
- if (empty($ghsMainId)) {
- util::fail('没有找到你的main信息');
- }
- $ghsMain = MainClass::getById($ghsMainId, true);
- if (empty($ghsMain)) {
- util::fail('没有找到main信息');
- }
- $ghsMobile = $ghsShop->mobile ?? 0;
- if (empty($ghsMobile)) {
- util::fail('手机号有问题?');
- }
- $customMobile = 0;
- $customShop = null;
- $customShopId = 0;
- if (!empty($id)) {
- $custom = CustomClass::getById($id, true);
- if (empty($custom)) {
- util::fail('门店信息没有找到');
- }
- $customShopId = $custom->shopId ?? 0;
- $customShop = self::getById($customShopId, true);
- if (isset($customShop->pfShopId) && !empty($customShop->pfShopId)) {
- util::fail('这个零售店已经绑定了批发店');
- }
- $customMobile = $customShop->mobile ?? 0;
- }
- if ($ghsMobile != $customMobile) {
- //如果绑定的零售店跟批发店手机号不一样,则先查批发店这个手机号有没创建过零售店,没有则自动给创建,有则提醒选的零售店不对
- $has = ShopClass::getByCondition(['mobile' => $ghsMobile, 'ptStyle' => dict::getDict('ptStyle', 'hd')], true);
- if (!empty($has) && !empty($id)) {
- util::fail('请确认此零售店开通时用的手机号与本批发店一致?');
- } else {
- //创建零售店
- $hdInitData = $ghsShop->attributes ?? [];
- $hdInitData['adminId'] = $adminId;
- $hdInitData['name'] = $hdInitData['merchantName'] ?? '';
- $respond = SjService::initHdBaseInfo($hdInitData, $ghsMain, true);
- $customShop = $respond['shop'] ?? [];
- if (empty($customShop)) {
- util::fail('没有生成门店');
- }
- $customShopId = $customShop->id ?? 0;
- }
- } else {
- //商品和分类初始化
- CategoryClass::initCategoryGoods($ghsMainId);
- //商城和门店广告初始化
- AdClass::initAdd($ghsMainId);
- //商家商品配置信息
- $setData = ['mainId' => $ghsMainId, 'riseType' => 0, 'riseAmount' => 0];
- GoodsSettingClass::add($setData);
- }
- $customShop->mainId = $ghsMainId;
- $customShop->pfShopId = $ghsShopId;
- $customShop->save();
- $ghsShop->lsShopId = $customShopId;
- $ghsShop->save();
- //允许员工登录零售店
- $staffList = ShopAdminClass::getAllByCondition(['mainId' => $ghsMainId], null, '*', null, true);
- if (!empty($staffList)) {
- foreach ($staffList as $staff) {
- $adminId = $staff->adminId ?? 0;
- $admin = AdminClass::getById($adminId, true);
- if (!empty($admin)) {
- $admin->currentShopId = $customShopId;
- $admin->save();
- }
- }
- }
- }
- }
|