// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\store\model\merchant; use app\common\model\merchant\MerchantOrder as MerchantOrderModel; /** * 代理商订单 * Class MerchantOrder * @package app\store\model\merchant */ class MerchantOrder extends MerchantOrderModel { /** * 获取余额变动明细列表 * @param array $param * @return \think\Paginator */ public function getList(array $param = []) { // 设置查询条件 $filter = $this->getFilter($param); // 获取列表数据 return $this->with(['user.avatar', 'goods.images.file', 'merchant']) ->alias('order') ->field('order.*') ->where($filter) ->leftJoin('user', 'user.user_id = order.user_id') ->order(['order.create_time' => 'desc']) ->paginate(15); } /** * 设置查询条件 * @param array $param * @return array */ private function getFilter(array $param): array { // 设置默认的检索数据 $params = $this->setQueryDefaultValue($param, [ 'merchant_id' => 0, // 用户ID 'search' => '', // 用户昵称 'betweenTime' => [] // 起止时间 ]); // 检索查询条件 $filter = []; // 用户ID $params['merchant_id'] > 0 && $filter[] = ['order.merchant_id', '=', $params['merchant_id']]; // 用户昵称 !empty($params['search']) && $filter[] = ['user.mobile', 'like', "%{$params['search']}%"]; // 起止时间 if (!empty($params['betweenTime'])) { $times = between_time($params['betweenTime']); $filter[] = ['order.create_time', '>=', $times['start_time']]; $filter[] = ['order.create_time', '<', $times['end_time'] + 86400]; } return $filter; } /** * 获取某天的总销售额 * @param null $startDate * @param null $endDate * @param array $merchant * @return float */ public function getOrderTotalPrice($startDate = null, $endDate = null,$merchant=[]): float { // 查询对象 $query = $this->getNewQuery(); $filter = []; // 设置查询条件 if (!is_null($startDate) && !is_null($endDate)) { $filter[] = ['create_time', '>=', strtotime($startDate)]; $filter[] = ['create_time', '<', strtotime($endDate) + 86400]; } if(!empty($merchant)) { $filter[] = ['merchant_id', '=', $merchant['merchant_id']]; } // 总销售额 return $query->where('order_status', '=', 30) ->where($filter) ->sum('order_price'); } }