OrderModel.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\common\model;
  3. class OrderModel extends BaseModel
  4. {
  5. protected $table = 'erp_order';
  6. protected function genSchema(array $schema)
  7. {
  8. // TODO: Implement genSchema() method.
  9. }
  10. public function products() {
  11. return $this->hasMany(OrderProductModel::class, 'order_id','id')->where('is_delete',0);
  12. }
  13. public function payments() {
  14. return $this->hasMany(OrderPaymentModel::class, 'order_id','id')->where('is_delete',0);
  15. }
  16. public function annuals() {
  17. return $this->hasMany(OrderAnnualFeeModel::class, 'order_id','id')->where('is_delete',0);
  18. }
  19. public function proceeds() {
  20. return $this->hasMany(OrderProceedsModel::class, 'order_id','id')->where('is_delete',0);
  21. }
  22. public function store() {
  23. return $this->hasOne(StoreModel::class, 'id', 'store_id');
  24. }
  25. public function findByPaginate(array $params) {
  26. $where = [
  27. ['is_delete', '=', 0]
  28. ];
  29. if($params['store_id'] > 0)
  30. array_push($where,['store_id', '=', $params['store_id']]);
  31. if($params['type'] > 0)
  32. array_push($where,['type', '=', $params['type']]);
  33. return $this->where($where)
  34. ->with(['products','store'])
  35. ->order('create_time','desc')
  36. ->paginate(['list_rows'=>10, "query" => $params]);
  37. }
  38. public function report(array $params) {
  39. $where = [
  40. ['is_delete', '=', 0]
  41. ];
  42. if($params['store_id'] > 0)
  43. array_push($where,['store_id', '=', $params['store_id']]);
  44. if($params['type'] > 0)
  45. array_push($where,['type', '=', $params['type']]);
  46. return $this->where($where)
  47. ->with(['products','store'])
  48. ->order('create_time','desc')
  49. ->select();
  50. }
  51. public function findById($id)
  52. {
  53. return $this->where('is_delete',0)
  54. ->with([
  55. 'products',
  56. 'payments',
  57. 'payments.payment_channel',
  58. // 'payments.card_config',
  59. 'annuals',
  60. 'proceeds'
  61. ])->find($id);
  62. }
  63. }