12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace app\common\model\fullsend;
- use app\common\model\BaseModel;
- use app\common\model\Goods;
- use think\facade\Log;
- /**
- * 满就送活动模型
- * @package app\store\model\coupon
- */
- class FullSendGiftGoods extends BaseModel
- {
- protected $name = 'full_send_gift_goods';
- // 定义主键
- protected $pk = 'id';
- protected $append = ['goods_info'];
- public function getGoodsInfoAttr($value,$data){
- $res = Goods::alias('gd')
- ->leftJoin('goods_image gi','gd.goods_id=gi.goods_id')
- ->leftJoin('goods_sku gs','gd.goods_id=gs.goods_id')
- ->leftJoin('upload_file uf','gi.image_id=uf.file_id')
- ->where('gd.goods_id',$data['goods_id'])
- ->field('gd.goods_name,gd.goods_no,gd.goods_price_min,gd.status,gi.image_id,uf.domain,uf.file_path,gs.goods_props')->find();
- $res->goods_props_obj = $res->goods_props?json_decode($res->goods_props):null;
- $res->goods_image = $res->domain.'/'.$res->file_path;
- return $res;
- //return Goods::where('goods_id',$data['goods_id'])->field('goods_name,goods_no')->find();
- }
- public function add($coupon_activity_id,$data)
- {
- // 先删除全部
- static::deleteAll(['full_send_activity_id' => $coupon_activity_id]);
- if (!empty($data)) {
- $dataset = [];
- foreach ($data as $item) {
- $dataset[] = [
- 'full_send_activity_id'=>$coupon_activity_id,
- 'goods_id' => $item,
- ];
- }
- (new static)->addAll($dataset);
- }
- }
- }
|