| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace app\admin\logic;
- use app\admin\model\dao\ShopGoodsSpec;
- use app\admin\model\dao\ShopGoodsSpecRelation;
- use app\admin\model\dao\ShopGoodsSpecType;
- use app\admin\model\dao\ShopGoodsType;
- use app\common\model\ShopGoods;
- use think\db\Query;
- use think\facade\Cache;
- use think\facade\Db;
- /**
- * 商城商品
- * Class ShopGoodsLogic
- * @package app\admin\logic
- */
- class ShopGoodsLogic
- {
- /**
- * 数量统计
- * @return mixed
- * @throws \think\db\exception\DbException
- */
- public static function getCount()
- {
- $cacheKey = "caches:goods:counts";
- if (!Cache::has($cacheKey)) {
- $data = ShopGoods::where(['on_sale' => 1])->count('goods_id');
- if ($data) {
- Cache::set($cacheKey, $data, rand(3, 5));
- }
- return $data;
- }
- return Cache::get($cacheKey);
- }
- public static function getList($page, $limit, $where)
- {
- $model = new ShopGoods();
- $count = $model
- ->withJoin(['supplier', 'cate' => function (Query $query) {
- $query->where('cate.id', '>', 0);
- }], 'LEFT')
- ->where($where)
- ->count();
- $list = $model
- ->withJoin(['supplier', 'cate' => function (Query $query) {
- $query->where('cate.id', '>', 0);
- }], 'LEFT')
- ->where($where)
- ->page($page, $limit)
- ->order('goods_id desc')
- ->select()->toArray();
- foreach ($list as $k => &$v) {
- // $v['cate'] = ShopCategoryLogic::getCateById($v['category']);
- $v['id'] = $v['goods_id'];
- // $v['supplier'] = Db::name('shop_supplier')->where(['id'=>$v['supplier']])->value('name');
- $v['goods_type'] = ShopGoodsTypeLogic::getNameByCache($v['goods_type']);
- }
- return [$count, $list];
- }
- public static function getGoodsOrEmpty($id)
- {
- }
- public static function getGoodsBase($id)
- {
- $model = new ShopGoods();
- $data = $model->where(['goods_id' => $id])->findOrEmpty()->toArray();
- if ($data['goods_img_banner']) {
- $data['goods_img_banner'] = implode('|', json_decode($data['goods_img_banner'], true));
- }
- $data['goods_remark'] = htmlspecialchars_decode($data['goods_remark']);
- $specRelation = ShopGoodsSpecRelation::getArrListByGoodsId($id);
- $specAttrId = ShopGoodsSpecType::getPidById($specRelation[0]['spec_id']);
- if ($data['is_exist_many_spec'] == 0) {
- $data['defaultSku'] = ShopGoodsSpec::getGoodsSpecByGoodId($id);
- }
- $hot_keywords = ShopHotKeywordsLogic::getCacheList();
- $shop_supplier = ShopSupplierLogic::getCacheList();
- $shop_goods_type = ShopGoodsTypeLogic::getCacheList();
- return [$data, $hot_keywords, $shop_goods_type, $shop_supplier, $specAttrId];
- }
- }
|