MerchantClass.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. namespace biz\merchant\classes;
  3. use biz\ad\classes\AdClass;
  4. use biz\admin\classes\AdminRoleClass;
  5. use biz\admin\classes\ShopAdminClass;
  6. use biz\coupon\classes\CouponAssetClass;
  7. use biz\goods\classes\CategoryClass;
  8. use biz\goods\classes\GoodsSettingClass;
  9. use common\components\business;
  10. use common\components\httpUtil;
  11. use common\components\qrCodeUtil;
  12. use common\components\stringUtil;
  13. use Yii;
  14. use biz\base\classes\BaseClass;
  15. class MerchantClass extends BaseClass
  16. {
  17. public static $baseFile = '\biz\merchant\models\Merchant';
  18. //常用链接
  19. public static $commonUrl = [
  20. 1 => ['id' => 1, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '商城'],
  21. 2 => ['id' => 2, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '申请会员'],
  22. 3 => ['id' => 3, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '点我付款'],
  23. ];
  24. //商家信息组合 shish 2019.12.20
  25. public static function groupMerchantBaseInfo($list)
  26. {
  27. return $list;
  28. }
  29. public static function getMerchantByIds($ids)
  30. {
  31. return self::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
  32. }
  33. public static function getMerchantById($id)
  34. {
  35. $merchant = self::getById($id);
  36. if (empty($merchant)) {
  37. return $merchant;
  38. }
  39. $list = self::groupBaseInfo([$merchant]);
  40. return current($list);
  41. }
  42. public static function groupBaseInfo($list)
  43. {
  44. foreach ($list as $key => $val) {
  45. $list[$key] = business::formatMerchantLogo($list[$key]);
  46. $list[$key]['address'] = '福建省厦门市思明区上湖社1017号';
  47. }
  48. return $list;
  49. }
  50. //创建商家信息 shish 2020.2.11
  51. public static function generateMerchant($data)
  52. {
  53. //生成商家
  54. $date = date("Y-m-d H:i:s");
  55. $time = time();
  56. $data['accountStyle'] = 0;//认证服务号
  57. $data['status'] = 0;//待审核
  58. $data['createTime'] = $date;
  59. $data['updateTime'] = $date;
  60. $data['shopLat'] = isset($data['lat']) ? $data['lat'] : (string)0;
  61. $data['shopLong'] = isset($data['long']) ? $data['long'] : (string)0;
  62. $data['shopPrecision'] = (string)0;
  63. $data['wxToken'] = stringUtil::buildWxToken(0);
  64. $data['shopPhotoList'] = isset($data['shopPhotoList']) ? $data['shopPhotoList'] : '';
  65. $data['merchantName'] = isset($data['merchantName']) ? $data['merchantName'] : '';
  66. $data['shopProvince'] = isset($data['province']) ? $data['province'] : '';
  67. $data['shopCity'] = isset($data['city']) ? $data['city'] : '';
  68. $data['shopDist'] = isset($data['dist']) ? $data['dist'] : '';
  69. $data['shopAddress'] = isset($data['address']) ? $data['address'] : '';
  70. $data['alipayAccount'] = isset($data['alipayAccount']) ? $data['alipayAccount'] : '';
  71. $data['alipayAccountName'] = isset($data['alipayAccountName']) ? $data['alipayAccountName'] : '';
  72. //默认设置为代理商
  73. $data['agentLevel'] = 1;
  74. //申请表的id去掉,商家有自己的id
  75. unset($data['id']);
  76. $merchant = self::add($data);
  77. $adminId = $data['adminId'];
  78. $merchantId = $merchant['id'];
  79. $mobile = $data['mobile'];
  80. //生成商家资产
  81. $assetData = [
  82. 'balance' => 0,
  83. 'totalVisit' => 0,
  84. 'totalUser' => 0,
  85. 'totalMember' => 0,
  86. 'totalFans' => 0,
  87. 'totalWeixinFans' => 0,
  88. 'totalIntegral' => 0,
  89. 'totalPoint' => 0,
  90. 'totalGoods' => 0,
  91. 'totalRecharge' => 0,
  92. 'totalOrder' => 0,
  93. 'totalDeal' => 0,
  94. 'merchantId' => $merchantId,
  95. 'totalIncome' => 0,
  96. 'totalExpend' => 0,
  97. 'createTime' => $date,
  98. 'updateTime' => $date,
  99. ];
  100. //商家资产表
  101. MerchantAssetClass::add($assetData);
  102. //生成商家拓展信息
  103. $extendData = [
  104. 'merchantId' => $merchantId,
  105. 'wxAppId' => isset($data['wxAppId']) ? $data['wxAppId'] : '',
  106. 'webTitle' => isset($data['merchantName']) ? $data['merchantName'] : '',
  107. 'webKeyword' => isset($data['merchantName']) ? $data['merchantName'] : '',
  108. 'webDescription' => isset($data['merchantName']) ? $data['merchantName'] : '',
  109. 'wxMenuInit' => 0,
  110. 'wxTMessageInit' => 0,
  111. 'payment' => 0,//支付功能关闭
  112. 'recharge' => 0,//充值功能关闭
  113. 'giveCoupon' => 1,//默认赠送代金劵
  114. 'giveCouponPrice' => 5,//代金劵金额5元
  115. 'couponMeetPrice' => 180,//满足金额
  116. 'couponValidity' => 30,//代金劵有效期30天
  117. 'alipayAccount' => isset($data['alipayAccount']) ? $data['alipayAccount'] : '',//提现的支付宝帐号
  118. 'alipayAccountName' => isset($data['alipayAccountName']) ? $data['alipayAccountName'] : '',//提现支付宝帐号姓名
  119. 'gradeList' => '1_2000_0.9I2_5000_0.88I3_10000_0.85I4_20000_0.8',//1 级会员需要满 2000 积分 购物享9折;2 级会员需要满 5000 积分 购物享88折
  120. 'createTime' => $date,
  121. 'updateTime' => $date,
  122. ];
  123. MerchantExtendClass::add($extendData);
  124. MerchantInitClass::add(['merchantId' => $merchantId]);
  125. //商家商品配置信息
  126. $setData = [
  127. 'merchantId' => $merchantId,
  128. 'riseType' => 0,
  129. 'riseAmount' => 0,
  130. 'addTime' => time(),
  131. ];
  132. GoodsSettingClass::add($setData);
  133. //创建门店
  134. $shopData = [
  135. 'shopName' => $merchant['merchantName'],
  136. 'merchantId' => $merchantId,
  137. 'addTime' => $time,
  138. 'createTime' => $date,
  139. 'updateTime' => $date,
  140. 'openTime' => '8:00 - 23:00',
  141. 'telephone' => $mobile,
  142. 'introduction' => '欢迎光临',
  143. 'province' => isset($data['province']) ? $data['province'] : '',
  144. 'city' => isset($data['city']) ? $data['city'] : '',
  145. 'dist' => isset($data['dist']) ? $data['dist'] : '',
  146. 'default' => 1,
  147. 'address' => isset($data['address']) ? $data['address'] : '',
  148. 'fullAddress' => isset($data['fullAddress']) ? $data['fullAddress'] : '',
  149. ];
  150. $shopReturn = ShopClass::addShop($shopData);
  151. $shopId = $shopReturn['id'];
  152. //设置商家默认门店
  153. MerchantClass::updateById($merchantId, ['defaultShopId' => $shopId]);
  154. //创建管理员角色
  155. $hasRole = AdminRoleClass::getByCondition(['merchantId' => $merchantId]);
  156. if (empty($hasRole)) {
  157. AdminRoleClass::addAdminRole(['roleName' => '店员', 'merchantId' => $merchantId, 'auth' => '*']);
  158. $roleReturn = AdminRoleClass::addAdminRole(['roleName' => '老板', 'merchantId' => $merchantId, 'auth' => '*']);
  159. $roleId = $roleReturn['id'];
  160. }
  161. //创建管理员
  162. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $shopId, 'adminId' => $adminId]);
  163. if (empty($shopAdmin)) {
  164. $adminData = [
  165. 'password' => password_hash($mobile, PASSWORD_BCRYPT),
  166. 'confirmPassword' => password_hash($mobile, PASSWORD_BCRYPT),
  167. 'mobile' => $mobile
  168. ];
  169. AdminClass::updateById($adminId, $adminData);
  170. $shopData = [
  171. 'adminId' => $adminId,
  172. 'shopId' => $shopId,
  173. 'merchantId' => $merchantId,
  174. 'remind' => 1,
  175. 'roleId' => $roleId,
  176. 'default' => 1,
  177. 'addTime' => $time,
  178. ];
  179. print_r($shopData);
  180. ShopAdminClass::add($shopData);
  181. }
  182. //商品和分类初始化
  183. CategoryClass::initCategoryGoods($merchantId);
  184. //商城和门店广告初始化
  185. AdClass::initAdd($merchantId);
  186. //优惠券资产与配置信息初始化
  187. CouponAssetClass::add(['merchantId' => $merchantId, 'switch' => 1]);
  188. return $merchant;
  189. }
  190. //h5商城链接二维码 shish 2020.4.30
  191. public static function getH5MallQrCode($id)
  192. {
  193. $url = Yii::$app->params['mallDomain'] . "/#/?account=" . $id;
  194. //强制转成https
  195. $url = httpUtil::becomeHttps($url);
  196. $respond = qrCodeUtil::generateH5MallQrCode($url);
  197. return isset($respond['url']) ? $respond['url'] : '';
  198. }
  199. }