12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace app\admin\model;
- use think\db\Query;
- use think\Model;
- use app\common\model\Goods;
- /**
- * @method Query|static typeView()
- * @method Query|static typeFav()
- * @method Query|static typeCart()
- */
- class GoodsViewFavCart extends Model
- {
- public function scopeTypeView(Query $query){
- $query->where('type','view');
- }
- public function scopeTypeCart(Query $query){
- $query->where('type','cart');
- }
- public function scopeTypeFav(Query $query){
- $query->where('type','fav');
- }
- public static function increment($goods,$type){
- $goods_id=$goods instanceof Goods ?$goods['id']:$goods;
- $date=date('Y-m-d');
- $has=self::where('goods_id',$goods_id)
- ->where('date',$date)
- ->where('type',$type)
- ->find();
- if($has){
- $has->setInc('num');
- }else{
- self::create([
- 'goods_id'=>$goods_id,
- 'date'=>$date,
- 'type'=>$type,
- 'num'=>1,
- ]);
- }
- }
- }
|