| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <?php
- namespace bizGhs\custom\classes;
- use biz\ghs\classes\GhsClass;
- use biz\shop\classes\ShopClass;
- use biz\sj\classes\MerchantClass;
- use biz\sj\classes\SjClass;
- use common\components\business;
- use common\components\imgUtil;
- use common\components\util;
- use Yii;
- use bizHd\base\classes\BaseClass;
- class CustomClass extends BaseClass
- {
- public static $baseFile = '\bizGhs\custom\models\Custom';
- //申请开店建立客户关系 ssh 2021.2.28
- public static function buildCustom($applyData, $sjId, $shopId)
- {
- if ($applyData['style'] == SjClass::STYLE_RETAIL) {
- if ($applyData['introStyle'] == SjClass::STYLE_SUPPLIER) {
- $has = CustomClass::getByCondition(['sjId' => $applyData['introSjId'], 'customSjId' => $sjId, 'customShopId' => $shopId]);
- if (empty($has)) {
- $customData = [
- 'customSjId' => $sjId,//零售商家id
- 'customShopId' => $shopId,//零售门店id
- 'sjId' => $applyData['introSjId'],//供货商id
- 'name' => $applyData['name'],
- 'mobile' => $applyData['mobile'],
- 'province' => $applyData['province'] ?? '',
- 'city' => $applyData['city'] ?? '',
- 'dist' => $applyData['dist'] ?? '',
- 'address' => $applyData['address'] ?? '',
- 'fullAddress' => $applyData['fullAddress'],
- 'long' => $applyData['long'],
- 'lat' => $applyData['lat'],
- ];
- CustomClass::addCustom($customData);
- $introShopId = $applyData['introShopId'] ?? 0;
- $ghsShop = ShopClass::getShopInfo($introShopId);
- if (empty($ghsShop)) {
- util::fail('没有找到门店');
- }
- $ghsData = [
- 'ghsSjId' => $ghsShop['merchantId'],
- 'ghsShopId' => $ghsShop['id'],
- 'sjId' => $sjId,
- 'shopId' => $sjId,
- 'mobile' => $ghsShop['mobile'] ?? '',
- 'province' => $ghsShop['province'] ?? '',
- 'city' => $ghsShop['city'] ?? '',
- 'dist' => $ghsShop['dist'] ?? '',
- 'address' => $ghsShop['address'] ?? '',
- 'floor' => $ghsShop['floor'] ?? '',
- 'fullAddress' => $ghsShop['fullAddress'] ?? '',
- 'lat' => $ghsShop['lat'] ?? '',
- 'long' => $ghsShop['long'] ?? '',
- ];
- GhsClass::addGhs($ghsData);
- }
- }
- }
- if ($applyData['style'] == SjClass::STYLE_SUPPLIER) {
- if ($applyData['introStyle'] == SjClass::STYLE_RETAIL) {
- $has = CustomClass::getByCondition(['sjId' => $sjId, 'customSjId' => $applyData['introSjId'], 'customShopId' => $applyData['introShopId']]);
- if (empty($has)) {
- $introSjId = $applyData['introSjId'] ?? 0;
- $introShopId = $applyData['introShopId'] ?? 0;
- $shop = ShopClass::getShopInfo($introShopId);
- $name = $shop['shopName'] ?? '';
- $super = ShopClass::getSuper($introShopId);
- $mobile = $super['mobile'] ?? '';
- $customData = [
- 'customSjId' => $introSjId,//零售商id
- 'customShopId' => $introShopId,//零售门店id
- 'sjId' => $sjId,//供货商id
- 'name' => $name,
- 'mobile' => $mobile,
- 'isOpen' => 1,
- 'province' => $applyData['province'] ?? '',
- 'city' => $applyData['city'] ?? '',
- 'dist' => $applyData['dist'] ?? '',
- 'address' => $applyData['address'] ?? '',
- 'fullAddress' => $applyData['fullAddress'],
- 'long' => $applyData['long'],
- 'lat' => $applyData['lat'],
- ];
- CustomClass::addCustom($customData);
- $ghsShop = ShopClass::getShopInfo($shopId);
- if (empty($ghsShop)) {
- util::fail('没有找到门店');
- }
- $ghsData = [
- 'ghsSjId' => $sjId,
- 'ghsShopId' => $shopId,
- 'sjId' => $introSjId,
- 'shopId' => $introShopId,
- 'mobile' => $ghsShop['mobile'] ?? '',
- 'province' => $ghsShop['province'] ?? '',
- 'city' => $ghsShop['city'] ?? '',
- 'dist' => $ghsShop['dist'] ?? '',
- 'address' => $ghsShop['address'] ?? '',
- 'floor' => $ghsShop['floor'] ?? '',
- 'fullAddress' => $ghsShop['fullAddress'] ?? '',
- 'lat' => $ghsShop['lat'] ?? '',
- 'long' => $ghsShop['long'] ?? '',
- ];
- GhsClass::addGhs($ghsData);
- }
- }
- }
- }
- //添加客户 ssh 2021.2.24
- public static function addCustom($data)
- {
- return self::add($data);
- }
- //获取客户信息 ssh 2021.2.4
- public static function getCustom($id)
- {
- $info = self::getById($id);
- if (empty($info)) {
- return $info;
- }
- $respond = self::groupBaseInfo([$info]);
- return current($respond);
- }
- public static function getCustomByIds($ids)
- {
- $list = self::getByIds($ids, null, 'id');
- return self::groupBaseInfo($list);
- }
- //整合头像等信息 ssh 2021.1.8
- public static function groupBaseInfo($list)
- {
- if (empty($list)) {
- return $list;
- }
- //获取客户信息
- $customSjIdList = array_unique(array_filter(array_column($list, 'customSjId')));
- $sjInfo = MerchantClass::getByIds($customSjIdList, null, 'id');
- foreach ($list as $key => $val) {
- $customSjId = $val['customSjId'];
- $currentInfo = isset($sjInfo[$customSjId]) ? $sjInfo[$customSjId] : [];
- $currentInfo = business::formatMerchantLogo($currentInfo);
- $smallAvatar = !empty($currentInfo['smallLogoUrl']) ? $currentInfo['smallLogoUrl'] : imgUtil::getPrefix() . '/hhb_small.png';
- $avatar = !empty($currentInfo['logoUrl']) ? $currentInfo['logoUrl'] : imgUtil::getPrefix() . '/hhb_small.png';
- $list[$key]['smallAvatar'] = $smallAvatar;
- $list[$key]['shortSmallAvatar'] = $currentInfo['shortSmallLogoUrl'];
- $list[$key]['avatar'] = $avatar;
- $list[$key]['shortAvatar'] = $currentInfo['shortLogoUrl'];
- $list[$key]['visitTime'] = '03-20 12:00';
- $list[$key]['level'] = 0;
- $list[$key]['sn'] = $val['id'];
- }
- return $list;
- }
- //欠款权限开关 ssh 2021.1.8
- public static function debt($custom, $debt)
- {
- $id = isset($custom['id']) ? $custom['id'] : 0;
- self::updateById($id, ['debt' => $debt]);
- return true;
- }
- //权限判断 ssh 2021.1.8
- public static function valid($custom, $merchantId)
- {
- if (empty($custom)) {
- util::fail('没有找到客户');
- }
- if ($custom['sjId'] != $merchantId) {
- util::fail('您没有权限操作此客户');
- }
- }
- }
|