// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\common\model; use cores\BaseModel; use app\common\library\helper; /** * 合作商关联商品券模型 * Class PartnersGoods * @package app\common\model */ class PartnersGoods extends BaseModel { // 定义表名 protected $name = 'partners_goods'; // 定义主键 protected $pk = 'id'; /** * 关联模型:商品 * @return \think\model\relation\HasOne */ public function goods(): \think\model\relation\HasOne { return $this->hasOne('Goods', 'id', 'goods_id'); } /** * 获取商品信息详情 * @param int $partnersId * @param int $goodsId * @return array|null|static */ public static function detail(int $partnersId, int $goodsId) { return static::get(['partners_id' => $partnersId, 'goods_id' => $goodsId]); } /** * 获取合作商商品列表 * @param int $partnersId 合作商ID * @return \think\Collection * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public static function getGoodsList(int $partnersId): \think\Collection { return (new static)->where('partners_id', '=', $partnersId)->order(['id' => 'asc'])->select(); } /** * 累计合作商使用数量 * @param int|array $where * @param int $num * @return mixed */ public static function setIncUseNum($where, int $num) { return (new static)->setInc($where, 'use_num', $num); } /** * 减少合作商库存数量 * @param int|array $where * @param int $num * @return mixed */ public static function setDecStockNum($where, int $num) { return (new static)->setDec($where, 'stock_num', $num); } }