XjClass.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace biz\product\classes;
  3. use biz\base\classes\BaseClass;
  4. use common\components\imgUtil;
  5. class XjClass extends BaseClass
  6. {
  7. public static $baseFile = '\biz\product\models\Xj';
  8. public static function getAllXj()
  9. {
  10. $where = [];
  11. $where['status'] = 1;
  12. $where['delStatus'] = 0;
  13. $list = self::getAllByCondition($where, null, '*', null);
  14. return self::groupInfo($list);
  15. }
  16. //获取商家小菊颜色
  17. public static function getSjXj($ext)
  18. {
  19. $xj = $ext->xj ?? '';
  20. $ids = json_decode($xj, true);
  21. $list = self::getAllByCondition(['id' => ['in', $ids]], null, '*', null);
  22. return self::groupInfo($list);
  23. }
  24. public static function groupInfo($list)
  25. {
  26. if (empty($list)) {
  27. return [];
  28. }
  29. foreach ($list as $key => $val) {
  30. $shortCover = $val['cover'] ?? '';
  31. $cover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  32. $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  33. $list[$key]['cover'] = $cover;
  34. $list[$key]['shortCover'] = $shortCover;
  35. $list[$key]['bigCover'] = $bigCover;
  36. }
  37. return $list;
  38. }
  39. // 获取当前门店小菊的总数
  40. public static function getXjCount($shopId)
  41. {
  42. $where = [];
  43. $where['shopId'] = $shopId;
  44. $where['delStatus'] = 0;
  45. return self::getCount($where);
  46. }
  47. //新增小菊
  48. public static function addXj($shopId, $cover, $shopExt)
  49. {
  50. $count = self::getXjCount($shopId);
  51. if ($count < 10) {
  52. $count++;
  53. $count = "0" . $count;
  54. }
  55. $name = "小菊" . $count;
  56. $data = [];
  57. $data['cover'] = $cover;
  58. $data['name'] = $name;
  59. $data['shopId'] = $shopId;
  60. $data['status'] = 1;
  61. $res = self::add($data);
  62. $id = $res['id'];
  63. //启用
  64. $xj = $shopExt->xj;
  65. $hasIds = [];
  66. if (!empty($xj)) {
  67. $hasIds = json_decode($xj, true);
  68. }
  69. if (in_array($id, $hasIds) == false) {
  70. $hasIds[] = $id;
  71. $shopExt->xj = json_encode($hasIds);
  72. $shopExt->save();
  73. }
  74. }
  75. //批量添加 ssh 20211210
  76. public static function batchAddXj($arr, $shop, $itemInfo)
  77. {
  78. $shopId = $shop->id ?? 0;
  79. $sjId = $shop->sjId ?? 0;
  80. $mainId = $shop->mainId ?? 0;
  81. $itemId = $itemInfo->id ?? 0;
  82. $ptItemId = $itemInfo->itemId ?? 0;
  83. $max = self::getByCondition(['shopId' => $shopId, 'delStatus' => 0], true, 'no DESC');
  84. $maxId = $max->no ?? 0;
  85. $itemName = $itemInfo->name ?? '';
  86. $stock = $itemInfo->stock ? floatval($itemInfo->stock) : 0;
  87. foreach ($arr as $key => $imgUrl) {
  88. $maxId++;
  89. $name = $itemName . $maxId;
  90. $data = [
  91. 'cover' => $imgUrl,
  92. 'name' => $name,
  93. 'no' => $maxId,
  94. 'status' => 1,
  95. 'shopId' => $shopId,
  96. 'sjId' => $sjId,
  97. 'mainId' => $mainId,
  98. 'itemId' => $itemId,
  99. 'ptItemId' => $ptItemId,
  100. 'stock' => $stock,
  101. ];
  102. self::add($data);
  103. }
  104. }
  105. //获取当前门店下所有的xj
  106. public static function getShopXj($shopId)
  107. {
  108. $where = [];
  109. $where['shopId'] = $shopId;
  110. $where['status'] = 1;
  111. $where['delStatus'] = 0;
  112. $list = self::getAllByCondition($where, null, '*', null);
  113. return self::groupInfo($list);
  114. }
  115. }