ShopClass.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace bizGhs\shop\classes;
  3. use biz\shop\classes\ShopExtClass;
  4. use bizGhs\admin\classes\AdminClass;
  5. use common\components\stringUtil;
  6. use common\components\util;
  7. use bizHd\base\classes\BaseClass;
  8. use biz\sj\classes\SjClass;
  9. class ShopClass extends BaseClass
  10. {
  11. public static $baseFile = '\bizGhs\shop\models\Shop';
  12. //创建门店 ssh 2020.2.8
  13. public static function addShop($data)
  14. {
  15. $data['createTime'] = date("Y-m-d H:i:s");
  16. $shopName = isset($data['shopName']) ? $data['shopName'] : '';
  17. if (empty($shopName)) {
  18. util::fail('请填写门店名称');
  19. }
  20. if (stringUtil::getWordNum($shopName) > 8) {
  21. util::fail('门店名称不能超过8个汉字,2个字母顶一个汉字');
  22. }
  23. $exists = self::getByCondition(['sjId' => $data['sjId'], 'shopName' => $shopName]);
  24. if (!empty($exists)) {
  25. util::fail('门店名称已经存在');
  26. }
  27. //补充fullAddress lqh 2021.4.18
  28. $data['fullAddress'] = $data['city'] . $data['address'] . $data['floor'];
  29. $data['img'] = isset($data['img']) && !empty($data['img']) ? json_encode($data['img']) : '';
  30. if (isset($data['ptStyle']) == false) {
  31. util::fail('请先择平台类型');
  32. }
  33. $shop = self::add($data, true);
  34. $newShopId = $shop->id;
  35. $extData = ['shopId' => $newShopId];
  36. ShopExtClass::add($extData);
  37. //初始化员工和角色
  38. $mainId = $data['mainId'] ?? 0;
  39. $mobile = $data['mobile'] ?? 0;
  40. $adminId = $data['adminId'] ?? 0;
  41. $initAdminData = ['mobile' => $mobile, 'adminId' => $adminId];
  42. AdminClass::initAdmin($initAdminData, $mainId, $shop);
  43. return $shop;
  44. }
  45. // 通过分店门店id取首店门店id
  46. public static function getDefaultShopId($shopId)
  47. {
  48. $shop = self::getById($shopId);
  49. if (empty($shop)) {
  50. return null;
  51. }
  52. $sjId = $shop['sjId'];
  53. $sj = SjClass::getById($sjId);
  54. if (empty($sj)) {
  55. return null;
  56. }
  57. return $sj['defaultShopId'];
  58. }
  59. }