OrderProductModel.php 3.2 KB

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