FengsuSku.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\common\model;
  4. use think\Model;
  5. use app\admin\service\FengsuService;
  6. //风速-发货记录
  7. class FengsuSku Extends Model
  8. {
  9. // 自动写入时间戳字段
  10. protected $autoWriteTimestamp = true;
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $type = [
  14. 'createtime' => 'timestamp:Y-m-d H:i',
  15. 'updatetime' => 'timestamp:Y-m-d H:i',
  16. ];
  17. public function stockconfig()
  18. {
  19. return $this->hasOne(StockConfig::class,'id','variety_id')->field('id,title');
  20. }
  21. //获取店铺下规格
  22. public static function getSpecsIdByShopId(string $shop_id, string $spec_id): object
  23. {
  24. // return self::where('shop_id', $shop_id)->where('sku_id', $spec_id)->findOrEmpty();
  25. $result = self::alias('f')
  26. ->where(['f.shop_id'=>$shop_id,'f.sku_id'=>$spec_id])
  27. ->join('yun_product_config p', 'f.variety_id = p.type_id AND f.spec_id = p.id', 'INNER')
  28. ->field([
  29. 'f.*',
  30. 'p.type_id',
  31. 'p.title as spec_name',
  32. 'p.another_name as box_name',
  33. 'p.weight',
  34. 'p.box_id'
  35. ])
  36. ->findOrEmpty();
  37. return $result;
  38. }
  39. //批量插入规格
  40. public static function insertSpecs(string $shop_id, string $sku_id, int $variety_id, int $spec_id)
  41. {
  42. return self::create(['shop_id'=> $shop_id, 'variety_id'=>$variety_id, 'spec_id'=>$spec_id, 'sku_id'=>$sku_id]);
  43. }
  44. }