OrderProductModel.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\common\model;
  3. class OrderProductModel extends BaseModel
  4. {
  5. protected $table = 'erp_order_product';
  6. protected function genSchema(array $schema)
  7. {
  8. // TODO: Implement genSchema() method.
  9. }
  10. /**
  11. * @param $o_id
  12. * @param int $is_pay
  13. * @return OrderProductModel[]|array|\think\Collection
  14. * @throws \think\db\exception\DataNotFoundException
  15. * @throws \think\db\exception\DbException
  16. * @throws \think\db\exception\ModelNotFoundException
  17. */
  18. public function findByOrderId($o_id, $is_pay = 1) {
  19. return $this->where('is_delete', 0)
  20. ->where('order_id',$o_id)
  21. ->where('is_pay', $is_pay)
  22. ->select();
  23. }
  24. /**
  25. * @param $o_id
  26. * @param int $page
  27. * @param int $size
  28. * @return \think\Paginator
  29. * @throws \think\db\exception\DbException
  30. */
  31. public function fetchByOrderId($o_id, $page = 1, $size = 10) {
  32. return $this->where('is_delete', 0)
  33. ->where('order_id',$o_id)
  34. ->page($page)
  35. ->paginate($size);
  36. }
  37. /**
  38. * @param $c_id
  39. * @param int $is_upload_numerology
  40. * @param int $is_upload
  41. * @return int
  42. * @throws \think\db\exception\DbException
  43. */
  44. public function countByCustomerId($c_id, $is_upload_numerology = 1, $is_upload = null) {
  45. $where = [
  46. ['is_delete', '=', 0],
  47. ['customer_id', '=', $c_id],
  48. ['is_upload_numerology', '=', $is_upload_numerology]
  49. ];
  50. if ($is_upload) {
  51. array_push($where,['is_upload', '=', $is_upload]);
  52. }
  53. return $this->where($where)
  54. ->count();
  55. }
  56. public function countByAdviser($adviser_1_id, $start_time = null, $end_time = null) {
  57. $where = [
  58. ['is_delete', '=', 0],
  59. ['adviser_1_id', '=', $adviser_1_id],
  60. ['is_pay' , '=', 1]
  61. ];
  62. if($start_time) array_push($where, ['create_time', '>=', $start_time]);
  63. if($end_time) array_push($where, ['create_time', '<=', $end_time]);
  64. return [
  65. $this->where($where)->sum('real_price'),
  66. $this->where(array_merge($where,[
  67. ['is_upload_numerology', '=', 1],
  68. ['is_upload', '=', 1]
  69. ]))->count(),
  70. $this->where(array_merge($where,[['is_upload_numerology', '=', 1]]))->count(),
  71. $this->where(array_merge($where, [['is_serve', '=', 0]]))->sum('real_price'),
  72. $this->where(array_merge($where, [['teacher_1_id', '>', 0]]))->sum('real_price'),
  73. $this->where(array_merge($where, [['is_serve', '=', 1]]))->sum('real_price'),
  74. ];
  75. }
  76. public function countByAdviserProductCategoryIds($adviser_1_id, $category_ids = [], $start_time = null, $end_time = null) {
  77. if (count($category_ids) == 0) return [0 , 0];
  78. $where = [
  79. ['is_delete', '=', 0],
  80. ['adviser_1_id', '=', $adviser_1_id],
  81. ['is_pay' , '=', 1],
  82. ['product_category_id', 'in', $category_ids]
  83. ];
  84. if($start_time) array_push($where, ['create_time', '>=', $start_time]);
  85. if($end_time) array_push($where, ['create_time', '<=', $end_time]);
  86. return [$this->where($where)->sum('real_price'), $this->where($where)->count()];
  87. }
  88. }