| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- <?php
- namespace biz\merchant\classes;
- use biz\ad\classes\AdClass;
- use biz\admin\classes\AdminRoleClass;
- use biz\admin\classes\ShopAdminClass;
- use biz\coupon\classes\CouponAssetClass;
- use biz\goods\classes\CategoryClass;
- use biz\goods\classes\GoodsSettingClass;
- use common\components\business;
- use common\components\httpUtil;
- use common\components\qrCodeUtil;
- use common\components\stringUtil;
- use Yii;
- use biz\base\classes\BaseClass;
- class MerchantClass extends BaseClass
- {
-
- public static $baseFile = '\biz\merchant\models\Merchant';
-
- //常用链接
- public static $commonUrl = [
- 1 => ['id' => 1, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '商城'],
- 2 => ['id' => 2, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '申请会员'],
- 3 => ['id' => 3, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '点我付款'],
- ];
-
- //商家信息组合 shish 2019.12.20
- public static function groupMerchantBaseInfo($list)
- {
- return $list;
- }
-
- public static function getMerchantByIds($ids)
- {
- return self::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
- }
-
- public static function getMerchantById($id)
- {
- $merchant = self::getById($id);
- if (empty($merchant)) {
- return $merchant;
- }
- $list = self::groupBaseInfo([$merchant]);
- return current($list);
- }
-
- public static function groupBaseInfo($list)
- {
- foreach ($list as $key => $val) {
- $list[$key] = business::formatMerchantLogo($list[$key]);
- $list[$key]['address'] = '福建省厦门市思明区上湖社1017号';
- }
- return $list;
- }
-
- //创建商家信息 shish 2020.2.11
- public static function generateMerchant($data)
- {
- //生成商家
- $date = date("Y-m-d H:i:s");
- $time = time();
- $data['accountStyle'] = 0;//认证服务号
- $data['status'] = 0;//待审核
- $data['createTime'] = $date;
- $data['updateTime'] = $date;
- $data['shopLat'] = isset($data['lat']) ? $data['lat'] : (string)0;
- $data['shopLong'] = isset($data['long']) ? $data['long'] : (string)0;
- $data['shopPrecision'] = (string)0;
- $data['wxToken'] = stringUtil::buildWxToken(0);
- $data['shopPhotoList'] = isset($data['shopPhotoList']) ? $data['shopPhotoList'] : '';
- $data['merchantName'] = isset($data['merchantName']) ? $data['merchantName'] : '';
- $data['shopProvince'] = isset($data['province']) ? $data['province'] : '';
- $data['shopCity'] = isset($data['city']) ? $data['city'] : '';
- $data['shopDist'] = isset($data['dist']) ? $data['dist'] : '';
- $data['shopAddress'] = isset($data['address']) ? $data['address'] : '';
- $data['alipayAccount'] = isset($data['alipayAccount']) ? $data['alipayAccount'] : '';
- $data['alipayAccountName'] = isset($data['alipayAccountName']) ? $data['alipayAccountName'] : '';
- //默认设置为代理商
- $data['agentLevel'] = 1;
- //申请表的id去掉,商家有自己的id
- unset($data['id']);
- $merchant = self::add($data);
- $adminId = $data['adminId'];
- $merchantId = $merchant['id'];
- $mobile = $data['mobile'];
- //生成商家资产
- $assetData = [
- 'balance' => 0,
- 'totalVisit' => 0,
- 'totalUser' => 0,
- 'totalMember' => 0,
- 'totalFans' => 0,
- 'totalWeixinFans' => 0,
- 'totalIntegral' => 0,
- 'totalPoint' => 0,
- 'totalGoods' => 0,
- 'totalRecharge' => 0,
- 'totalOrder' => 0,
- 'totalDeal' => 0,
- 'merchantId' => $merchantId,
- 'totalIncome' => 0,
- 'totalExpend' => 0,
- 'createTime' => $date,
- 'updateTime' => $date,
- ];
- //商家资产表
- MerchantAssetClass::add($assetData);
-
- //生成商家拓展信息
- $extendData = [
- 'merchantId' => $merchantId,
- 'wxAppId' => isset($data['wxAppId']) ? $data['wxAppId'] : '',
- 'webTitle' => isset($data['merchantName']) ? $data['merchantName'] : '',
- 'webKeyword' => isset($data['merchantName']) ? $data['merchantName'] : '',
- 'webDescription' => isset($data['merchantName']) ? $data['merchantName'] : '',
- 'wxMenuInit' => 0,
- 'wxTMessageInit' => 0,
- 'payment' => 0,//支付功能关闭
- 'recharge' => 0,//充值功能关闭
- 'giveCoupon' => 1,//默认赠送代金劵
- 'giveCouponPrice' => 5,//代金劵金额5元
- 'couponMeetPrice' => 180,//满足金额
- 'couponValidity' => 30,//代金劵有效期30天
- 'alipayAccount' => isset($data['alipayAccount']) ? $data['alipayAccount'] : '',//提现的支付宝帐号
- 'alipayAccountName' => isset($data['alipayAccountName']) ? $data['alipayAccountName'] : '',//提现支付宝帐号姓名
- 'gradeList' => '1_2000_0.9I2_5000_0.88I3_10000_0.85I4_20000_0.8',//1 级会员需要满 2000 积分 购物享9折;2 级会员需要满 5000 积分 购物享88折
- 'createTime' => $date,
- 'updateTime' => $date,
- ];
- MerchantExtendClass::add($extendData);
-
- MerchantInitClass::add(['merchantId' => $merchantId]);
-
- //商家商品配置信息
- $setData = [
- 'merchantId' => $merchantId,
- 'riseType' => 0,
- 'riseAmount' => 0,
- 'addTime' => time(),
- ];
- GoodsSettingClass::add($setData);
-
- //创建门店
- $shopData = [
- 'shopName' => $merchant['merchantName'],
- 'merchantId' => $merchantId,
- 'addTime' => $time,
- 'createTime' => $date,
- 'updateTime' => $date,
- 'openTime' => '8:00 - 23:00',
- 'telephone' => $mobile,
- 'introduction' => '欢迎光临',
- 'province' => isset($data['province']) ? $data['province'] : '',
- 'city' => isset($data['city']) ? $data['city'] : '',
- 'dist' => isset($data['dist']) ? $data['dist'] : '',
- 'default' => 1,
- 'address' => isset($data['address']) ? $data['address'] : '',
- 'fullAddress' => isset($data['fullAddress']) ? $data['fullAddress'] : '',
- ];
- $shopReturn = ShopClass::addShop($shopData);
- $shopId = $shopReturn['id'];
- //设置商家默认门店
- MerchantClass::updateById($merchantId, ['defaultShopId' => $shopId]);
-
- //创建管理员角色
- $hasRole = AdminRoleClass::getByCondition(['merchantId' => $merchantId]);
- if (empty($hasRole)) {
- AdminRoleClass::addAdminRole(['roleName' => '店员', 'merchantId' => $merchantId, 'auth' => '*']);
- $roleReturn = AdminRoleClass::addAdminRole(['roleName' => '老板', 'merchantId' => $merchantId, 'auth' => '*']);
- $roleId = $roleReturn['id'];
- }
-
- //创建管理员
- $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $shopId, 'adminId' => $adminId]);
- if (empty($shopAdmin)) {
- $adminData = [
- 'password' => password_hash($mobile, PASSWORD_BCRYPT),
- 'confirmPassword' => password_hash($mobile, PASSWORD_BCRYPT),
- 'mobile' => $mobile
- ];
- AdminClass::updateById($adminId, $adminData);
- $shopData = [
- 'adminId' => $adminId,
- 'shopId' => $shopId,
- 'merchantId' => $merchantId,
- 'remind' => 1,
- 'roleId' => $roleId,
- 'default' => 1,
- 'addTime' => $time,
- ];
- print_r($shopData);
- ShopAdminClass::add($shopData);
- }
-
- //商品和分类初始化
- CategoryClass::initCategoryGoods($merchantId);
-
- //商城和门店广告初始化
- AdClass::initAdd($merchantId);
-
- //优惠券资产与配置信息初始化
- CouponAssetClass::add(['merchantId' => $merchantId, 'switch' => 1]);
-
- return $merchant;
- }
-
- //h5商城链接二维码 shish 2020.4.30
- public static function getH5MallQrCode($id)
- {
- $url = Yii::$app->params['mallDomain'] . "/#/?account=" . $id;
- //强制转成https
- $url = httpUtil::becomeHttps($url);
- $respond = qrCodeUtil::generateH5MallQrCode($url);
- return isset($respond['url']) ? $respond['url'] : '';
- }
- }
|