| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449 |
- <?php
- namespace hd\controllers;
- use biz\ghs\classes\GhsClass;
- use biz\recharge\classes\RechargeHbClass;
- use biz\shop\classes\ShopClass;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\custom\classes\CustomLevelClass;
- use bizGhs\merchant\classes\WlClass;
- use bizHd\purchase\classes\PurchaseClass;
- use bizHd\shop\classes\ShopExtClass;
- use bizGhs\stat\classes\StatVisitClass;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\qrCodeUtil;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- class GhsController extends BaseController
- {
- public $guestAccess = ['info', 'get-ghs-data'];
- //提示花店有多个供货商
- public function actionRemindMoreGhs()
- {
- $where = [];
- $where['ownShopId'] = $this->shopId;
- $where['delStatus'] = 0;
- $count = GhsClass::getCount($where);
- $needNotice = 0;
- if ($count > 1) {
- $admin = $this->admin;
- $noticeHasMoreGhs = $admin->noticeHasMoreGhs ?? 0;
- if ($noticeHasMoreGhs == 0) {
- $needNotice = 1;
- }
- }
- util::success(['needNotice' => $needNotice]);
- }
- public static $levelMap = [
- 'pt' => ['name' => '普店', 'num' => 0, 'amount' => 0, 'key' => ''],
- 'hj' => ['name' => '银店', 'num' => 0, 'amount' => 0, 'key' => 'hj'],
- 'zs' => ['name' => '金店', 'num' => 0, 'amount' => 0, 'key' => 'zs'],
- ];
- //未登录获取供货商信息 ssh 20240507
- public function actionGetGhsData()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $salt = $get['salt'] ?? '';
- $ghs = GhsClass::getById($id);
- if (empty($ghs)) {
- util::fail('没有找到供货商的信息哦');
- }
- if (isset($ghs['salt']) == false || $ghs['salt'] != $salt) {
- util::fail('不是您的供货商');
- }
- $debtAmount = $ghs['debtAmount'] ?? 0;
- $balance = $ghs['balance'] ?? 0;
- $remainDebtAmount = bcsub($debtAmount, $balance, 2);
- $remainDebtAmount = floatval($remainDebtAmount);
- $customId = $ghs['customId'] ?? 0;
- $custom = CustomClass::getById($customId);
- if (empty($custom)) {
- util::fail('供货商信息不完整');
- }
- $ghs['remainDebtAmount'] = $remainDebtAmount;
- $custom['remainDebtAmount'] = $remainDebtAmount;
- //有同个地方要同步修改,关键词 custom_go_ghs_gathering_code
- if (getenv('YII_ENV') == 'production') {
- $url = "https://mall.huahb.cn/#/admin/ghs/pay?id={$id}&salt={$salt}";
- } else {
- $url = "https://mall.huaml.com/#/admin/ghs/pay?id={$id}&salt={$salt}";
- }
- $unique = "recharge_to_ghs_" . $id;
- $imgUrl = qrCodeUtil::generateRechargeQrCode($url, $unique);
- $imageUrl = imgUtil::groupImg($imgUrl);
- util::success(['ghs' => $ghs, 'custom' => $custom, 'imgUrl' => $imageUrl]);
- }
- //获取物流列表 ssh 20230608
- public function actionGetWlList()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $ghs = GhsClass::getById($id, true);
- if (empty($ghs)) {
- util::success(['list' => []]);
- }
- $mainId = $ghs->mainId ?? 0;
- $list = WlClass::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0], null, '*');
- util::success(['list' => $list]);
- }
- //添加虚拟的供货商 ssh 20230305
- public function actionAddGhs()
- {
- $post = Yii::$app->request->post();
- $name = $post['name'] ?? '';
- if (empty($name)) {
- util::fail('请填写名称');
- }
- if (stringUtil::getWordNum($name) > 8) {
- util::fail('名称不能超过8个汉字');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $shopId = $this->shopId;
- $has = GhsClass::getByCondition(['ownShopId' => $shopId, 'name' => $name], true);
- if (!empty($has)) {
- util::fail($name . ' 已经存在了');
- }
- \bizHd\ghs\services\GhsService::addVirtualGhs($post, $this->shop);
- $transaction->commit();
- util::complete('添加成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::error("添加失败原因:" . $e->getMessage());
- util::fail('添加失败');
- }
- }
- //是否屏蔽 ssh 20230226
- public function actionChangeDelStatus()
- {
- $get = Yii::$app->request->get();
- $ghsId = $get['ghsId'] ?? 0;
- $delStatus = $get['delStatus'] ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- if (empty($ghs)) {
- util::fail('没有找到供货商');
- }
- $ownMainId = $ghs->ownMainId ?? 0;
- if ($ownMainId != $this->mainId) {
- util::fail('不是你的供货商,无法操作');
- }
- $ghs->delStatus = $delStatus;
- $ghs->save();
- $customId = $ghs->customId ?? 0;
- $custom = CustomClass::getById($customId, true);
- $custom->delStatus = $delStatus;
- $custom->save();
- util::complete('操作成功');
- }
- //获取供货商物流 ssh 20230105
- public function actionGetAllWl()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $ghs = GhsClass::getById($id, true);
- if (empty($ghs) || $ghs->ownMainId != $this->mainId) {
- util::success(['list' => []]);
- }
- $ghsMainId = $ghs->mainId ?? 0;
- $list = \bizGhs\merchant\classes\WlClass::getAllByCondition(['mainId' => $ghsMainId, 'delStatus' => 0], 'inTurn DESC', 'id,name');
- util::success(['list' => $list]);
- }
- //采购选分类有变化通知
- public function actionGetClassRemind()
- {
- $cacheKey = 'class_change_remind_' . $this->shopAdminId;
- $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- $hasStatus = !empty($has) ? 1 : 0;
- util::success(['hasRemind' => $hasStatus]);
- }
- //采购选分类有变化通知
- public function actionHasClassRemind()
- {
- $cacheKey = 'class_change_remind_' . $this->shopAdminId;
- Yii::$app->redis->executeCommand('SET', [$cacheKey, 'has']);
- util::complete();
- }
- //供货商列表 ssh 2021.1.24
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $delStatus = isset($get['delStatus']) && is_numeric($get['delStatus']) ? $get['delStatus'] : 0;
- $where = [];
- $where['ownShopId'] = $this->shopId;
- $where['delStatus'] = $delStatus;
- $name = isset($get['name']) ? $get['name'] : '';
- if (stringUtil::isLetter($name)) {
- $where['py'] = ['like', $name];
- } else {
- $where['name'] = ['like', $name];
- }
- $respond = GhsClass::getGhsList($where);
- //广告列表
- $apiHost = Yii::$app->params['hdImgHost'];
- //$ad = [['banner' => $apiHost . '/ljh/banner2.jpg', 'url' => '/admin/ljh/info']];
- $ad = [];
- $respond['ad'] = $ad;
- //默认显示广告
- $showAd = 1;
- if (isset($respond['list']) && !empty($respond['list'])) {
- foreach ($respond['list'] as $key => $ghs) {
- if (getenv('YII_ENV') == 'production') {
- //海翔、源花汇先不显示广告
- $noAdShopId = [42345, 10649];
- } else {
- $noAdShopId = [0];
- }
- if (isset($ghs['shopId']) && in_array($ghs['shopId'], $noAdShopId)) {
- $showAd = 0;
- }
- }
- }
- $respond['showAd'] = $showAd;
- util::success($respond);
- }
- //详情 ssh 2021.4.11
- public function actionDetail()
- {
- $id = Yii::$app->request->get('id');
- $ghsInfo = GhsClass::getGhsInfo($id);
- $giveLevel = $ghsInfo['giveLevel'] ?? 0;
- $levelMap = CustomClass::$nickNameMap;
- $giveLevelName = $levelMap[$giveLevel] ?? '散客';
- $ghsInfo['giveLevelName'] = $giveLevelName;
- GhsClass::valid($ghsInfo, $this->shopId);
- //是否有充值送红包活动
- $ghsShopId = $ghsInfo['shopId'] ?? 0;
- $ghsShop = ShopClass::getById($ghsShopId, true);
- $ghsInfo['hasRechargeHb'] = $ghsShop->recharge ?? 0;
- $ghsInfo['hasRechargeHbAmount'] = 0;
- $ghsInfo['xrFl'] = $ghsShop->xrFl ?? 0;
- $ghsInfo['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
- $ghsInfo['tjFl'] = $ghsShop->tjFl ?? 0;
- $ghsInfo['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
- $ghsInfo['packCost'] = $ghsShop->packCost ? floatval($ghsShop->packCost) : 0;
- $lackExpend = $ghsShop->lackExpend ? floatval($ghsShop->lackExpend) : 0;
- $customId = $ghsInfo['customId'] ?? 0;
- $needAdd = \bizHd\shop\classes\ShopClass::needAddPackCost($ghsShop, $customId);
- //昆明批发,需要算打包费和运费
- $needAddPackFreight = 1;
- if (!$needAdd) {
- $lackExpend = 0;
- //昆明批发,不需要算打包费和运费
- $needAddPackFreight = 0;
- }
- $ghsInfo['needAddPackFreight'] = $needAddPackFreight;
- $ghsInfo['lackExpend'] = $lackExpend;
- $ghsInfo['showSold'] = $ghsShop->showSold ?? 0;
- $ghsInfo['lsShopId'] = $ghsShop->lsShopId ?? 0;
- //预订单的最低公斤数和每公斤服务费
- $ghsInfo['kiloFee'] = $ghsShop->kiloFee ?? 0;
- $ghsInfo['miniKilo'] = $ghsShop->miniKilo ?? 0;
- $ghsInfo['pfLevel'] = $ghsShop->pfLevel ?? 0;
- $ghsInfo['afterSale'] = $ghsShop->afterSale ?? 1;
- //联系电话
- $ghsInfo['telephone'] = $ghsShop->telephone ?? '';
- $shareLogo = imgUtil::groupImg('buy_logo.jpg');
- if (!empty($ghsShop->shareLogo)) {
- $shareLogo = imgUtil::groupImg($ghsShop->shareLogo);
- }
- $ghsInfo['shareLogo'] = $shareLogo;
- $ghsInfo['superWx'] = '';
- if (!empty($ghsShop->superWx)) {
- $ghsInfo['superWx'] = imgUtil::groupImg($ghsShop->superWx) . "?x-oss-process=image/resize,w_150";
- }
- $ghsMainId = $ghsShop->mainId ?? 0;
- $kmPackCost = PurchaseClass::getKmPackCost($ghsMainId);
- $ghsInfo['kmPackCost'] = $kmPackCost;
- $ghsInfo['transCost'] = dict::getDict('transCost', null, null, $ghsShop->mainId);
- //杭州斗南鲜花批发 免运费活动
- if (isset($ghsInfo['shopId']) && $ghsInfo['shopId'] == 4608) {
- $current = time();
- if ($current < strtotime('2023-4-8 00:00:00')) {
- $ghsInfo['hasAct'] = 1;
- }
- }
- $shopExt = ShopExtClass::getByCondition(['shopId' => $ghsShopId], false, false, 'purchaseGuide,purchaseGuideText,hcFreeKm,hcMap');
- $ghsInfo['buyNotice'] = $ghsShop->buyNotice ?? 0;
- $ghsInfo['buyNoticeText'] = $shopExt['purchaseGuideText'] ?? '';
- //判断是否开启同城配送功能
- $intraCityRet = ShopClass::hasIntraCity($ghsShop);
- $openIntraCity = $intraCityRet['openIntraCity'] ?? 0;
- $ghsInfo['openIntraCity'] = $openIntraCity;
- //花材的免费配送设置
- $hcFreeKm = $shopExt['hcFreeKm'] ?? 0;
- $ghsInfo['hcFreeKm'] = $hcFreeKm;
- $hcMapString = $shopExt['hcMap'] ?? '';
- $hcMap = [];
- if (!empty($hcMapString)) {
- $hcMap = json_decode($hcMapString, true);
- }
- $ghsInfo['hcMap'] = $hcMap;
- util::success($ghsInfo);
- }
- //根据门店获取供货商信息 ssh 2021.4.14
- public function actionInfo()
- {
- $shopId = Yii::$app->request->get('shopId');
- if (!empty($this->shopId)) {
- $current = ShopClass::getById($shopId, true);
- if (empty($current)) {
- util::fail('没有找到批发店,rid-186-' . $shopId);
- }
- if ($current->ptStyle != dict::getDict('ptStyle', 'ghs')) {
- util::fail('没有找到批发店,rid-195-' . $shopId);
- }
- $ghs = GhsClass::build($shopId, $this->shopId);
- //是否有充值送红包活动
- $ghsShopId = $ghs['shopId'] ?? 0;
- $ghsShop = ShopClass::getById($ghsShopId, true);
- $ghs['hasRechargeHb'] = $ghsShop->recharge ?? 0;
- $ghs['hasRechargeHbAmount'] = 0;
- $avatar = $ghs['avatar'] ?? '';
- $ghs['avatar'] = imgUtil::groupImg($avatar);
- $map = CustomClass::$nickNameMap;
- $giveLevel = $ghs['giveLevel'] ?? 0;
- $ghs['giveLevelName'] = $map[$giveLevel] ?? '';
- $ghs['showSold'] = $ghsShop->showSold ?? 0;
- $ghs['buyNotice'] = $ghsShop->buyNotice ?? 0;
- $shopExt = ShopExtClass::getByCondition(['shopId' => $ghsShopId], true, false, 'id,shopId,purchaseGuideText');
- $ghs['buyNoticeText'] = $shopExt->purchaseGuideText ?? '';
- $ghs['xrFl'] = $ghsShop->xrFl ?? 0;
- $ghs['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
- $ghs['tjFl'] = $ghsShop->tjFl ?? 0;
- $ghs['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
- $ghs['lsShopId'] = $ghsShop->lsShopId ?? 0;
- $ghs['presell'] = $ghsShop->presell ?? 0;
- $shareLogo = imgUtil::groupImg('buy_logo.jpg');
- if (isset($ghsShop->shareLogo) && !empty($ghsShop->shareLogo)) {
- $shareLogo = imgUtil::groupImg($ghsShop->shareLogo);
- }
- $ghs['shareLogo'] = $shareLogo;
- $ghs['telephone'] = $ghsShop->telephone ?? '';
- $ghs['superWx'] = '';
- if (!empty($ghsShop->superWx)) {
- $ghs['superWx'] = imgUtil::groupImg($ghsShop->superWx);
- }
- $ghs['transCost'] = dict::getDict('transCost', null, null, $ghsShop->mainId);
- } else {
- //没有开店也给显示供货商信息
- $shop = ShopClass::getShopInfo($shopId);
- $shopName = $shop['shopName'] ?? '';
- $sjName = $shop['merchantName'] ?? '';
- $avatar = $shop['avatar'] ?? '';
- $default = $shop['default'] ?? 0;
- $name = $default == 1 && $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
- $ghs = [
- 'id' => 0,
- 'name' => $name,
- 'debtAmount' => 0.00,
- 'expendAmount' => 0.00,
- 'giveLevel' => 0,
- 'giveLevelName' => '普通',
- 'xrFl' => 0,
- 'xrFlAmount' => 0,
- 'tjFl' => 0,
- 'tjFlAmount' => 0,
- 'avatar' => $avatar,
- 'showSold' => 0,
- 'buyNotice' => 0,
- 'lsShopId' => 0,
- 'presell' => 0,
- 'shareLogo' => '',
- 'superWx' => '',
- 'transCost' => [],
- ];
- }
- util::success($ghs);
- }
- //获取客户等级 ssh 20211016
- public function actionGetCustomLevel()
- {
- $id = Yii::$app->request->get('id');
- $info = GhsClass::getById($id, true);
- GhsClass::valid($info, $this->shopId);
- $ghsShopId = $info->shopId ?? 0;
- $info = CustomLevelClass::getByCondition(['shopId' => $ghsShopId]);
- $map = self::$levelMap;
- foreach ($map as $key => $val) {
- $flag = $val['key'] ?? '';
- if (empty($flag)) {
- $map[$key]['num'] = $info["num"] ?? 0;
- $map[$key]['amount'] = $info["amount"] ?? 0;
- } else {
- $map[$key]['num'] = $info[$flag . "Num"] ?? 0;
- $map[$key]['amount'] = $info[$flag . "Amount"] ?? 0;
- }
- }
- util::success(['list' => $map]);
- }
- //访问供货商的商城 ssh 20211022
- public function actionVisitMall()
- {
- $id = Yii::$app->request->get('id');
- $info = GhsClass::getById($id, true);
- GhsClass::valid($info, $this->shopId);
- $customId = $info->customId ?? 0;
- $custom = CustomClass::getById($customId, true);
- if (empty($custom)) {
- util::fail('没有找到客户');
- }
- if ($custom->black == 1) {
- //没有列入黑名单的,增加访客记录
- StatVisitClass::addGhsCustomVisit($info, $custom);
- }
- util::complete();
- }
- //补充缺失的供货商 ssh 20211027
- public function actionBcGhs()
- {
- util::fail('过几天再试');
- GhsClass::bcGhs($this->shopId);
- util::complete('载入成功');
- }
- }
|