OrderProductModel.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. ];
  46. if($start_time) array_push($where, ['create_time', '>=', $start_time]);
  47. if($end_time) array_push($where, ['create_time', '<=', $end_time]);
  48. return [
  49. $this->where($where)->sum('real_price'),
  50. $this->where(array_merge($where,[
  51. ['is_upload_numerology', '=', 1],
  52. ['is_upload', '=', 1]
  53. ]))->count(),
  54. $this->where([
  55. ['is_delete', '=', 0],
  56. ['adviser_1_id', '=', $adviser_1_id],
  57. ['is_upload_numerology', '=', 1],
  58. ])->count(),
  59. $this->where([
  60. ['is_delete', '=', 0],
  61. ['adviser_1_id', '=', $adviser_1_id],
  62. ['is_serve', '=', 0],
  63. ])->sum('real_price'),
  64. $this->where([
  65. ['is_delete', '=', 0],
  66. ['adviser_1_id', '=', $adviser_1_id],
  67. ['teacher_id', '>', 0],
  68. ])->sum('real_price'),
  69. $this->where([
  70. ['is_delete', '=', 0],
  71. ['adviser_1_id', '=', $adviser_1_id],
  72. ['is_serve', '=', 1],
  73. ])->sum('real_price'),
  74. ];
  75. }
  76. public function groupByAdviser($adviser_1_id, $start_time = null, $end_time = null) {
  77. return $this->where([
  78. ['is_delete', '=', 0],
  79. ['adviser_1_id', '=', $adviser_1_id],
  80. ])->sum('real_price');
  81. }
  82. }