|
|
@@ -3,6 +3,7 @@
|
|
|
namespace bizTy\shop\classes;
|
|
|
|
|
|
use biz\admin\classes\ShopAdminClass;
|
|
|
+use bizTy\sj\classes\MerchantClass;
|
|
|
use common\components\dirUtil;
|
|
|
use common\components\httpUtil;
|
|
|
use common\components\qrCodeUtil;
|
|
|
@@ -13,118 +14,141 @@ use bizTy\base\classes\BaseClass;
|
|
|
|
|
|
class ShopClass extends BaseClass
|
|
|
{
|
|
|
-
|
|
|
- public static $baseFile = '\bizTy\shop\models\Shop';
|
|
|
-
|
|
|
- public static function getShopInfo($id)
|
|
|
- {
|
|
|
- return self::getById($id);
|
|
|
- }
|
|
|
-
|
|
|
- public static function getShopList($where)
|
|
|
- {
|
|
|
- $list = self::getList('*', $where, 'addTime DESC');
|
|
|
- return $list;
|
|
|
- }
|
|
|
-
|
|
|
- //获取商家默认的门店ID shish 2020.1.19
|
|
|
- public static function getDefaultShopId($merchant)
|
|
|
- {
|
|
|
- return isset($merchant['defaultShopId']) ? $merchant['defaultShopId'] : 0;
|
|
|
- }
|
|
|
-
|
|
|
- //创建门店 shish 2020.2.8
|
|
|
- public static function addShop($data)
|
|
|
- {
|
|
|
- $data['createTime'] = date("Y-m-d H:i:s");
|
|
|
- $shopName = isset($data['shopName']) ? $data['shopName'] : '';
|
|
|
- if (empty($shopName)) {
|
|
|
- util::fail('请填写门店名称');
|
|
|
- }
|
|
|
- $exists = self::getByCondition(['merchantId' => $data['merchantId'], 'shopName' => $shopName]);
|
|
|
- if (!empty($exists)) {
|
|
|
- util::fail('门店名称已经存在');
|
|
|
- }
|
|
|
- $shop = self::add($data);
|
|
|
- return $shop;
|
|
|
- }
|
|
|
-
|
|
|
- //更新门店 shish 2020.2.29
|
|
|
- public static function updateShop($id, $data)
|
|
|
- {
|
|
|
- $shopName = isset($data['shopName']) ? $data['shopName'] : '';
|
|
|
- $merchantId = $data['merchantId'];
|
|
|
- $findShop = self::getByCondition(['merchantId' => $merchantId, 'shopName' => $shopName]);
|
|
|
- if (!empty($findShop) && $findShop['id'] != $id) {
|
|
|
- util::fail('门店名称已经存在');
|
|
|
- }
|
|
|
- return self::updateById($id, $data);
|
|
|
- }
|
|
|
-
|
|
|
- //取商家所有门店 shish 2020.2.29
|
|
|
- public static function getAllShop($merchantId)
|
|
|
- {
|
|
|
- return self::getAllByCondition(['merchantId' => $merchantId]);
|
|
|
- }
|
|
|
-
|
|
|
- //验证所属权限 shish 2020.2.29
|
|
|
- public static function valid($shop, $merchantId)
|
|
|
- {
|
|
|
- if (empty($shop)) {
|
|
|
- util::fail('门店无效');
|
|
|
- }
|
|
|
- if (isset($shop['merchantId']) == false || $shop['merchantId'] != $merchantId) {
|
|
|
- util::fail('您没有权限访问');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //删除门店 shish 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]);
|
|
|
- }
|
|
|
-
|
|
|
- //生成收款码 shish 2020.3.9
|
|
|
- public static function generateGatheringCode($merchantId, $shopId)
|
|
|
- {
|
|
|
- $url = Yii::$app->params['mallDomain'] . "/#/pages/pay/index?account={$merchantId}&shopId=" . $shopId;
|
|
|
- //强制转成https
|
|
|
- $url = httpUtil::becomeHttps($url);
|
|
|
- $gatheringCode = qrCodeUtil::generateGatheringQrCode($url, $merchantId, $shopId, '', 10);
|
|
|
- return $gatheringCode;
|
|
|
- }
|
|
|
-
|
|
|
- //增加余额 shish 2021.2.21
|
|
|
- //$fix = false 余额使用时不需要指定在谁那边用
|
|
|
- public static function addBalance($shop, $amount, $fix = false)
|
|
|
- {
|
|
|
- $shop->balance += $amount;
|
|
|
- $shop->totalRecharge += $amount;
|
|
|
- if ($fix) {
|
|
|
- $shop->fixBalance += $amount;
|
|
|
- }
|
|
|
- $shop->save();
|
|
|
- }
|
|
|
-
|
|
|
- //获取商家所有的门店 shish 2021.2.26
|
|
|
- public static function getSjShopList($sjId)
|
|
|
- {
|
|
|
- return self::getAllByCondition(['merchantId' => $sjId, 'delStatus' => 0], null, ['id']);
|
|
|
- }
|
|
|
-
|
|
|
- //取门店长信息 shish 2021.1.17
|
|
|
- public static function getSuper($id)
|
|
|
- {
|
|
|
- $shop = self::getById($id);
|
|
|
- if (empty($shop)) {
|
|
|
- return [];
|
|
|
- }
|
|
|
- $adminId = $shop['adminId'] ?? 0;
|
|
|
- return \biz\admin\classes\AdminClass::getDetail($adminId);
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+ public static $baseFile = '\bizTy\shop\models\Shop';
|
|
|
+
|
|
|
+ public static function getShopInfo($id)
|
|
|
+ {
|
|
|
+ return self::getById($id);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function getShopList($where)
|
|
|
+ {
|
|
|
+ $list = self::getList('*', $where, 'addTime DESC');
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
+
|
|
|
+ //查看店铺 shish 2021.3.1
|
|
|
+ public static function getShopByIds($ids)
|
|
|
+ {
|
|
|
+ $list = self::getByIds($ids);
|
|
|
+ return self::groupShopInfo($list);
|
|
|
+ }
|
|
|
+
|
|
|
+ //门店 shish 2021.3.1
|
|
|
+ public static function groupShopInfo($list)
|
|
|
+ {
|
|
|
+ if (empty($list)) {
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
+ $sjIds = array_column($list, 'merchantId');
|
|
|
+ $sjList = MerchantClass::getMerchantByIds($sjIds);
|
|
|
+ foreach ($list as $key => $val) {
|
|
|
+ $sjId = $val['merchantId'];
|
|
|
+ $logoUrl = isset($sjList[$sjId]['logoUrl']) ? $sjList[$sjId]['logoUrl'] : Yii::$app->params['imgHost'] . '/retail/default-img.png';
|
|
|
+ $list[$key]['avatar'] = $logoUrl;
|
|
|
+ }
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取商家默认的门店ID shish 2020.1.19
|
|
|
+ public static function getDefaultShopId($merchant)
|
|
|
+ {
|
|
|
+ return isset($merchant['defaultShopId']) ? $merchant['defaultShopId'] : 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ //创建门店 shish 2020.2.8
|
|
|
+ public static function addShop($data)
|
|
|
+ {
|
|
|
+ $data['createTime'] = date("Y-m-d H:i:s");
|
|
|
+ $shopName = isset($data['shopName']) ? $data['shopName'] : '';
|
|
|
+ if (empty($shopName)) {
|
|
|
+ util::fail('请填写门店名称');
|
|
|
+ }
|
|
|
+ $exists = self::getByCondition(['merchantId' => $data['merchantId'], 'shopName' => $shopName]);
|
|
|
+ if (!empty($exists)) {
|
|
|
+ util::fail('门店名称已经存在');
|
|
|
+ }
|
|
|
+ $shop = self::add($data);
|
|
|
+ return $shop;
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新门店 shish 2020.2.29
|
|
|
+ public static function updateShop($id, $data)
|
|
|
+ {
|
|
|
+ $shopName = isset($data['shopName']) ? $data['shopName'] : '';
|
|
|
+ $merchantId = $data['merchantId'];
|
|
|
+ $findShop = self::getByCondition(['merchantId' => $merchantId, 'shopName' => $shopName]);
|
|
|
+ if (!empty($findShop) && $findShop['id'] != $id) {
|
|
|
+ util::fail('门店名称已经存在');
|
|
|
+ }
|
|
|
+ return self::updateById($id, $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ //取商家所有门店 shish 2020.2.29
|
|
|
+ public static function getAllShop($merchantId)
|
|
|
+ {
|
|
|
+ return self::getAllByCondition(['merchantId' => $merchantId]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //验证所属权限 shish 2020.2.29
|
|
|
+ public static function valid($shop, $merchantId)
|
|
|
+ {
|
|
|
+ if (empty($shop)) {
|
|
|
+ util::fail('门店无效');
|
|
|
+ }
|
|
|
+ if (isset($shop['merchantId']) == false || $shop['merchantId'] != $merchantId) {
|
|
|
+ util::fail('您没有权限访问');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除门店 shish 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]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成收款码 shish 2020.3.9
|
|
|
+ public static function generateGatheringCode($merchantId, $shopId)
|
|
|
+ {
|
|
|
+ $url = Yii::$app->params['mallDomain'] . "/#/pages/pay/index?account={$merchantId}&shopId=" . $shopId;
|
|
|
+ //强制转成https
|
|
|
+ $url = httpUtil::becomeHttps($url);
|
|
|
+ $gatheringCode = qrCodeUtil::generateGatheringQrCode($url, $merchantId, $shopId, '', 10);
|
|
|
+ return $gatheringCode;
|
|
|
+ }
|
|
|
+
|
|
|
+ //增加余额 shish 2021.2.21
|
|
|
+ //$fix = false 余额使用时不需要指定在谁那边用
|
|
|
+ public static function addBalance($shop, $amount, $fix = false)
|
|
|
+ {
|
|
|
+ $shop->balance += $amount;
|
|
|
+ $shop->totalRecharge += $amount;
|
|
|
+ if ($fix) {
|
|
|
+ $shop->fixBalance += $amount;
|
|
|
+ }
|
|
|
+ $shop->save();
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取商家所有的门店 shish 2021.2.26
|
|
|
+ public static function getSjShopList($sjId)
|
|
|
+ {
|
|
|
+ return self::getAllByCondition(['merchantId' => $sjId, 'delStatus' => 0], null, ['id']);
|
|
|
+ }
|
|
|
+
|
|
|
+ //取门店长信息 shish 2021.1.17
|
|
|
+ public static function getSuper($id)
|
|
|
+ {
|
|
|
+ $shop = self::getById($id);
|
|
|
+ if (empty($shop)) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ $adminId = $shop['adminId'] ?? 0;
|
|
|
+ return \biz\admin\classes\AdminClass::getDetail($adminId);
|
|
|
+ }
|
|
|
+
|
|
|
}
|