first(); } /** * @param $notices * @return mixed */ public static function createdNotices($notices) { return self::insert($notices); } /** * @param $goodsId * @param $notices * @return mixed */ public static function updatedNotices($goodsId, $notices) { return self::where('goods_id', $goodsId)->update($notices); } /** * @param $goodsId * @return mixed */ public static function deletedNotices($goodsId) { return self::where('goods_id', $goodsId)->delete(); } public static function getList($goodsId) { return self::where('goods_id',$goodsId) ->get(); } public static function relationSave($goodsId, $data, $operate = '') { if(!$goodsId){ return false; } if (!$data) { return false; } self::deleteAllByGoodsId($goodsId); if(!$data['uid'] || !isset($data['type'])){ return false; } $noticesData = [ 'goods_id' => $goodsId, 'uid' => $data['uid'] ]; return self::addByGoodsId($data, $noticesData); } public static function relationValidator($goodsId, $data, $operate) { $flag = false; $model = new static; $validator = $model->validator($data); if($validator->fails()){ $model->error($validator->messages()); }else{ $flag = true; } return $flag; } public static function deleteAllByGoodsId($goodsId) { return static::where('goods_id', $goodsId) ->delete(); } public static function addByGoodsId($data,$noticesData) { foreach ($data['type'] as $type) { $saleModel = new static; $noticesData['type'] = $type; $saleModel->setRawAttributes($noticesData); $saleModel->save(); } return true; } }