join('AgentUser m', 'm.id=f.agent_id') ->order('f.add_time desc'), 'f.add_time'); if (isset($where['agent_id']) && $where['agent_id']) $model = $model->where('f.agent_id', $where['agent_id']); $model = $model->where('f.price', '<>', 0); return $model->field(['f.*', 'FROM_UNIXTIME(f.add_time,"%Y-%m-%d %H:%i:%s") as add_time', 'm.lecturer_name']); } /**讲师流水 * @param $where * @return array */ public static function getBillList($where) { $data = ($data = self::setWhereList($where)->page((int)$where['page'], (int)$where['limit'])->select()) && count($data) ? $data->toArray() : []; foreach ($data as &$v) { $v['title'] = self::get_order_type($v['type']); } $count = self::setWhereList($where)->count(); return compact('data', 'count'); } /**流水导出 * @param $where */ public static function SaveExport($where) { $data = ($data = self::setWhereList($where)->select()) && count($data) ? $data->toArray() : []; $export = []; foreach ($data as $value) { $title = self::get_order_type($value['type']); $export[] = [ $value['mer_id'], $value['mer_name'], $title, $value['total_price'], $value['pay_price'], $value['refund_price'], $value['status'] == 0 ? '-' . $value['price'] : $value['price'], $value['add_time'], ]; } $filename = '分成记录' . time() . '.xlsx'; $head = ['讲师ID', '讲师昵称', '订单类型', '订单总价', '实际金额', '退款金额', '分成/退还', '创建时间']; PhpSpreadsheetService::outdata($filename, $export, $head); } /**订单类型 * @param $type * @return string */ public static function get_order_type($type) { switch ($type) { case 0: $title = '课程订单'; break; case 1: $title = '会员订单'; break; case 2: $title = '商品订单'; break; case 3: $title = '资料订单'; break; case 4: $title = '报名订单'; break; case 5: $title = '考试订单'; break; } return $title; } }