| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace app\common\model;
- class OrderProductModel extends BaseModel
- {
- protected $table = 'erp_order_product';
- protected function genSchema(array $schema)
- {
- // TODO: Implement genSchema() method.
- }
- /**
- * @param $o_id
- * @param int $is_pay
- * @return OrderProductModel[]|array|\think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function findByOrderId($o_id, $is_pay = 1) {
- return $this->where('is_delete', 0)
- ->where('order_id',$o_id)
- ->where('is_pay', $is_pay)
- ->select();
- }
- /**
- * @param $o_id
- * @param int $page
- * @param int $size
- * @return \think\Paginator
- * @throws \think\db\exception\DbException
- */
- public function fetchByOrderId($o_id, $page = 1, $size = 10) {
- return $this->where('is_delete', 0)
- ->where('order_id',$o_id)
- ->page($page)
- ->paginate($size);
- }
- /**
- * @param $c_id
- * @param int $is_upload_numerology
- * @param int $is_upload
- * @return int
- * @throws \think\db\exception\DbException
- */
- public function countByCustomerId($c_id, $is_upload_numerology = 1, $is_upload = null) {
- $where = [
- ['is_delete', '=', 0],
- ['customer_id', '=', $c_id],
- ['is_upload_numerology', '=', $is_upload_numerology]
- ];
- if ($is_upload) {
- array_push($where,['is_upload', '=', $is_upload]);
- }
- return $this->where($where)
- ->count();
- }
- public function countByAdviser($adviser_1_id, $start_time = null, $end_time = null) {
- $where = [
- ['is_delete', '=', 0],
- ['adviser_1_id', '=', $adviser_1_id],
- ['is_pay' , '=', 1]
- ];
- if($start_time) array_push($where, ['create_time', '>=', $start_time]);
- if($end_time) array_push($where, ['create_time', '<=', $end_time]);
- return [
- $this->where($where)->sum('real_price'),
- $this->where(array_merge($where,[
- ['is_upload_numerology', '=', 1],
- ['is_upload', '=', 1]
- ]))->count(),
- $this->where(array_merge($where,[['is_upload_numerology', '=', 1]]))->count(),
- $this->where(array_merge($where, [['is_serve', '=', 0]]))->sum('real_price'),
- $this->where(array_merge($where, [['teacher_1_id', '>', 0]]))->sum('real_price'),
- $this->where(array_merge($where, [['is_serve', '=', 1]]))->sum('real_price'),
- ];
- }
- public function countByAdviserProductCategoryIds($adviser_1_id, $category_ids = [], $start_time = null, $end_time = null) {
- if (count($category_ids) == 0) return [0 , 0];
- $where = [
- ['is_delete', '=', 0],
- ['adviser_1_id', '=', $adviser_1_id],
- ['is_pay' , '=', 1],
- ['product_category_id', 'in', $category_ids]
- ];
- if($start_time) array_push($where, ['create_time', '>=', $start_time]);
- if($end_time) array_push($where, ['create_time', '<=', $end_time]);
- return [$this->where($where)->sum('real_price'), $this->where($where)->count()];
- }
- }
|