123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- /**
- * 优惠券赠品模型
- *
- */
- class PromoRebate extends Model
- {
- use HasFactory;
- // 与模型关联的表名
- protected $table = 'promo_rebate';
- // 是否主动维护时间戳
- public $timestamps = false;
- // 定义时间戳字段名
- // const CREATED_AT = 'insert_time';
- // const UPDATED_AT = 'update_time';
- /**
- * 添加数据
- *
- */
- public function add($data)
- {
- // 时间
- $data['insert_time'] = time();
- $data['update_time'] = time();
- // 写入数据表
- $id = $this->query()->insertGetId($data);
- // 返回结果
- return $id;
- }
- /**
- * 添加数据
- *
- */
- public function edit($id,$data)
- {
- // 更新时间
- $data['update_time'] = time();
- // 写入数据表
- $result = $this->query()->where(['id'=>$id])->update($data);
- // 返回结果
- return $result;
- }
- /**
- * 优惠券赠品列表
- *
- */
- public function getProductByCouponId($couponId)
- {
- // 写入数据表
- $result = $this->query()->where([['promo_id','=',$couponId]])->get(['product_id','rebate_num'])->toArray();
- // 返回结果
- return $result;
- }
- /**
- * 查询赠品列表
- *
- * @param array $couponIds 优惠券列表
- *
- */
- public function getRebatesByCouponIds($couponIds)
- {
- // 写入数据表
- $result = $this->query()->join('product','promo_rebate.product_id','=','product.id')->whereIn('promo_id',$couponIds)->get(['promo_rebate.coupon_id','promo_rebate.product_id','promo_rebate.rebate_num','product.name as product_name','product.spec as product_spec'])->toArray();
- // 返回结果
- return $result;
- }
- }
|