| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?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['id'] = $v['goods_id'];
- $v['box_pic'] = isset($v['box_pic'])? getPreviewUrl($v['box_pic']):'';
- $v['goods_img'] = $v['goods_img']? getPreviewUrl($v['goods_img']):'';
- $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_img'] = $data['goods_img']? getPreviewUrl($data['goods_img']):'';
- $data['box_pic'] = $data['box_pic']? getPreviewUrl($data['box_pic']):'';
- $banners = $data['goods_img_banner']? json_decode($data['goods_img_banner'], true): [];
- if($banners){
- foreach ($banners as &$v){
- $v = getPreviewUrl($v);
- }
- }
- $data['goods_img_banner'] = $banners?implode('|',$banners):'';
- $data['goods_remark'] = getContent(htmlspecialchars_decode($data['goods_remark']));
- $specRelation = ShopGoodsSpecRelation::getArrListByGoodsId($id);
- $specAttrId = isset($specRelation[0])?ShopGoodsSpecType::getPidById($specRelation[0]['spec_id']):0;
- if ($data['is_exist_many_spec'] == 0) {
- $data['defaultSku'] = ShopGoodsSpec::getGoodsSpecByGoodId($id);
- if(empty($data['defaultSku'])){
- $data['defaultSku'] = [
- 'price'=> 0.00,
- 'original_price'=>0.00,
- 'cost_price'=>0.00,
- 'stock'=> 0,
- ];
- }
- }
- $hot_keywords = ShopHotKeywordsLogic::getCacheList();
- $shop_supplier = ShopSupplierLogic::getCacheList();
- $shop_goods_type = ShopGoodsTypeLogic::getCacheList();
- return [$data, $hot_keywords, $shop_goods_type, $shop_supplier, $specAttrId];
- }
- }
|