SjService.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. namespace bizHd\merchant\services;
  3. use bizGhs\custom\services\CustomService;
  4. use bizHd\base\services\BaseService;
  5. use bizHd\custom\classes\CustomClass;
  6. use bizHd\goods\classes\KindClass;
  7. use bizHd\member\classes\MemberLevelClass;
  8. use bizHd\merchant\classes\SjAssetClass;
  9. use bizHd\merchant\classes\SjClass;
  10. use bizHd\merchant\classes\SjExtendClass;
  11. use bizHd\merchant\classes\SjInitClass;
  12. use bizHd\recharge\classes\RechargeSqClass;
  13. use bizHd\saas\classes\ApplyClass;
  14. use bizHd\shop\classes\ShopClass;
  15. use bizHd\user\classes\UserClass;
  16. use common\components\dict;
  17. use common\components\noticeUtil;
  18. use common\components\stringUtil;
  19. use Yii;
  20. class SjService extends BaseService
  21. {
  22. public static $baseFile = '\bizHd\merchant\classes\SjClass';
  23. public static function initHdBaseInfo($applyData, $main, $applyOpen = false)
  24. {
  25. $applyId = $applyData['id'] ?? 0;
  26. $adminId = $applyData['adminId'] ?? 0;
  27. $live = isset($applyData['live']) ? $applyData['live'] : 1;
  28. $mainId = $main->id ?? 0;
  29. unset($applyData['id']);
  30. $ptStyle = dict::getDict('ptStyle', 'hd');
  31. //生成商家
  32. $applyData['accountStyle'] = 0;
  33. $applyData['status'] = 1;
  34. $applyData['lat'] = $applyData['lat'] ?? (string)0;
  35. $applyData['long'] = $applyData['long'] ?? (string)0;
  36. $applyData['precision'] = (string)0;
  37. $applyData['wxToken'] = stringUtil::buildWxToken(0);
  38. $applyData['photoList'] = $applyData['photoList'] ?? '';
  39. $applyData['name'] = $applyData['name'] ?? '';
  40. $applyData['province'] = $applyData['province'] ?? '';
  41. $applyData['city'] = $applyData['city'] ?? '';
  42. $applyData['dist'] = $applyData['dist'] ?? '';
  43. $applyData['address'] = $applyData['address'] ?? '';
  44. $applyData['agentLevel'] = 1;
  45. $deadline = time() + 365 * 86400 * 2;
  46. $applyData['deadline'] = date("Y-m-d H:i:s", $deadline);
  47. if ($applyOpen) {
  48. $applyData['parentId'] = $applyData['introSjId'] ?? 0;
  49. $applyData['parentShopId'] = $applyData['introShopId'] ?? 0;
  50. }
  51. $jsData = $applyData;
  52. $sjData['style'] = $ptStyle;
  53. $sjData['live'] = $live;
  54. $sj = self::add($jsData, true);
  55. $sjId = $sj->id;
  56. $sjName = $sj->name ?? 0;
  57. $mobile = $applyData['mobile'] ?? '';
  58. if (!empty($applyId) && $applyOpen == true) {
  59. ApplyClass::updateById($applyId, ['sjId' => $sjId]);
  60. }
  61. //生成资产
  62. $assetData = [
  63. 'balance' => 0,
  64. 'totalVisit' => 0,
  65. 'totalUser' => 0,
  66. 'totalMember' => 0,
  67. 'totalFans' => 0,
  68. 'totalIntegral' => 0,
  69. 'totalPoint' => 0,
  70. 'totalGoods' => 0,
  71. 'totalRecharge' => 0,
  72. 'totalOrder' => 0,
  73. 'totalDeal' => 0,
  74. 'sjId' => $sjId,
  75. 'totalIncome' => 0,
  76. 'totalExpend' => 0,
  77. ];
  78. SjAssetClass::add($assetData);
  79. //生成商家拓展信息
  80. $extendData = [
  81. 'sjId' => $sjId,
  82. 'wxAppId' => isset($applyData['wxAppId']) ? $applyData['wxAppId'] : '',
  83. 'webTitle' => isset($applyData['name']) ? $applyData['name'] : '',
  84. 'webKeyword' => isset($applyData['name']) ? $applyData['name'] : '',
  85. 'webDescription' => isset($applyData['name']) ? $applyData['name'] : '',
  86. 'wxMenuInit' => 0,
  87. 'wxTMessageInit' => 0,
  88. 'payment' => 0,//支付功能关闭
  89. 'recharge' => 0,//充值功能关闭
  90. 'giveCoupon' => 1,//默认赠送代金劵
  91. 'giveCouponPrice' => 5,//代金劵金额5元
  92. 'couponMeetPrice' => 180,//满足金额
  93. 'couponValidity' => 30,//代金劵有效期30天
  94. 'alipayAccount' => isset($applyData['alipayAccount']) ? $applyData['alipayAccount'] : '',//提现的支付宝帐号
  95. 'alipayAccountName' => isset($applyData['alipayAccountName']) ? $applyData['alipayAccountName'] : '',//提现支付宝帐号姓名
  96. 'gradeList' => '1_2000_0.9I2_5000_0.88I3_10000_0.85I4_20000_0.8',//1 级会员需要满 2000 积分 购物享9折;2 级会员需要满 5000 积分 购物享88折
  97. ];
  98. SjExtendClass::add($extendData);
  99. SjInitClass::add(['sjId' => $sjId]);
  100. $onlyCg = 1;
  101. //app注册的,打开全部功能
  102. if (isset($applyData['appRegister']) && $applyData['appRegister'] == 1) {
  103. //$onlyCg = 0;
  104. }
  105. //给10天时间
  106. $deadTime = time()+864000;
  107. //创建门店
  108. $shopData = [
  109. 'shopName' => '首店',
  110. 'sjId' => $sjId,
  111. 'merchantName' => $sjName,
  112. 'telephone' => $mobile,
  113. 'default' => 1,
  114. 'adminId' => $adminId,
  115. 'mainId' => $mainId,
  116. 'parentId' => $applyData['introSjId'] ?? 0,
  117. 'parentShopId' => $applyData['introShopId'] ?? 0,
  118. 'mobile' => $mobile,
  119. 'introduction' => '欢迎光临',
  120. 'province' => $applyData['province'] ?? '',
  121. 'city' => $applyData['city'] ?? '',
  122. 'dist' => $applyData['dist'] ?? '',
  123. 'address' => $applyData['address'] ?? '',
  124. 'floor' => $applyData['floor'] ?? '',
  125. 'fullAddress' => $applyData['fullAddress'] ?? '',
  126. 'showAddress' => $applyData['showAddress'] ?? '',
  127. 'open' => 1,
  128. 'lat' => $applyData['lat'] ?? '',
  129. 'long' => $applyData['long'] ?? '',
  130. 'img' => ['/example/shop/1.jpg'],
  131. 'ptStyle' => $ptStyle,
  132. 'live' => $live,
  133. 'onlyCg' => $onlyCg,
  134. 'deadline'=> date("Y-m-d H:i:s", $deadTime),
  135. 'beforeDeadline'=> date("Y-m-d H:i:s"),
  136. ];
  137. $shopInfo = ShopClass::addShop($shopData);
  138. $shopId = $shopInfo->id;
  139. //变更状态和设置商家的默认门店
  140. $sjData = [];
  141. $sjData['defaultShopId'] = $shopId;
  142. $sjStatus = SjClass::STATUS_HAS_CHECK;
  143. $sjData['status'] = $sjStatus;
  144. SjClass::updateById($sjId, $sjData);
  145. //建立供货商和客户关系
  146. if ($applyOpen) {
  147. CustomService::shareBuildTrade($applyData, $shopInfo);
  148. }
  149. //生成保存默认客户
  150. $user = UserClass::replaceUser(['mobile' => $mobile]);
  151. $result = CustomClass::buildRelation($shopInfo, $user);
  152. $custom = $result['custom'];
  153. $customId = $custom->id ?? 0;
  154. $shopInfo->defaultCustomId = $customId;
  155. $shopInfo->save();
  156. if ($live == 1) {
  157. //初始化种类
  158. $initKindData = ['mainId' => $mainId, 'sjId' => $sjId];
  159. KindClass::initKind($initKindData);
  160. }
  161. //充值送钱初始化
  162. RechargeSqClass::initData($shopInfo);
  163. //会员等级初始化
  164. MemberLevelClass::initData($shopInfo);
  165. return ['sj' => $sj, 'shop' => $shopInfo];
  166. }
  167. }