Commit 671d0e5b by 朱继来

Merge branch 'zjl_sample_20190925'

parents bbd5dc4b fbcdc978
......@@ -13,6 +13,8 @@ use App\Model\Pcb\PcbServerModel;
use App\Model\KefuModel;
use App\Model\CmsModel;
use App\Model\OrderItemsTrackModel;
use App\Model\UserSampleApplyModel;
use App\Model\UserSampleInviteModel;
class ApiController extends Controller
{
......@@ -121,7 +123,7 @@ class ApiController extends Controller
$this->Export($KefuModel->del($request));
}
// 删除客服
// 置顶客服
public function ApiTopKefu($request)
{
$KefuModel = new KefuModel;
......@@ -160,4 +162,25 @@ class ApiController extends Controller
$this->Export(0, '', $data);
}
// 获取自营样片领取列表
public function ApiSelfSampleList($request)
{
$UserSampleApplyModel = new UserSampleApplyModel;
$this->ExportLayui($UserSampleApplyModel->lists($request));
}
// 获取自营样片领取记录
public function ApiSelfSampleApplyLog($request)
{
$UserSampleApplyModel = new UserSampleApplyModel;
$this->ExportLayui($UserSampleApplyModel->applyLog($request));
}
// 获取自营样片邀约记录
public function ApiSelfSampleInviteLog($request)
{
$UserSampleInviteModel = new UserSampleInviteModel;
$this->ExportLayui($UserSampleInviteModel->lists($request));
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\UserSampleApplyModel;
use DB;
use Excel;
Class ExportController extends Controller
{
// 统一入口
public function entrance(Request $request, $id)
{
return $this->$id($request);
}
// 导出会员
public function selfSampleExport($request)
{
$UserSampleApplyModel = new UserSampleApplyModel();
$data = $UserSampleApplyModel->lists($request, 1);
foreach ($data as $k=>$v) {
$cellData[$k]['user_id'] = $v['user_id'];
$cellData[$k]['account'] = $v['account'];
$cellData[$k]['invite_count'] = $v['invite_count'];
$cellData[$k]['apply_num_total'] = $v['apply_num_total'];
$cellData[$k]['apply_count'] = $v['apply_count'];
$cellData[$k]['order_id'] = $v['order_id'];
$cellData[$k]['order_sn'] = $v['order_sn'];
$cellData[$k]['goods_id'] = $v['goods_id'];
$cellData[$k]['goods_name'] = $v['goods_name'];
$cellData[$k]['create_time'] = $v['create_time'];
}
$headerCell = ['用户ID', '用户账户', '邀请人数', '已申请样片数', '剩余领取次数', '订单ID', '订单编号', '样片ID', '样片名称', '最近一次领取时间'];
$fileName ='自营样片领取记录导出'.date('_YmdHis');
$sheetName = '自营样片';
$this->commonFunc($cellData, $headerCell, $fileName, $sheetName);
}
/**
* 导出
* @param [type] $cellData [导出数据]
* @param [type] $headerCell [菜单项]
* @param [type] $fileName [文件名]
* @param string $sheetName [sheet名]
* @return [type] [description]
*/
public function commonFunc($cellData, $headerCell, $fileName, $sheetName='')
{
$sheetName = $sheetName ? $sheetName : '导出';
array_unshift($cellData, $headerCell);
Excel::create($fileName, function($excel) use ($cellData, $sheetName){
$excel->sheet($sheetName, function($sheet) use ($cellData){
$sheet->rows($cellData);
});
})->export('xls');
}
}
\ No newline at end of file
......@@ -280,4 +280,25 @@ class WebController extends Controller
return view('web', $data);
}
// 自营样片领取列表
public function selfSampleList($request, $data, $id)
{
$data['title'] = '自营样片领取列表';
return view('web', $data);
}
// 自营样片领取和邀约记录
public function selfSampleLog($request, $data, $id)
{
$user_id = $request->input('user_id', 0);
if (!$user_id) return redirect('/web/selfSampleList');
$data['title'] = '自营样片领取和邀约记录';
$data['paths'] = [["title" => '自营订单', "href" => '#'], ["title" => '自营订单领取列表', "href" => '/web/selfSampleList'], ["title" => '自营样片领取和邀约记录', "href" => '#']];
$data['user_id'] = $user_id;
return view('web', $data);
}
}
......@@ -108,6 +108,7 @@ Route::group(['middleware' => 'web'], function () {
Route::match(['get', 'post'],'/web/{key}', 'WebController@info');
Route::match(['get', 'post'],'/api/{key}', 'ApiController@Entrance');
Route::match(['get', 'post'], '/export/{key}', 'ExportController@entrance');
Route::match(['get', 'post'], '/refund/{id}', 'OrderController@refund');
......
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
use Excel;
use DB;
class UserInfoModel extends Model
{
protected $connection = 'order';
protected $table = 'lie_user_info';
protected $primaryKey = 'ui_id';
public $timestamps = false;
// 获取用户样片领取机会
public function getUserApplyCount($user_id)
{
$user_info = $this->where('user_id', $user_id)->select('apply_count')->first();
if (!$user_info) return 0;
return $user_info->apply_count;
}
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
use Excel;
use DB;
class UserSampleApplyModel extends Model
{
protected $connection = 'order';
protected $table = 'lie_user_sample_apply';
protected $primaryKey = 'apply_id';
public $timestamps = true;
const CREATED_AT = 'create_time';
/** * @param \DateTime|int $value * @return false|int * @author dividez */
public function fromDateTime($value)
{
return strtotime(parent::fromDateTime($value));
}
// 获取领取列表
public function lists($request, $export='')
{
$page = $request->input('page', 1);
$limit = $request->input('limit', 10);
$field = ['a.apply_id', 'a.user_id', 'a.account', 'a.order_id', 'order_sn', 'a.goods_id', 'a.goods_name', 'a.apply_num', 'a.create_time'];
$map['account'] = $request->input('account', ''); // 用户账户
$map['goods_name'] = $request->input('goods_name', ''); // 商品名称
$map['order_sn'] = $request->input('order_sn', ''); // 订单号
$map['begin_time'] = $request->input('begin_time', '') ? strtotime($request->input('begin_time')) : '';
$map['end_time'] = $request->input('end_time', '') ? strtotime($request->input('end_time')) + 86399 : '';
$sub = UserSampleApplyModel::select(DB::raw('max(apply_id) as apply_id'))->groupBy('user_id');
$list = $this->from('lie_user_sample_apply as a')
->join(DB::raw("({$sub->toSql()}) as b"), function($join) {
$join->on('a.apply_id', '=', 'b.apply_id');
})->where(function($query) use ($map) {
// 客服名称
if ($map['account']) {
$query->where('a.account', '=', $map['account']);
}
})->where(function($query) use ($map) {
// 邮箱
if ($map['goods_name']) {
$query->where('a.goods_name', 'like', $map['goods_name'].'%');
}
})->where(function($query) use ($map) {
// 客服名称
if ($map['order_sn']) {
$query->where('a.order_sn', '=', $map['order_sn']);
}
})->where(function($query) use ($map) {
// 创建时间
if(!empty($map['begin_time']) && !empty($map['end_time'])) {
$query->whereBetween('a.create_time', [$map['begin_time'], $map['end_time']]);
}
else if(!empty($map['begin_time'])) {
$query->where('a.create_time', '>=', $map['begin_time']);
}
else if(!empty($map['end_time'])) {
$query->where('a.create_time', '<=', $map['end_time']);
}
})
->select($field)
->orderBy('a.create_time', 'desc')
->orderBy('a.apply_id', 'asc');
if ($export) {
$list = $list->get()->toArray();
$list = $this->handle($list);
if (empty($list)) {
echo '<script>alert("导出数据为空");history.go(-1);</script>';die;
}
return $list;
} else {
$list = $list->paginate($limit, ['*'], 'page', $page)->toArray();
$data = $this->handle($list['data']);
return [0, '获取成功', $data, $list['total']];
}
}
// 处理数据
public function handle($data)
{
if (!$data) return false;
foreach ($data as &$v) {
$UserSampleInviteModel = new UserSampleInviteModel;
$UserInfoModel = new UserInfoModel;
$v['invite_count'] = $UserSampleInviteModel->getUserInviteCount($v['user_id']);
$v['apply_num_total'] = $this->getSampleApplySum($v['user_id']);
$v['apply_count'] = $UserInfoModel->getUserApplyCount($v['user_id']);
}
return $data;
}
// 获取指定用户申请的样片总数
public function getSampleApplySum($user_id)
{
return $this->where('user_id', $user_id)->sum('apply_num');
}
// 获取领取记录
public function applyLog($request)
{
$user_id = $request->input('user_id');
$page = $request->input('page', 1);
$limit = $request->input('limit', 10);
$field = ['apply_id', 'user_id', 'account', 'order_id', 'order_sn', 'goods_id', 'goods_name', 'apply_num', 'create_time'];
$list = $this->where('user_id', $user_id)
->select($field)
->orderBy('create_time', 'desc')
->orderBy('apply_id', 'asc')
->paginate($limit, ['*'], 'page', $page)->toArray();
return [0, '获取成功', $list['data'], $list['total']];
}
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
use Excel;
use DB;
class UserSampleInviteModel extends Model
{
protected $connection = 'order';
protected $table = 'lie_user_sample_invite';
protected $primaryKey = 'invite_id';
public $timestamps = true;
const CREATED_AT = 'create_time';
/** * @param \DateTime|int $value * @return false|int * @author dividez */
public function fromDateTime($value)
{
return strtotime(parent::fromDateTime($value));
}
// 获取邀约列表
public function lists($request)
{
$user_id = $request->input('user_id');
$page = $request->input('page', 1);
$limit = $request->input('limit', 10);
$field = ['invite_id', 'user_id', 'account', 'invitee_uid', 'invitee_mobile', 'create_time'];
$list = $this->where('user_id', $user_id)
->select($field)
->orderBy('create_time', 'desc')
->orderBy('invite_id', 'asc')
->paginate($limit, ['*'], 'page', $page)->toArray();
return [0, '获取成功', $list['data'], $list['total']];
}
// 获取指定用户邀约人数
public function getUserInviteCount($user_id)
{
return $this->where('user_id', $user_id)->count();
}
// 获取用户邀约列表
public function getUserInviteList($user_id)
{
return $this->where('user_id', $user_id)->select('invitee_uid', 'invitee_mobile', 'create_time')->get()->toArray();
}
}
\ No newline at end of file
layui.use(['form', 'table', 'laydate'], function(){
var form = layui.form;
var table = layui.table;
var laydate = layui.laydate;
laydate.render({
elem: '#begin_time' //指定元素
});
laydate.render({
elem: '#end_time' //指定元素
});
table.render({
id: 'list'
,elem: '#sample'
,url: '/api/ApiSelfSampleList' //数据接口
,method:'post'
,cellMinWidth: 80 //全局定义常规单元格的最小宽度
,page: true //开启分页
,cols: [[ //表头
{title: '序号', type: 'numbers', fixed: 'left', width: 80}
,{field: 'user_id', title: '用户ID', width: 100}
,{field: 'account', title: '用户账户', width: 150}
,{field: 'invite_count', title: '邀请人数', width: 100}
,{field: 'apply_num_total', title: '已申请样片数', width: 120}
,{field: 'apply_count', title: '剩余领取次数', width: 120}
,{field: 'order_id', title: '订单ID', width: 100}
,{field: 'order_sn', title: '订单编号', width: 150}
,{field: 'goods_id', title: '样片ID', width: 100}
,{field: 'goods_name', title: '样片名称', width: 200}
,{field: 'create_time', title: '最近一次领取时间', width: 180}
,{title: '操作', align:'center', fixed: 'right', toolbar: '#list_action', width: 195}
]]
,limit: 10
,limits: [10, 20, 50,]
});
form.on('submit(load)', function(data) {
//执行重载
table.reload('list', {
page: {
curr: 1
}
,where: data.field
});
return false;
});
// 导出
$('.export').click(function() {
var account = $('input[name=account]').val(),
goods_name = $('input[name=goods_name]').val(),
order_sn = $('input[name=order_sn]').val(),
begin_time = $('input[name=begin_time]').val(),
end_time = $('input[name=end_time]').val(),
url = '/export/selfSampleExport';
if (!account && !goods_name && !order_sn && !begin_time && !end_time) {
layer.msg('请选择筛选条件');
return false;
}
layer.confirm('确定导出数据吗?', {
title: '导出数据'
,btn: ['确定', '取消']
}, function(){
layer.closeAll('dialog'); // 确定时关闭弹框
window.location.href = url+'?account='+account+'&goods_name='+goods_name+'&order_sn='+order_sn+'&begin_time='+begin_time+'&end_time='+end_time;
});
})
});
\ No newline at end of file
layui.use(['table'], function(){
var table = layui.table;
// 领取记录
table.render({
id: 'list'
,elem: '#apply_log'
,url: '/api/ApiSelfSampleApplyLog' //数据接口
,method:'post'
,cellMinWidth: 80 //全局定义常规单元格的最小宽度
,page: true //开启分页
,where: {
user_id : $('input[name=user_id]').val()
}
,cols: [[ //表头
{title: '序号', type: 'numbers', fixed: 'left', width: 80}
,{field: 'user_id', title: '用户ID', width: 150}
,{field: 'account', title: '用户账户', width: 200}
,{field: 'order_id', title: '订单ID', width: 150}
,{field: 'order_sn', title: '订单编号', width: 200}
,{field: 'goods_id', title: '样片ID', width: 150}
,{field: 'goods_name', title: '样片名称', width: 300}
,{field: 'apply_num', title: '领取数量', width: 150}
,{field: 'create_time', title: '领取时间', width: 218}
]]
,limit: 10
,limits: [10, 20, 50,]
});
// 邀约记录
table.render({
id: 'list'
,elem: '#invite_log'
,url: '/api/ApiSelfSampleInviteLog' //数据接口
,method:'post'
,cellMinWidth: 80 //全局定义常规单元格的最小宽度
,page: true //开启分页
,where: {
user_id : $('input[name=user_id]').val()
}
,cols: [[ //表头
{title: '序号', type: 'numbers', fixed: 'left', width: 80}
,{field: 'user_id', title: '用户ID'}
,{field: 'account', title: '用户账户'}
,{field: 'invitee_uid', title: '受邀人ID'}
,{field: 'invitee_mobile', title: '受邀人手机号码'}
,{field: 'create_time', title: '受邀人注册时间'}
]]
,limit: 10
,limits: [10, 20, 50,]
});
});
\ No newline at end of file
......@@ -559,6 +559,13 @@
<td colspan="10">{{$order_temp_info['kefu_remark']}}</td>
</tr>
@endif
@if ($order_info['order_goods_type'] == 2 && $order_temp_info['business_type'] == 1)
<tr>
<td>项目需求描述:</td>
<td colspan="10">{{$order_temp_info['sample_demand_desc']}}</td>
</tr>
@endif
</tfoot>
</table>
......
<form class="layui-form layui-box" method="post">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">用户账户</label>
<div class="layui-input-inline">
<input type="text" name="account" placeholder="填写用户账户" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">商品名称</label>
<div class="layui-input-inline">
<input type="text" name="goods_name" placeholder="填写商品名称" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">订单编号</label>
<div class="layui-input-inline">
<input type="text" name="order_sn" placeholder="填写订单编号" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">领取时间</label>
<div class="layui-input-inline">
<input type="text" name="begin_time" value="" autocomplete="off" placeholder="选择开始时间" class="layui-input" id="begin_time" readonly>
</div>
<div class="layui-form-mid">-</div>
<div class="layui-input-inline">
<input type="text" name="end_time" value="" autocomplete="off" placeholder="选择结束时间" class="layui-input" id="end_time" readonly>
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-btn-container" style="text-align: center; margin-top: 10px;">
<button lay-submit lay-filter="load" class="layui-btn" data-type="search">搜索</button>
<button type="button" class="layui-btn layui-btn-normal export">导出</button>
</div>
</div>
</form>
<table id="sample" lay-filter="list"></table>
<script type="text/html" id="list_action">
<a class="btn btn-xs btn-info" href="/web/selfSampleLog?user_id=@{{ d.user_id }}" target="_blank">领取和邀约记录</a>
</script>
\ No newline at end of file
<input type="hidden" name="user_id" value="{{ $user_id }}">
<h3>领取记录</h3>
<table id="apply_log" lay-filter="apply"></table>
<hr>
<h3>邀约记录</h3>
<table id="invite_log" lay-filter="invite"></table>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment