| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- namespace biz\product\classes;
- use biz\base\classes\BaseClass;
- use common\components\imgUtil;
- class XjClass extends BaseClass
- {
- public static $baseFile = '\biz\product\models\Xj';
- public static function getAllXj()
- {
- $where = [];
- $where['status'] = 1;
- $where['delStatus'] = 0;
- $list = self::getAllByCondition($where, null, '*', null);
- return self::groupInfo($list);
- }
- //获取商家小菊颜色
- public static function getSjXj($ext)
- {
- $xj = $ext->xj ?? '';
- $ids = json_decode($xj, true);
- $list = self::getAllByCondition(['id' => ['in', $ids]], null, '*', null);
- return self::groupInfo($list);
- }
- public static function groupInfo($list)
- {
- if (empty($list)) {
- return [];
- }
- foreach ($list as $key => $val) {
- $shortCover = $val['cover'] ?? '';
- $cover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
- $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
- $list[$key]['cover'] = $cover;
- $list[$key]['shortCover'] = $shortCover;
- $list[$key]['bigCover'] = $bigCover;
- }
- return $list;
- }
- // 获取当前门店小菊的总数
- public static function getXjCount($shopId)
- {
- $where = [];
- $where['shopId'] = $shopId;
- $where['delStatus'] = 0;
- return self::getCount($where);
- }
- //新增小菊
- public static function addXj($shopId, $cover, $shopExt)
- {
- $count = self::getXjCount($shopId);
- if ($count < 10) {
- $count++;
- $count = "0" . $count;
- }
- $name = "小菊" . $count;
- $data = [];
- $data['cover'] = $cover;
- $data['name'] = $name;
- $data['shopId'] = $shopId;
- $data['status'] = 1;
- $res = self::add($data);
- $id = $res['id'];
- //启用
- $xj = $shopExt->xj;
- $hasIds = [];
- if (!empty($xj)) {
- $hasIds = json_decode($xj, true);
- }
- if (in_array($id, $hasIds) == false) {
- $hasIds[] = $id;
- $shopExt->xj = json_encode($hasIds);
- $shopExt->save();
- }
- }
- //批量添加 ssh 20211210
- public static function batchAddXj($arr, $shop, $itemInfo)
- {
- $shopId = $shop->id ?? 0;
- $sjId = $shop->sjId ?? 0;
- $mainId = $shop->mainId ?? 0;
- $itemId = $itemInfo->id ?? 0;
- $ptItemId = $itemInfo->itemId ?? 0;
- $max = self::getByCondition(['shopId' => $shopId, 'delStatus' => 0], true, 'no DESC');
- $maxId = $max->no ?? 0;
- $itemName = $itemInfo->name ?? '';
- $stock = $itemInfo->stock ? floatval($itemInfo->stock) : 0;
- foreach ($arr as $key => $imgUrl) {
- $maxId++;
- $name = $itemName . $maxId;
- $data = [
- 'cover' => $imgUrl,
- 'name' => $name,
- 'no' => $maxId,
- 'status' => 1,
- 'shopId' => $shopId,
- 'sjId' => $sjId,
- 'mainId' => $mainId,
- 'itemId' => $itemId,
- 'ptItemId' => $ptItemId,
- 'stock' => $stock,
- ];
- self::add($data);
- }
- }
- //获取当前门店下所有的xj
- public static function getShopXj($shopId)
- {
- $where = [];
- $where['shopId'] = $shopId;
- $where['status'] = 1;
- $where['delStatus'] = 0;
- $list = self::getAllByCondition($where, null, '*', null);
- return self::groupInfo($list);
- }
- }
|