XjClass.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 clearAll($itemId)
  41. {
  42. $where = ['itemId' => $itemId];
  43. $data = ['status' => 2, 'delStatus' => 1];
  44. return self::updateByCondition($where, $data);
  45. }
  46. // 获取当前门店小菊的总数
  47. public static function getXjCount($shopId)
  48. {
  49. $where = [];
  50. $where['shopId'] = $shopId;
  51. $where['delStatus'] = 0;
  52. return self::getCount($where);
  53. }
  54. //新增小菊
  55. public static function addXj($shopId, $cover, $shopExt)
  56. {
  57. $count = self::getXjCount($shopId);
  58. if ($count < 10) {
  59. $count++;
  60. $count = "0" . $count;
  61. }
  62. $name = "小菊" . $count;
  63. $data = [];
  64. $data['cover'] = $cover;
  65. $data['name'] = $name;
  66. $data['shopId'] = $shopId;
  67. $data['status'] = 1;
  68. $res = self::add($data);
  69. $id = $res['id'];
  70. //启用
  71. $xj = $shopExt->xj;
  72. $hasIds = [];
  73. if (!empty($xj)) {
  74. $hasIds = json_decode($xj, true);
  75. }
  76. if (in_array($id, $hasIds) == false) {
  77. $hasIds[] = $id;
  78. $shopExt->xj = json_encode($hasIds);
  79. $shopExt->save();
  80. }
  81. }
  82. //批量添加 ssh 20211210
  83. public static function batchAddXj($arr, $shop, $itemInfo)
  84. {
  85. $shopId = $shop->id ?? 0;
  86. $sjId = $shop->sjId ?? 0;
  87. $mainId = $shop->mainId ?? 0;
  88. $itemId = $itemInfo->id ?? 0;
  89. $ptItemId = $itemInfo->itemId ?? 0;
  90. $max = self::getByCondition(['shopId' => $shopId, 'delStatus' => 0], true, 'no DESC');
  91. $maxId = $max->no ?? 0;
  92. $itemName = $itemInfo->name ?? '';
  93. $stock = $itemInfo->stock ? floatval($itemInfo->stock) : 0;
  94. foreach ($arr as $key => $imgUrl) {
  95. $maxId++;
  96. $name = $itemName . $maxId;
  97. $data = [
  98. 'cover' => $imgUrl,
  99. 'name' => $name,
  100. 'no' => $maxId,
  101. 'status' => 1,
  102. 'shopId' => $shopId,
  103. 'sjId' => $sjId,
  104. 'mainId' => $mainId,
  105. 'itemId' => $itemId,
  106. 'ptItemId' => $ptItemId,
  107. 'stock' => $stock,
  108. ];
  109. self::add($data);
  110. }
  111. }
  112. //获取当前门店下所有的xj
  113. public static function getShopXj($shopId)
  114. {
  115. $where = [];
  116. $where['shopId'] = $shopId;
  117. $where['status'] = 1;
  118. $where['delStatus'] = 0;
  119. $list = self::getAllByCondition($where, null, '*', null);
  120. return self::groupInfo($list);
  121. }
  122. }