| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- <?php
- namespace biz\shop\classes;
- use biz\ghs\classes\GhsClass;
- use biz\pt\classes\PtAssetClass;
- use biz\sj\classes\SjClass;
- use bizGhs\product\classes\ProductClass;
- use common\components\dict;
- use common\components\httpUtil;
- use common\components\imgUtil;
- use common\components\qrCodeUtil;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- use biz\base\classes\BaseClass;
- class ShopClass extends BaseClass
- {
- public static $baseFile = '\biz\shop\models\Shop';
- //获取图片信息 ssh 2021.3.14
- public static function getShopInfo($id)
- {
- $info = self::getById($id);
- if (empty($info)) {
- return $info;
- }
- $list = self::groupShopInfo([$info]);
- return current($list);
- }
- public static function getShopList($where)
- {
- $list = self::getList('*', $where, 'addTime DESC');
- return $list;
- }
- //查看店铺 ssh 2021.3.1
- public static function getShopByIds($ids)
- {
- $list = self::getByIds($ids);
- return self::groupShopInfo($list);
- }
- //门店 ssh 2021.3.1
- public static function groupShopInfo($list)
- {
- if (empty($list)) {
- return $list;
- }
- foreach ($list as $key => $val) {
- $list[$key]['avatar'] = imgUtil::groupImg($val['avatar']);
- }
- return $list;
- }
- //获取商家默认的门店ID ssh 2020.1.19
- public static function getDefaultShopId($merchant)
- {
- return isset($merchant['defaultShopId']) ? $merchant['defaultShopId'] : 0;
- }
- //创建门店 ssh 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('请填写门店名称');
- }
- if (stringUtil::getWordNum($shopName) > 8) {
- util::fail('门店名称不能超过8个汉字,2个字母顶一个汉字');
- }
- $exists = self::getByCondition(['sjId' => $data['sjId'], 'shopName' => $shopName]);
- if (!empty($exists)) {
- util::fail('门店名称已经存在');
- }
- //补充fullAddress linqh 2021.4.18
- $data['fullAddress'] = $data['province'] . $data['city'] . $data['address'] . $data['floor'];
- $img = json_encode([]);
- if (isset($data['img']) && !empty($data['img'])) {
- $img = json_encode($data['img']);
- }
- $data['img'] = $img;
- if (isset($data['ptStyle']) == false) {
- util::fail('请先择平台类型');
- }
- $shop = self::add($data);
- $newShopId = $shop['id'];
- //初始化花材 linqh 2021.5.11
- $adminId = $data['adminId'] ?? 0;
- $shopId = $data['shopId'] ?? 0;
- ProductClass::newShopInitProduct($data['sjId'], $shopId, $newShopId, $adminId);
- return $shop;
- }
- //更新门店 ssh 2020.2.29
- public static function updateShop($id, $data)
- {
- $shopName = isset($data['shopName']) ? $data['shopName'] : '';
- $sjId = $data['sjId'];
- $findShop = self::getByCondition(['sjId' => $sjId, 'shopName' => $shopName]);
- if (!empty($findShop) && $findShop['id'] != $id) {
- util::fail('门店名称已经存在');
- }
- return self::updateById($id, $data);
- }
- //取商家所有门店 ssh 2020.2.29
- public static function getAllShop($sjId)
- {
- return self::getAllByCondition(['sjId' => $sjId], null, "*");
- }
- //验证所属权限 ssh 2020.2.29
- public static function valid($shop, $sjId)
- {
- if (empty($shop)) {
- util::fail('门店无效');
- }
- if (isset($shop['sjId']) == false || $shop['sjId'] != $sjId) {
- 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 2020.3.9
- public static function generateGatheringCode($sjId, $shopId)
- {
- $url = Yii::$app->params['mallDomain'] . "/#/pages/pay/index?account={$sjId}&shopId=" . $shopId;
- //强制转成https
- $url = httpUtil::becomeHttps($url);
- $gatheringCode = qrCodeUtil::generateGatheringQrCode($url, $sjId, $shopId, '', 10);
- return $gatheringCode;
- }
- //客户下单引起的余额增加 shish 20210520
- public static function customKdAddBalance($shop, $amount, $order, $capitalType)
- {
- //门店余额增加
- $currentBalance = bcadd($shop->balance, $amount, 2);
- $shop->balance = $currentBalance;
- $shop->totalRecharge = bcadd($shop->totalRecharge, $amount, 2);
- //可提现余额同步增加
- $currentTx = bcadd($shop->txBalance, $amount, 2);
- $shop->txBalance = $currentTx;
- $shop->save();
- //增加余额变动记录
- $id = $order->id;
- $event = "客户下单 {$amount}元";
- $tx = dict::getDict('yeTx', 'can');
- $change = [
- 'relateId' => $id,
- 'capitalType' => $capitalType,
- 'amount' => $amount,
- 'balance' => $currentBalance,
- 'txBalance' => $currentTx,
- 'io' => 1,
- 'payWay' => $order->payWay,
- 'event' => $event,
- 'sjId' => $order->sjId,
- 'shopId' => $order->shopId,
- 'tx' => $tx,
- 'ptStyle' => $shop->ptStyle,
- ];
- ShopYeChangeClass::addChange($change, true);
- //平台余额增加
- PtAssetClass::customKdAddBalance($shop, $amount, $order, $capitalType, $tx);
- }
- //门店充值增加余额 ssh 2021.2.21
- //$fix = true 余额只能在指定门店使用
- public static function rechargeAddBalance($shop, $amount, $order, $tx, $capitalType, $fix = false)
- {
- //门店余额增加
- $currentBalance = bcadd($shop->balance, $amount, 2);
- $shop->balance = $currentBalance;
- $currentTotalRecharge = bcadd($shop->totalRecharge, $amount, 2);
- $shop->totalRecharge = $currentTotalRecharge;
- //定向消费余额
- if ($fix) {
- $currentFix = bcadd($shop->fixBalance, $amount, 2);
- $shop->fixBalance = $currentFix;
- }
- $currentTx = $shop->txBalance;
- //提现余额
- if ($tx == dict::getDict('yeTx', 'can')) {
- $currentTx = bcadd($shop->txBalance, $amount, 2);
- $shop->txBalance = $currentTx;
- }
- $shop->save();
- $order->totalRecharge = $currentTotalRecharge;
- $order->save();
- //增加余额变动记录
- $id = $order->id;
- $event = "充值{$amount}元";
- if ($order->shopAdminId == 0) {
- $event = "系统充值{$amount}元";
- }
- $change = [
- 'relateId' => $id,
- 'capitalType' => $capitalType,
- 'amount' => $amount,
- 'balance' => $currentBalance,
- 'txBalance' => $currentTx,
- 'io' => 1,
- 'payWay' => $order->payWay,
- 'event' => $event,
- 'sjId' => $order->sjId,
- 'shopId' => $order->shopId,
- 'tx' => $tx,
- 'ptStyle' => $shop->ptStyle,
- ];
- ShopYeChangeClass::addChange($change, true);
- //平台余额增加
- PtAssetClass::rechargeAddBalance($shop, $amount, $order, $capitalType, $tx);
- }
- //采购余额付款,减少余额 shish 20210519
- public static function purchaseReduceBalance($shop, $amount, $order)
- {
- if (bccomp($amount, $shop->balance, 2) == 1) {
- util::fail('余额不足');
- }
- $sjId = $order->sjId;
- $shopId = $order->shopId;
- //定向消费余额
- $currentFixBalance = $shop->fixBalance;
- $ghsId = $order->ghsId;
- $ghs = GhsClass::getById($ghsId, true);
- if (empty($ghs)) {
- util::fail('没有找到供货商');
- }
- //找出推荐人
- $ghsShopId = $ghs->shopId;
- $parentShopId = SjClass::getParentShopId($sjId);
- //指定消费判断
- if ($ghsShopId != $parentShopId) {
- //如果不是在自己推荐人那边采购,需确认扣掉定向消费余额后还够不够扣
- $notFixBalance = bcsub($shop->balance, $currentFixBalance, 2);
- if (bccomp($amount, $notFixBalance, 2) == 1) {
- util::fail('充值余额只能在介绍您的门店消费');
- }
- } else {
- //需要定向消费余额不够本次扣时全部扣掉
- if ($currentFixBalance > 0) {
- $reduceFix = $currentFixBalance > $amount ? $amount : $currentFixBalance;
- $shop->fixBalance = bcsub($currentFixBalance, $reduceFix, 2);
- }
- }
- $currentBalance = bcsub($shop->balance, $amount, 2);
- $shop->balance = $currentBalance;
- $tx = dict::getDict('yeTx', 'canNot');
- //还有可提现余额也要先用掉
- $currentTxBalance = $shop->txBalance;
- if ($currentTxBalance > 0) {
- $reduceTxBalance = $currentTxBalance > $amount ? $amount : $currentTxBalance;
- $shop->txBalance = bcsub($currentTxBalance, $reduceTxBalance, 2);
- $tx = dict::getDict('yeTx', 'can');
- }
- $shop->save();
- $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
- //增加余额变动记录
- $id = $order->id;
- $change = [
- 'relateId' => $id,
- 'capitalType' => $capitalType,
- 'amount' => $amount,
- 'balance' => $currentBalance,
- 'txBalance' => $currentTxBalance,
- 'io' => 0,
- 'payWay' => $order->payWay,
- 'event' => "余额支付{$amount}元",
- 'sjId' => $sjId,
- 'shopId' => $shopId,
- 'tx' => $tx,
- 'ptStyle' => $shop->ptStyle,
- ];
- ShopYeChangeClass::addChange($change, true);
- //平台余额增加
- PtAssetClass::reduceBalance($shop, $amount, $order, $capitalType, $tx);
- }
- //获取商家所有的门店 ssh 2021.2.26
- public static function getSjShopList($sjId)
- {
- return self::getAllByCondition(['sjId' => $sjId, 'delStatus' => 0], null, ['id']);
- }
- //取门店长信息 ssh 2021.1.17
- public static function getSuper($id)
- {
- $shop = self::getById($id);
- if (empty($shop)) {
- return [];
- }
- $adminId = $shop['adminId'] ?? 0;
- return \bizHd\admin\classes\AdminClass::getDetail($adminId);
- }
- }
|