| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- declare(strict_types=1);
- namespace app\common\model;
- use think\Model;
- use app\common\model\PackSpecs;
- class ImportSku Extends Model
- {
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = true;
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $type = [
- 'createtime' => 'timestamp:Y-m-d H:i',
- 'updatetime' => 'timestamp:Y-m-d H:i',
- ];
- public function stockconfig()
- {
- return $this->hasOne(StockConfig::class,'id','variety_id')->field('id,title');
- }
-
- //获取店铺下规格
- public static function getSpecsIdByShopId(string $shop_id, string $spec_id): object
- {
- // return self::where('shop_id', $shop_id)->where('sku_id', $spec_id)->findOrEmpty();
- $result = self::alias('f')
- ->where(['f.shop_id'=>$shop_id,'f.sku_id'=>$spec_id])
- ->join('yun_product_config p', 'f.variety_id = p.type_id AND f.spec_id = p.id', 'INNER')
- ->field([
- 'f.*',
- 'p.type_id',
- 'p.title as spec_name',
- 'p.weight',
- 'p.box_id'
- ])
- ->findOrEmpty();
- return $result;
- }
- //批量插入规格
- public static function insertSpecs(string $shop_id, string $sku_id, int $variety_id, int $spec_id)
- {
- return self::create(['shop_id'=> $shop_id, 'variety_id'=>$variety_id, 'spec_id'=>$spec_id, 'sku_id'=>$sku_id]);
- }
- //获规格下的打包规格
- public static function getPackSpecs(string $shop_id, string $spec_id)
- {
- // return self::where('shop_id', $shop_id)->where('sku_id', $spec_id)->findOrEmpty();
- $result = self::alias('f')
- ->where(['f.shop_id'=>$shop_id,'f.sku_id'=>$spec_id])
- ->join('yun_product_config p', 'f.variety_id = p.type_id AND f.spec_id = p.id', 'INNER')
- ->field([
- 'p.pack_specs_id'
- ])
- ->findOrEmpty();
- $pack_specs_id=$result->pack_specs_id;
- if(empty($pack_specs_id)) return null;
- $packSpecs=new PackSpecs();
- $result=$packSpecs->where('id',$pack_specs_id)->findOrEmpty();
- return $result;
- }
- }
|