SjService.php 5.8 KB

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