ShopClass.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. namespace bizHd\shop\classes;
  3. use biz\shop\classes\ShopExtClass;
  4. use bizHd\ad\classes\AdClass;
  5. use bizHd\admin\classes\AdminClass;
  6. use bizHd\goods\classes\CategoryClass;
  7. use bizHd\goods\classes\GoodsSettingClass;
  8. use bizHd\merchant\classes\SjClass;
  9. use bizHd\saas\classes\ApplyClass;
  10. use common\components\dict;
  11. use common\components\imgUtil;
  12. use common\components\noticeUtil;
  13. use common\components\stringUtil;
  14. use common\components\util;
  15. use Yii;
  16. use bizHd\base\classes\BaseClass;
  17. class ShopClass extends BaseClass
  18. {
  19. public static $baseFile = '\bizHd\shop\models\Shop';
  20. //需要算上包装费
  21. public static function needAddPackCost($ghsShop, $customId, $orderAmount = 0)
  22. {
  23. if (isset($ghsShop->pfLevel) && $ghsShop->pfLevel == 1) {
  24. $current = date("Y_m_d");
  25. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  26. $has = Yii::$app->redis->executeCommand('GET', [$key]);
  27. if (!empty($has) && $has == 1) {
  28. return false;
  29. } else {
  30. return true;
  31. }
  32. } else {
  33. $lackExpend = $ghsShop->lackExpend ? floatval($ghsShop->lackExpend) : 0;
  34. $packCost = $ghsShop->packCost ? floatval($ghsShop->packCost) : 0;
  35. if ($lackExpend <= 0 || $packCost <= 0) {
  36. return false;
  37. }
  38. $current = date("Y_m_d");
  39. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  40. $has = Yii::$app->redis->executeCommand('GET', [$key]);
  41. if (!empty($has) && $has == 1) {
  42. return false;
  43. }
  44. if ($orderAmount > 0) {
  45. if ($orderAmount < $lackExpend) {
  46. return true;
  47. }
  48. } else {
  49. return true;
  50. }
  51. return false;
  52. }
  53. }
  54. public static function getNewShopList()
  55. {
  56. $where = ['ptStyle' => dict::getDict('ptStyle', 'hd')];
  57. $respond = self::getList('*', $where, 'addTime DESC');
  58. $list = $respond['list'] ?? [];
  59. if (!empty($list)) {
  60. foreach ($list as $key => $val) {
  61. $shopName = $val['shopName'] ?? '';
  62. $sjName = $val['merchantName'] ?? '';
  63. $default = $val['default'] ?? 0;
  64. $showName = $sjName . ' ' . $shopName;
  65. if ($default == 1) {
  66. $showName = $sjName;
  67. }
  68. $list[$key]['showName'] = $showName;
  69. $list[$key]['cover'] = imgUtil::groupImg('');
  70. }
  71. $respond['list'] = $list;
  72. }
  73. return $respond;
  74. }
  75. public static function getShopList($where)
  76. {
  77. $list = self::getList('*', $where, 'addTime DESC');
  78. $list['list'] = self::groupBaseInfo($list['list']);
  79. return $list;
  80. }
  81. //组装门店基本信息 ssh 2019.12.2
  82. public static function groupBaseInfo($list)
  83. {
  84. foreach ($list as $key => $val) {
  85. $list[$key]['img'] = json_decode($val['img'], true);
  86. if (isset($list[$key]['img']) && is_array($list[$key]['img'])) {
  87. foreach ($list[$key]['img'] as $img) {
  88. $list[$key]['imgUrl'][] = imgUtil::groupImg($img);
  89. }
  90. } else {
  91. $list[$key]['img'] = [];
  92. $list[$key]['imgUrl'] = [];
  93. }
  94. $superWx = $val['superWx'] ?? '';
  95. $shortSuperWx = $superWx;
  96. $list[$key]['shortSuperWx'] = $shortSuperWx;
  97. $list[$key]['superWx'] = imgUtil::groupImg($shortSuperWx) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  98. }
  99. return $list;
  100. }
  101. public static function addMainShop($data, $oldShop, $sj)
  102. {
  103. if (isset($oldShop->pfShopId) && !empty($oldShop->pfShopId)) {
  104. util::fail('请在批发端操作');
  105. }
  106. $mobile = $data['mobile'] ?? 0;
  107. if (empty($mobile) || stringUtil::isMobile($mobile) == false) {
  108. util::fail('请输入正确手机号');
  109. }
  110. $hasShop = ShopClass::getByCondition(['mobile' => $mobile], true);
  111. if (!empty($hasShop)) {
  112. util::fail('手机号已经使用');
  113. }
  114. $hasApply = ApplyClass::getByCondition(['mobile' => $mobile], true);
  115. if (!empty($hasApply)) {
  116. util::fail('手机号已注册过');
  117. }
  118. $defaultShopId = $sj['defaultShopId'] ?? 0;
  119. $defaultShop = self::getById($defaultShopId, true);
  120. if (empty($defaultShop)) {
  121. util::fail('没有找到门店50');
  122. }
  123. $oldMainId = $defaultShop->mainId ?? 0;
  124. if (empty($oldMainId)) {
  125. util::fail('没有找到main信息');
  126. }
  127. $main = MainClass::addMainCopyItem($oldMainId);
  128. $mainId = $main->id ?? 0;
  129. $data['mainId'] = $mainId;
  130. $newShop = self::addShop($data);
  131. return $newShop;
  132. }
  133. //创建门店 ssh 2020.2.8
  134. public static function addShop($data)
  135. {
  136. $data['createTime'] = date("Y-m-d H:i:s");
  137. $shopName = isset($data['shopName']) ? $data['shopName'] : '';
  138. $mainId = $data['mainId'] ?? 0;
  139. if (empty($shopName)) {
  140. util::fail('请填写门店名称');
  141. }
  142. if (stringUtil::getWordNum($shopName) > 8) {
  143. util::fail('门店名称不能超过8个汉字,2个字母顶一个汉字');
  144. }
  145. $exists = self::getByCondition(['sjId' => $data['sjId'], 'shopName' => $shopName]);
  146. if (!empty($exists)) {
  147. util::fail('门店名称已经存在');
  148. }
  149. //补充fullAddress lqh 2021.4.18
  150. $data['fullAddress'] = $data['city'] . $data['address'] . $data['floor'];
  151. $data['img'] = isset($data['img']) && !empty($data['img']) ? json_encode($data['img']) : '';
  152. if (isset($data['ptStyle']) == false) {
  153. util::fail('请先择平台类型');
  154. }
  155. $shop = self::add($data, true);
  156. $newShopId = $shop->id;
  157. $extData = ['shopId' => $newShopId];
  158. ShopExtClass::add($extData);
  159. //商品和分类初始化
  160. CategoryClass::initCategoryGoods($mainId);
  161. //商城和门店广告初始化
  162. AdClass::initAdd($mainId);
  163. //商品配置信息
  164. $setData = ['mainId' => $mainId, 'riseType' => 0, 'riseAmount' => 0];
  165. GoodsSettingClass::add($setData);
  166. //初始化员工和角色
  167. $adminId = $data['adminId'] ?? 0;
  168. $mobile = $data['mobile'] ?? 0;
  169. $initAdminData = ['mobile' => $mobile, 'adminId' => $adminId];
  170. AdminClass::initAdmin($initAdminData, $mainId, $shop);
  171. return $shop;
  172. }
  173. //获取首店id
  174. public static function getDefaultShopId($shop)
  175. {
  176. $sjId = $shop->sjId ?? 0;
  177. $sj = SjClass::getById($sjId, true);
  178. $defaultShopId = $sj->defaultShopId ?? 0;
  179. return $defaultShopId;
  180. }
  181. }