OrderProductModel.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 $c_id
  24. * @param int $is_upload_numerology
  25. * @param int $is_upload
  26. * @return int
  27. * @throws \think\db\exception\DbException
  28. */
  29. public function countByCustomerId($c_id, $is_upload_numerology = 1, $is_upload = null) {
  30. $where = [
  31. ['is_delete', '=', 0],
  32. ['customer_id', '=', $c_id],
  33. ['is_upload_numerology', '=', $is_upload_numerology]
  34. ];
  35. if ($is_upload) {
  36. array_push($where,['is_upload', '=', $is_upload]);
  37. }
  38. return $this->where($where)
  39. ->count();
  40. }
  41. public function countByAdviser($adviser_1_id, $start_time = null, $end_time = null) {
  42. $where = [
  43. ['is_delete', '=', 0],
  44. ['adviser_1_id', '=', $adviser_1_id],
  45. ['is_pay' , '=', 1]
  46. ];
  47. if($start_time) array_push($where, ['create_time', '>=', $start_time]);
  48. if($end_time) array_push($where, ['create_time', '<=', $end_time]);
  49. return [
  50. $this->where($where)->sum('real_price'),
  51. $this->where(array_merge($where,[
  52. ['is_upload_numerology', '=', 1],
  53. ['is_upload', '=', 1]
  54. ]))->count(),
  55. $this->where(array_merge($where,[['is_upload_numerology', '=', 1]]))->count(),
  56. $this->where(array_merge($where, [['is_serve', '=', 0]]))->sum('real_price'),
  57. $this->where(array_merge($where, [['teacher_id', '>', 0]]))->sum('real_price'),
  58. $this->where(array_merge($where, [['is_serve', '=', 1]]))->sum('real_price'),
  59. ];
  60. }
  61. public function countByAdviserProductCategoryIds($adviser_1_id, $category_ids = [], $start_time = null, $end_time = null) {
  62. if (count($category_ids) == 0) return 0;
  63. $where = [
  64. ['is_delete', '=', 0],
  65. ['adviser_1_id', '=', $adviser_1_id],
  66. ['is_pay' , '=', 1],
  67. ['product_category_id', 'in', $category_ids]
  68. ];
  69. if($start_time) array_push($where, ['create_time', '>=', $start_time]);
  70. if($end_time) array_push($where, ['create_time', '<=', $end_time]);
  71. return $this->where($where)->sum('real_price');
  72. }
  73. }