Order.php 945 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. public function countOrder($condition)
  31. {
  32. $result = $this
  33. ->where($condition)
  34. ->count();
  35. return $result;
  36. }
  37. }