Order.php 787 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Order extends Model
  5. {
  6. protected $pk = 'order_id';
  7. public function user()
  8. {
  9. return $this->belongsTo('User', 'user_id', 'user_id');
  10. }
  11. public function product()
  12. {
  13. return $this->belongsTo('Product', 'product_id', 'product_id');
  14. }
  15. public function getOrdList($condition, $fileds = '*', $limit = 10)
  16. {
  17. if (empty($condition)) {
  18. $result = $this
  19. ->field($fileds)
  20. ->order('order_id', 'desc')
  21. ->paginate($limit);
  22. } else {
  23. $result = $this
  24. ->where($condition)
  25. ->order('order_id', 'desc')
  26. ->paginate($limit);
  27. }
  28. return $result;
  29. }
  30. }