| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- <?php
- namespace bizHd\shop\classes;
- use biz\shop\classes\ShopExtClass;
- use bizHd\ad\classes\AdClass;
- use bizHd\admin\classes\AdminClass;
- use bizHd\goods\classes\CategoryClass;
- use bizHd\goods\classes\GoodsSettingClass;
- use bizHd\merchant\classes\SjClass;
- use bizHd\saas\classes\ApplyClass;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\noticeUtil;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- use bizHd\base\classes\BaseClass;
- class ShopClass extends BaseClass
- {
- public static $baseFile = '\bizHd\shop\models\Shop';
- //是否营业状态 ssh 20251219
- public static function getOpenShop($shop)
- {
- $openShop = 1;
- if ($shop['open'] == 0) {
- $openShop = 0;
- } else {
- $openStartTime = $shop['openStartTime'] ?? '';
- $openEndTime = $shop['openEndTime'] ?? '';
- if (!empty($openStartTime) && !empty($openEndTime)) {
- $start = date('Y-m-d') . ' ' . $openStartTime;
- $startTime = strtotime($start);
- $end = date('Y-m-d') . ' ' . $openEndTime;
- $endTime = strtotime($end);
- $currentTime = time();
- if ($currentTime < $startTime || $currentTime > $endTime) {
- $openShop = 0;
- }
- }
- }
- return $openShop;
- }
- //需要算上包装费
- public static function needAddPackCost($ghsShop, $customId, $orderAmount = 0)
- {
- if (isset($ghsShop->pfLevel) && $ghsShop->pfLevel == 1) {
- $current = date("Y_m_d");
- $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
- $has = Yii::$app->redis->executeCommand('GET', [$key]);
- if (!empty($has) && $has == 1) {
- return false;
- } else {
- return true;
- }
- } else {
- $lackExpend = $ghsShop->lackExpend ? floatval($ghsShop->lackExpend) : 0;
- $packCost = $ghsShop->packCost ? floatval($ghsShop->packCost) : 0;
- if ($lackExpend <= 0 || $packCost <= 0) {
- return false;
- }
- $current = date("Y_m_d");
- $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
- $has = Yii::$app->redis->executeCommand('GET', [$key]);
- if (!empty($has) && $has == 1) {
- return false;
- }
- if ($orderAmount > 0) {
- if ($orderAmount < $lackExpend) {
- return true;
- }
- } else {
- return true;
- }
- return false;
- }
- }
- public static function getNewShopList()
- {
- $where = ['ptStyle' => dict::getDict('ptStyle', 'hd')];
- $respond = self::getList('*', $where, 'addTime DESC');
- $list = $respond['list'] ?? [];
- if (!empty($list)) {
- foreach ($list as $key => $val) {
- $shopName = $val['shopName'] ?? '';
- $sjName = $val['merchantName'] ?? '';
- $default = $val['default'] ?? 0;
- $showName = $sjName . ' ' . $shopName;
- if ($default == 1) {
- $showName = $sjName;
- }
- $list[$key]['showName'] = $showName;
- $list[$key]['cover'] = imgUtil::groupImg('');
- }
- $respond['list'] = $list;
- }
- return $respond;
- }
- public static function getShopList($where)
- {
- $list = self::getList('*', $where, 'addTime DESC');
- $list['list'] = self::groupBaseInfo($list['list']);
- return $list;
- }
- //组装门店基本信息 ssh 2019.12.2
- public static function groupBaseInfo($list)
- {
- foreach ($list as $key => $val) {
- $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);
- }
- } else {
- $list[$key]['img'] = [];
- $list[$key]['imgUrl'] = [];
- }
- $avatar = $val['avatar'] ?? '';
- $shortAvatar = $avatar;
- $smallAvatar = imgUtil::groupImg($shortAvatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
- $list[$key]['smallAvatar'] = $smallAvatar;
- $list[$key]['shortAvatar'] = $shortAvatar;
- $superWx = $val['superWx'] ?? '';
- $shortSuperWx = $superWx;
- $list[$key]['shortSuperWx'] = $shortSuperWx;
- $list[$key]['superWx'] = imgUtil::groupImg($shortSuperWx) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
- }
- return $list;
- }
- public static function addMainShop($data, $oldShop, $sj)
- {
- if (isset($oldShop->pfShopId) && !empty($oldShop->pfShopId)) {
- 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 = self::getById($defaultShopId, true);
- if (empty($defaultShop)) {
- util::fail('没有找到门店50');
- }
- $oldMainId = $defaultShop->mainId ?? 0;
- if (empty($oldMainId)) {
- util::fail('没有找到main信息');
- }
- $main = MainClass::addMainCopyItem($oldMainId);
- $mainId = $main->id ?? 0;
- $data['mainId'] = $mainId;
- $newShop = self::addShop($data);
- return $newShop;
- }
- //创建门店 ssh 2020.2.8
- public static function addShop($data)
- {
- $data['createTime'] = date("Y-m-d H:i:s");
- $shopName = isset($data['shopName']) ? $data['shopName'] : '';
- $mainId = $data['mainId'] ?? 0;
- if (empty($shopName)) {
- util::fail('请填写门店名称');
- }
- if (stringUtil::getWordNum($shopName) > 8) {
- util::fail('门店名称不能超过8个汉字,2个字母顶一个汉字');
- }
- $exists = self::getByCondition(['sjId' => $data['sjId'], 'shopName' => $shopName]);
- if (!empty($exists)) {
- util::fail('门店名称已经存在');
- }
- //补充fullAddress lqh 2021.4.18
- $data['fullAddress'] = $data['city'] . $data['address'] . $data['floor'];
- $data['img'] = isset($data['img']) && !empty($data['img']) ? json_encode($data['img']) : '';
- if (isset($data['ptStyle']) == false) {
- util::fail('请先择平台类型');
- }
- $shop = self::add($data, true);
- $newShopId = $shop->id;
- $extData = ['shopId' => $newShopId];
- ShopExtClass::add($extData);
- //商品和分类初始化
- CategoryClass::initCategoryGoods($mainId);
- //商城和门店广告初始化
- AdClass::initAdd($mainId);
- //商品配置信息
- $setData = ['mainId' => $mainId, 'riseType' => 0, 'riseAmount' => 0];
- GoodsSettingClass::add($setData);
- //初始化员工和角色
- $adminId = $data['adminId'] ?? 0;
- $mobile = $data['mobile'] ?? 0;
- $initAdminData = ['mobile' => $mobile, 'adminId' => $adminId];
- AdminClass::initAdmin($initAdminData, $mainId, $shop);
- return $shop;
- }
- //获取首店id
- public static function getDefaultShopId($shop)
- {
- $sjId = $shop->sjId ?? 0;
- $sj = SjClass::getById($sjId, true);
- $defaultShopId = $sj->defaultShopId ?? 0;
- return $defaultShopId;
- }
- }
|