| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- namespace bizHd\merchant\services;
- use bizGhs\custom\services\CustomService;
- use bizHd\base\services\BaseService;
- use bizHd\custom\classes\CustomClass;
- use bizHd\merchant\classes\SjAssetClass;
- use bizHd\merchant\classes\SjClass;
- use bizHd\merchant\classes\SjExtendClass;
- use bizHd\merchant\classes\SjInitClass;
- use bizHd\saas\classes\ApplyClass;
- use bizHd\shop\classes\ShopClass;
- use bizHd\user\classes\UserClass;
- use common\components\dict;
- use common\components\stringUtil;
- use Yii;
- class SjService extends BaseService
- {
- public static $baseFile = '\bizHd\merchant\classes\SjClass';
- public static function initHdBaseInfo($applyData, $main, $applyOpen = false)
- {
- $applyId = $applyData['id'] ?? 0;
- $adminId = $applyData['adminId'] ?? 0;
- $mainId = $main->id ?? 0;
- unset($applyData['id']);
- $ptStyle = dict::getDict('ptStyle', 'hd');
- //生成商家
- $applyData['accountStyle'] = 0;
- $applyData['status'] = 1;
- $applyData['lat'] = $applyData['lat'] ?? (string)0;
- $applyData['long'] = $applyData['long'] ?? (string)0;
- $applyData['precision'] = (string)0;
- $applyData['wxToken'] = stringUtil::buildWxToken(0);
- $applyData['photoList'] = $applyData['photoList'] ?? '';
- $applyData['name'] = $applyData['name'] ?? '';
- $applyData['province'] = $applyData['province'] ?? '';
- $applyData['city'] = $applyData['city'] ?? '';
- $applyData['dist'] = $applyData['dist'] ?? '';
- $applyData['address'] = $applyData['address'] ?? '';
- $applyData['agentLevel'] = 1;
- $deadline = time() + 365 * 86400;
- $applyData['deadline'] = date("Y-m-d H:i:s", $deadline);
- if ($applyOpen) {
- $applyData['parentId'] = $applyData['introSjId'] ?? 0;
- $applyData['parentShopId'] = $applyData['introShopId'] ?? 0;
- }
- $jsData = $applyData;
- $sjData['style'] = $ptStyle;
- $sj = self::add($jsData, true);
- $sjId = $sj->id;
- $sjName = $sj->name ?? 0;
- $mobile = $applyData['mobile'] ?? '';
- if (!empty($applyId) && $applyOpen == true) {
- ApplyClass::updateById($applyId, ['sjId' => $sjId]);
- }
- //生成资产
- $assetData = [
- 'balance' => 0,
- 'totalVisit' => 0,
- 'totalUser' => 0,
- 'totalMember' => 0,
- 'totalFans' => 0,
- 'totalIntegral' => 0,
- 'totalPoint' => 0,
- 'totalGoods' => 0,
- 'totalRecharge' => 0,
- 'totalOrder' => 0,
- 'totalDeal' => 0,
- 'sjId' => $sjId,
- 'totalIncome' => 0,
- 'totalExpend' => 0,
- ];
- SjAssetClass::add($assetData);
- //生成商家拓展信息
- $extendData = [
- 'sjId' => $sjId,
- 'wxAppId' => isset($applyData['wxAppId']) ? $applyData['wxAppId'] : '',
- 'webTitle' => isset($applyData['name']) ? $applyData['name'] : '',
- 'webKeyword' => isset($applyData['name']) ? $applyData['name'] : '',
- 'webDescription' => isset($applyData['name']) ? $applyData['name'] : '',
- 'wxMenuInit' => 0,
- 'wxTMessageInit' => 0,
- 'payment' => 0,//支付功能关闭
- 'recharge' => 0,//充值功能关闭
- 'giveCoupon' => 1,//默认赠送代金劵
- 'giveCouponPrice' => 5,//代金劵金额5元
- 'couponMeetPrice' => 180,//满足金额
- 'couponValidity' => 30,//代金劵有效期30天
- 'alipayAccount' => isset($applyData['alipayAccount']) ? $applyData['alipayAccount'] : '',//提现的支付宝帐号
- 'alipayAccountName' => isset($applyData['alipayAccountName']) ? $applyData['alipayAccountName'] : '',//提现支付宝帐号姓名
- 'gradeList' => '1_2000_0.9I2_5000_0.88I3_10000_0.85I4_20000_0.8',//1 级会员需要满 2000 积分 购物享9折;2 级会员需要满 5000 积分 购物享88折
- ];
- SjExtendClass::add($extendData);
- SjInitClass::add(['sjId' => $sjId]);
- //创建门店
- $shopData = [
- 'shopName' => '首店',
- 'sjId' => $sjId,
- 'merchantName' => $sjName,
- 'telephone' => $mobile,
- 'default' => 1,
- 'adminId' => $adminId,
- 'mainId' => $mainId,
- 'parentId' => $applyData['introSjId'] ?? 0,
- 'parentShopId' => $applyData['introShopId'] ?? 0,
- 'mobile' => $mobile,
- 'introduction' => '欢迎光临',
- 'province' => $applyData['province'] ?? '',
- 'city' => $applyData['city'] ?? '',
- 'dist' => $applyData['dist'] ?? '',
- 'address' => $applyData['address'] ?? '',
- 'floor' => $applyData['floor'] ?? '',
- 'fullAddress' => $applyData['fullAddress'] ?? '',
- 'open' => 1,
- 'lat' => $applyData['lat'] ?? '',
- 'long' => $applyData['long'] ?? '',
- 'img' => ['/example/shop/1.jpg'],
- 'ptStyle' => $ptStyle,
- ];
- $shopInfo = ShopClass::addShop($shopData);
- $shopId = $shopInfo->id;
- //变更状态和设置商家的默认门店
- $sjData = [];
- $sjData['defaultShopId'] = $shopId;
- $sjStatus = SjClass::STATUS_HAS_CHECK;
- $sjData['status'] = $sjStatus;
- SjClass::updateById($sjId, $sjData);
- //建立供货商和客户关系
- if ($applyOpen) {
- CustomService::shareBuildTrade($applyData, $shopInfo);
- }
- //生成保存默认客户
- $user = UserClass::replaceUser(['mobile' => $mobile]);
- $custom = CustomClass::replaceCustom($shopInfo, $user);
- $customId = $custom->id ?? 0;
- $shopInfo->defaultCustomId = $customId;
- $shopInfo->save();
- return ['sj' => $sj, 'shop' => $shopInfo];
- }
- }
|