OrderGoods.php 709 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace app\common\model;
  3. use app\admin\model\Orders;
  4. use think\db\Query;
  5. use think\Model;
  6. /**
  7. * @method Query|static filterAdmin($admin_id)
  8. */
  9. class OrderGoods extends Model
  10. {
  11. protected $autoWriteTimestamp=true;
  12. protected $updateTime=null;
  13. public static function unique(OrderInfo $orderInfo){
  14. self::insert([
  15. 'goods_id'=>$orderInfo['goods_id'],
  16. 'order_id'=>$orderInfo['order_id'],
  17. ],true);
  18. }
  19. public function scopeFilterAdmin(Query $query,$admin_id){
  20. $table=$this->getTable();
  21. $query->whereExists(
  22. Orders::whereRaw("orders.id={$table}.order_id and orders.admin_id=$admin_id")->buildSql()
  23. );
  24. }
  25. }