ShopClass.php 7.9 KB

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