Files
spacestation/agent/admin/controllers/api/receiver/Subsidy.php
T

238 lines
10 KiB
PHP

<?php
defined('BASEPATH') or exit('No direct script access allowed');
require_once APPPATH . 'controllers/api/BaseController.php';
class Subsidy extends BaseController
{
public function __construct()
{
parent::__construct();
$this->load->model('agent/auto_user_coupon_model');
$this->load->model('agent/auto_user_data_model');
$this->load->model('area_model');
$this->load->model('agent/receiver_order_subsidy_model');
$this->load->model('receiver/order/receiver_orders_model');
$this->load->model('receiver/order/receiver_order_datas_model');
$this->load->model('biz/biz_model');
$this->load->model('auto/auto_brand_model');
$this->load->model('auto/auto_series_model');
$this->receiver_orders_model->set_db('ssdb');
$this->biz_model->set_db('ssdb');
$this->auto_brand_model->set_db('ssdb');
$this->auto_series_model->set_db('ssdb');
$this->receiver_order_datas_model->set_db('ssdb');
}
public function page_get()
{
$params = $this->input_param();
$page = $params['page'] ?: 1;
$limit = $params['limit'] ?: 10;
$list = [];
$where = [];
$count = $this->receiver_order_subsidy_model->count($where);
if ($count) {
$rows = $this->receiver_order_subsidy_model->select($where, 'id desc', $page, $limit);
//车型
$brands = $this->auto_brand_model->get_map_by_ids(array_column($rows, 'brandId'));
$series = $this->auto_series_model->get_map_by_ids(array_column($rows, 'seriesId'));
foreach ($rows as $row) {
$order = $this->receiver_orders_model->get(['id' => $row['orderId']]);
$area = $this->area_model->get(['city_id' => $row['cityId']]);
$biz = $this->biz_model->get(['id' => $row['bizId']]);
$brand_detail = '';
if ($brands[$row['brandId']]) {
$brand_detail = $brands[$row['brandId']][0]['name'];
}
if ($series[$row['seriesId']]) {
$brand_detail .= '-' . $series[$row['seriesId']][0]['name'];
}
$list[] = [
'id' => $row['id'],
'sid' => $order['sid'],
'cityName' => $area['city_name'],
'bizName' => $biz['biz_name'],
'brandName' => $brand_detail,
'statusCn' => Receiver_order_subsidy_model::IF_CHECK_STATUS[$row['ifcheck']],
'contractImg' => $row['contractImg'] ? build_qiniu_image_url($row['contractImg']) : '',
'billImg' => $row['billImg'] ? build_qiniu_image_url($row['billImg']) : '',
'businessImg' => $row['businessImg'] ? build_qiniu_image_url($row['businessImg']) : '',
'cTime' => $row['createTime'],
'ifcheck' => intval($row['ifcheck']),
'reason' => $row['reason']
];
}
}
$data = ['list' => $list, 'count' => $count];
$this->return_response_list($data);
}
/**
* 详情
* @return void
*/
public function index_get()
{
$id = $this->input->get('id');
$this->load->model('auto/auto_series_model');
$select = '*, (select city_name from lc_area where city_id = lc_receiver_customers.city_id limit 1) as city_name, (select county_name from lc_area where county_id = lc_receiver_customers.county_id limit 1) as county_name';
$row = $this->customers_model->get(array('id' => $id), $select);
if (!$row) {
$this->return_json('客户不存在!');
}
$row_biz = $this->biz_model->get(array('id' => $row['biz_id']));
//用户信息
$mobile_sub = $row['mobile'];
if ($row['county_id']) {
$area = $this->area_model->get(array('county_id' => $row['county_id']));
$poi = "{$area['province_name']}-{$area['city_name']}-{$area['county_name']}";
} elseif ($row['city_id']) {
$area = $this->area_model->get(array('city_id' => $row['city_id']));
$poi = "{$area['province_name']}-{$area['city_name']}";
} elseif ($row['province_id']) {
$area = $this->area_model->get(array('province_id' => $row['province_id']));
$poi = "{$area['province_name']}";
}
$brand_detail = '';
if ($row['brand_id']) {
$brand = $this->auto_brand_model->get(['id' => $row['brand_id']]);
$brand && $brand_detail = $brand['name'];
}
if ($row['series_id']) {
$series = $this->auto_series_model->get(['id' => $row['series_id']]);
$series && $brand_detail .= '-' . $series['name'];
}
$of_title = '';
if ($row['of_id']) {
$of = $this->clues_cfrom_model->get(array('id' => $row['of_id']));
$of_title = $of['title'];
if ($row['of2_id']) {
$of = $this->clues_cfrom_model->get(array('id' => $row['of2_id']));
$of_title .= '-' . $of['title'];
}
}
$data = array(
'id' => $row['id'],
'name' => $row['name'],
'level' => $row['level'],
'mobile' => $mobile_sub,
'wx_name' => $this->customers_model->wxgrAry($row['wxgr']),
'c_time' => $row['createTime'],
'p_time' => $row['p_time'],
'status' => $row['status'],
'poi' => $poi,
'biz' => $row_biz['biz_name'],
'brand_detail' => $brand_detail,
'of_title' => $of_title,
);
$selectedCar = ['brandId' => $row['brand_id'] ?: '', 'seriesId' => $row['series_id'] ?: '', 'modelId' => ''];
$data['selectedCar'] = $selectedCar;
$statusAry = $this->customers_model->get_status();
unset($statusAry['-1']);
$this->return_response($data);
}
/**
* 审核
* @return void
*/
public function check_post()
{
$id = $this->post('id');
$status = $this->post('status');
$reason = $this->post('reason');
/** @var ReceiverOrderSubsidyEntity $row */
$row = $this->receiver_order_subsidy_model->get(['id' => $id], '', 'ReceiverOrderSubsidyEntity');
if (!$row) {
$this->return_json('数据不存在!');
}
if ($row->ifcheck != Receiver_order_subsidy_model::IF_CHECK_NO) {
$this->return_json('当前数据不是待审核状态!');
}
$result = $row->ifCheckSubsidy($status, $reason);
if (!$result->isSuccess()) {
$this->return_json($result->getMessage());
}
$this->return_response();
}
public function sendLog_get()
{
$params = $this->input_param();
$page = $params['page'] ?: 1;
$limit = $params['limit'] ?: 10;
$list = [];
$where = [
'ifcheck' => Receiver_order_subsidy_model::IF_CHECK_YES
];
$params['status'] && $where['status'] = $params['status'];
if ($params['dateRange']) {
$where['checkTime>='] = $params['dateRange'][0] . ' 00:00:00';
$where['checkTime<='] = $params['dateRange'][0] . ' 23:59:59';
}
if ($params['name'] || $params['mobile']) {
if ($params['name'] && $params['mobile']) {
$oWhere['name'] = $params['name'];
$oWhere['mobile'] = $params['mobile'];
} else {
$oWhere["name='{$params['name']}' or mobile='{$params['mobile']}'"] = null;
}
$orderList = $this->receiver_orders_model->select($oWhere, '', 0, 0, 'id');
$orderIdsArray = array_column($orderList, 'id');
$orderIds = implode(',', $orderIdsArray);
!$orderIds && $orderIds = '0';
$where["orderId in ($orderIds)"] = null;
}
$count = $this->receiver_order_subsidy_model->count($where);
if ($count) {
$rows = $this->receiver_order_subsidy_model->select($where, 'id desc', $page, $limit);
//车型
foreach ($rows as $row) {
$order = $this->receiver_orders_model->get(['id' => $row['orderId']]);
$orderData = $this->receiver_order_datas_model->get(['o_id' => $order['id']]);
$userData = $this->auto_user_data_model->get(['userId' => $row['userId']]);
$userCoupon = $this->auto_user_coupon_model->get([
'couponId' => $row['couponId'], 'userId' => $row['userId'], 'status' => Auto_user_coupon_model::STATUS_USED
]);
$list[] = [
'id' => $row['id'],
'name' => $order['name'],
'mobile' => $order['mobile'],
'bankCardNum' => $userData['bankCardNum'] ?: '',
'bankName' => $userData['bankName'] ?: '',
'bankImg' => $userData['bankImg'] ? build_qiniu_image_url($userData['bankImg']) : '',
'statusCn' => Receiver_order_subsidy_model::STATUS_STATUS[$row['status']],
'checkTime' => $row['checkTime'],
'price' => intval($userCoupon['price']),
'cardId' => $order['card_id'] ?: '',
'cardida' => $orderData['cardida'] ? build_qiniu_image_url($orderData['cardida']) : '',
'cardidb' => $orderData['cardidb'] ? build_qiniu_image_url($orderData['cardidb']) : '',
'status' => $row['status'],
];
}
}
$data = ['list' => $list, 'count' => $count];
$this->return_response_list($data);
}
//修改状态
public function status_post()
{
$id = $this->input_param('id');
$status = $this->input_param('status');
if (!$id) {
$this->return_json('参数错误');
}
$this->receiver_order_subsidy_model->update(['status' => $status], ['id' => $id]);
$this->return_response();
}
public function statusList_get()
{
$this->return_response(Receiver_order_subsidy_model::STATUS_STATUS);
}
}