创建版本

This commit is contained in:
2021-02-22 12:17:00 +08:00
commit af555f49c3
2332 changed files with 369202 additions and 0 deletions
@@ -0,0 +1,350 @@
<?php namespace Gdoo\Promotion\Controllers;
use Request;
use Validator;
use URL;
use DB;
use ZipArchive;
use Session;
use Gdoo\Promotion\Models\Promotion;
use Gdoo\Promotion\Models\PromotionMaterial as Material;
use Gdoo\Model\Grid;
use Gdoo\Model\Form;
use Gdoo\Index\Controllers\DefaultController;
use Exception;
class MaterialController extends DefaultController
{
public $permission = ['detail', 'dialog', 'store', 'archive', 'download'];
// 促销核销列表
public function indexAction()
{
// 客户权限
$region = regionCustomer('customer_id_customer');
$header = Grid::header([
'code' => 'promotion_material',
'referer' => 1,
'search' => ['by' => '-1'],
]);
$cols = $header['cols'];
$cols['actions']['options'] = [[
'name' => '显示',
'action' => 'show',
'display' => $this->access['show'],
]];
$search = $header['search_form'];
$query = $search['query'];
if (Request::method() == 'POST') {
$model = DB::table($header['table'])->setBy($header);
foreach ($header['join'] as $join) {
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
}
$model->leftJoin('promotion_material_file as f', 'f.material_id', '=', 'promotion_material.id');
$model->orderBy($header['sort'], $header['order']);
foreach ($search['where'] as $where) {
if ($where['active']) {
$model->search($where);
}
}
if ($query['by'] >= 0) {
$model->where('promotion_material.status', $query['by']);
}
if ($region['authorise']) {
foreach ($region['whereIn'] as $key => $where) {
$model->whereIn($key, $where);
}
}
$header['select'][] = 'promotion_material.promotion_id';
$header['select'][] = 'f.path';
$header['select'][] = 'f.created_by';
$header['select'][] = 'f.created_at';
$model->select($header['select']);
$rows = $model->paginate($query['limit'])->appends($query);
$items = Grid::dataFilters($rows, $header, function($item) {
return $item;
});
return $items->toJson();
}
$header['buttons'] = [
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
];
$header['left_buttons'] = [
['name' => '批量编辑', 'color' => 'default', 'icon' => 'fa-pencil-square-o', 'action' => 'batchEdit', 'display' => $this->access['batchEdit']],
];
$header['cols'] = $cols;
$header['tabs'] = Material::$tabs;
$header['bys'] = Material::$bys;
$header['js'] = Grid::js($header);
return $this->display([
'header' => $header,
]);
}
// 促销核销明细
public function detailAction()
{
$search = search_form([
'status' => '',
'promotion_id' => 0,
]);
$query = $search['query'];
$promotion = Promotion::where('id', $query['promotion_id'])->first();
$model = Material::leftJoin('promotion', 'promotion.id', '=', 'promotion_material.promotion_id')
->where('promotion_material.promotion_id', $query['promotion_id']);
if (is_numeric($query['status'])) {
$model->where('promotion_material.status', $query['status']);
}
$rows = $model->orderBy('promotion_material.id', 'desc')
->get(['promotion_material.*','promotion.sn'])
->toArray();
$items = [];
$audits = [];
foreach ($rows as $i => $row) {
$files = DB::table('promotion_material_file')->where('material_id', $row['id'])->get();
$images = [];
foreach ($files as $file) {
$path_file = upload_path().'/'.$file['path'];
if (is_file($path_file)) {
$images[] = ['url' => url('uploads/'.$file['path']), 'name' => ''];
}
}
$audits[$row['status']] ++;
$items[$row['id']] = $images;
$rows[$i]['images'] = $images;
}
$changes = [
0 => ['btn' => 'default', 'text' => '未审核'],
1 => ['btn' => 'success', 'text' => '已审合格'],
2 => ['btn' => 'danger', 'text' => '已审不合格'],
];
$tabs = [
'name' => 'status',
'items' => [
['id' => '', 'name' => '全部'],
['id' => 0, 'name' => '未审核'],
['id' => 1, 'name' => '已审合格'],
['id' => 2, 'name' => '已审不合格']
]
];
return $this->display([
'tabs' => $tabs,
'items' => $items,
'rows' => $rows,
'audits' => $audits,
'promotion' => $promotion,
'changes' => $changes,
'search' => $search,
]);
}
// 获取核销列表
public function dialogAction()
{
$user = auth()->user();
$customer_id = $user->customer->id;
$rows = Promotion::with('datas')->where('material_id', '!=', 2)
->where('status', 0)
->where('customer_id', $customer_id)
->where('number', '!=', '')
->get(['id', 'number as text','data_4', 'data_19', 'start_at', 'end_at']);
foreach ($rows as &$row) {
$row->products = $row->datas->implode('product_name', ',');
}
return $this->json($rows, true);
}
// 显示促销
public function showAction()
{
$id = Request::get('id');
$row = Material::with('promotion')
->where('id', $id)
->first();
// 获取核销图片
$_files = explode(',', $row['files']);
$files = DB::table('promotion_material_file')->whereIn('id', $_files)->get();
foreach ($files as $file) {
$file = upload_path().'/'.$file['path'].'/'.$file['file'];
// 生成缩略图
thumb($file, 80, 80);
}
$row['images'] = $files;
$row['upload_url'] = URL::to('/uploads');
if (Request::wantsJson()) {
return response()->json($row);
}
return $this->render([
'row' => $row,
]);
}
// 促销核销审核
public function auditAction()
{
$id = (array)Request::get('id');
$status = Request::get('status');
$rows = DB::table('promotion_material')
->whereIn('id', $id)->get()->toArray();
if (is_array($rows)) {
foreach ($rows as $row) {
$row['status'] = $status;
DB::table('promotion_material')->where('id', $row['id'])->update($row);
}
}
return $this->json('操作成功。', true);
}
// 促销核销审核
public function archiveAction()
{
$id = (array)Request::get('id');
$rows = DB::table('promotion_material')
->whereIn('id', $id)->get();
$zip_file = upload_path('promotion/material/archive.zip');
$zip = new ZipArchive();
$zip->open($zip_file, ZipArchive::CREATE | ZipArchive::OVERWRITE);
foreach ($rows as $row) {
$files = DB::table('promotion_material_file')->where('material_id', $row['id'])->get();
foreach ($files as $i => $file) {
$path_file = upload_path().'/'.$file['path'];
if (is_file($path_file)) {
$zip->addFile($path_file, $row['name'].'_'.$row['location'].'_'.$i.'.'.$file['type']);
}
}
}
$zip->close();
return $this->json('', true);
}
// 促销核销审核
public function downloadAction()
{
$sn = Request::get('sn');
if(empty($sn)) {
return $this->json('促销编号不能为空。');
}
return response()->download(upload_path('promotion/material/archive.zip'), $sn.'_'.date('Y-m-d').'.zip');
}
public function storeAction()
{
// 上传文件
if (Request::method() == 'POST') {
$gets = Request::all();
$promotion = DB::table('promotion')
->where('id', $gets['promotion_id'])
->first();
if (empty($promotion)) {
return $this->json('促销编号不能为空。');
}
DB::beginTransaction();
try {
$material_id = DB::table('promotion_material')->insertGetId($gets);
$images = Request::file('images');
$path = 'promotion/material/'.date('Y/m');
$upload_path = upload_path().'/'.$path;
$rows = [];
foreach ($images as $image) {
if ($image->isValid()) {
// 文件后缀名
$extension = $image->getClientOriginalExtension();
// 文件新名字
$filename = date('dhis_').str_random(4).'.'.$extension;
$filename = mb_strtolower($filename);
if ($image->move($upload_path, $filename)) {
// 修改图片大小
imageResize($upload_path.'/'.$filename, 1024, 1024);
$rows[] = DB::table('promotion_material_file')->insertGetId([
'material_id' => $material_id,
'path' => $path. '/'. $filename,
'name' => $filename,
'type' => $extension,
'status' => 1,
'size' => $image->getClientSize(),
]);
}
}
}
DB::commit();
return $this->json('照片保存成功。', true);
} catch(\Exception $e) {
DB::rollBack();
return $this->json($e->getMessage());
}
}
}
// 删除核销
public function deleteAction()
{
if (Request::method() == 'POST') {
$var1 = (array)Request::get('id');
$ids = [];
foreach($var1 as $id) {
$ids[] = floatval($id);
}
$rows = Material::whereIn('id', $ids)->get();
foreach ($rows as $row) {
$files = DB::table('promotion_material_file')->where('material_id', $row['id'])->pluck('id');
attachment_delete('promotion_material_file', $files);
$row->delete();
}
return $this->json('促销核销删除成功。', true);
}
}
}
@@ -0,0 +1,524 @@
<?php namespace Gdoo\Promotion\Controllers;
use DB;
use Request;
use Validator;
use Gdoo\User\Models\User;
use Gdoo\Promotion\Models\Promotion;
use Gdoo\Model\Grid;
use Gdoo\Model\Form;
use Gdoo\Index\Services\BadgeService;
use Gdoo\Promotion\Services\PromotionService;
use Gdoo\Index\Controllers\WorkflowController;
class PromotionController extends WorkflowController
{
public $permission = ['dialog', 'serviceSaleOrder', 'useCount', 'product'];
public function indexAction()
{
// 客户权限
$region = regionCustomer('customer_id_customer');
$header = Grid::header([
'code' => 'promotion',
'referer' => 1,
'search' => ['by' => ''],
]);
$cols = $header['cols'];
// 自定义列
$customFields = [
'zp_money' => [
'headerName' => '赠品金额(元)',
'field' => 'zp_money',
'calcFooter' => 'sum',
'width' => 100,
'suppressMenu' => true,
'type' => 'number',
'cellStyle' => ['text-align' => 'right'],
]
];
$cols = Grid::addColumns($cols, 'master_cash_amount', $customFields);
$cols['master_product']['cellRenderer'] = 'htmlCellRenderer';
$cols['master_cash_amount']['cellRenderer'] = 'htmlCellRenderer';
$cols['actions']['options'] = [[
'name' => '显示',
'action' => 'show',
'display' => $this->access['show'],
]];
$search = $header['search_form'];
$query = $search['query'];
if (Request::method() == 'POST') {
$model = DB::table($header['table'])->setBy($header);
foreach ($header['join'] as $join) {
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
}
$model->orderBy($header['sort'], $header['order']);
foreach ($search['where'] as $where) {
if ($where['active']) {
$model->search($where);
}
}
if ($region['authorise']) {
foreach ($region['whereIn'] as $key => $where) {
$model->whereIn($key, $where);
}
}
$model->leftJoin(DB::raw('(SELECT sum(fact_verification_cost) as master_cash_amount, min(date) as master_cash_date, apply_id FROM promotion_review where status = 1 group by apply_id) as b'), 'promotion.id', '=', 'b.apply_id');
$header['select'][] = 'b.master_cash_amount';
$header['select'][] = 'b.master_cash_date';
$model->select($header['select']);
$model->addSelect(DB::raw("case when promotion.type_id = 2 then promotion.undertake_money else 0 end as zp_money"));
$rows = $model->paginate($query['limit'])->appends($query);
$items = Grid::dataFilters($rows, $header, function($item) {
$item['master_cash_amount'] = '<a href="javascript:;" data-toggle="event" data-action="fee_detail" data-master_id="'.$item['master_id'].'" class="option">'.$item['master_cash_amount'].'</a>';
$item['master_product'] = '<a href="javascript:;" data-toggle="event" data-action="product" data-master_id="'.$item['master_id'].'" class="option">明细</a>';
return $item;
});
return $items->toJson();
}
$header['buttons'] = [
//['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
];
$header['left_buttons'] = [
['name' => '批量编辑', 'color' => 'default', 'icon' => 'fa-pencil-square-o', 'action' => 'batchEdit', 'display' => $this->access['batchEdit']],
];
$header['cols'] = $cols;
$header['tabs'] = Promotion::$tabs;
$header['bys'] = Promotion::$bys;
$header['js'] = Grid::js($header);
return $this->display([
'header' => $header,
]);
}
// 新建促销
public function createAction($action = 'edit')
{
$id = (int) Request::get('id');
$header['action'] = $action;
$header['code'] = 'promotion';
$header['id'] = $id;
// 客户权限
$header['region'] = ['field' => 'customer_id'];
$header['authorise'] = ['action' => 'index', 'field' => 'created_id'];
// 获取核销单
$review = DB::table('promotion_review')->where('apply_id', $id)->first();
$header['joint'] = [
['name' => '关联订单', 'action' => 'sale_order', 'field' => 'order_id'],
['name' => '核销单', 'action' => 'promotion_review', 'field' => 'id'],
['name' => '核销资料', 'action' => 'material', 'field' => 'id'],
];
$form = Form::make($header);
$tpl = $action == 'print' ? 'print' : 'create';
return $this->display([
'form' => $form,
'review' => $review,
], $tpl);
}
// 编辑促销
public function editAction()
{
return $this->createAction();
}
// 审核促销
public function auditAction()
{
return $this->createAction('audit');
}
// 显示促销
public function showAction()
{
return $this->createAction('show');
}
// 显示促销
public function printAction()
{
$id = (int) Request::get('id');
$template_id = (int) Request::get('template_id');
$header['action'] = 'print';
$header['code'] = 'promotion';
$header['id'] = $id;
$header['template_id'] = $template_id;
$this->layout = 'layouts.print2';
$form = Form::make($header);
$form['template']['name'] = '促销申请';
print_prince($this->display([
'form' => $form,
], 'print'));
}
// 赠品促销参照到订单
public function serviceSaleOrderAction()
{
$search = search_form(
['advanced' => ''], [
['form_type' => 'text', 'name' => '促销编号', 'field' => 'promotion_sn', 'options' => []],
['form_type' => 'text', 'name' => '客户名称', 'field' => 'customer_id_customer.name', 'options' => []],
], 'model');
$header = Grid::header([
'code' => 'promotion',
]);
$_search = $header['search_form'];
$query = $search['query'];
if (Request::method() == 'POST') {
if ($query['master']) {
$model = DB::table('promotion');
foreach ($header['join'] as $join) {
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
}
$model->where('promotion.customer_id', $query['customer_id'])
->whereRaw('promotion.id in (select promotion_id from ('.PromotionService::getSurplusPromotionSql().') as sp where type_id in (1, 2))')
->where('promotion.customer_id', $query['customer_id'])
->whereRaw('isnull(promotion.is_close, 0) = 0');
foreach ($search['where'] as $where) {
if ($where['active']) {
$model->search($where);
}
}
// 客户权限
$region = regionCustomer('customer_id_customer');
if ($region['authorise']) {
foreach ($region['whereIn'] as $key => $where) {
$model->whereIn($key, $where);
}
}
$model->selectRaw('
promotion.*,
promotion.status as master_status,
promotion.id as master_id,
customer_id_customer.code as customer_code,
customer_id_customer.name as customer_name,
customer_id_customer.warehouse_contact,
customer_id_customer.warehouse_phone,
customer_id_customer.warehouse_address
');
$rows = $model->get();
$rows = Grid::dataFilters($rows, $header, function($row) {
if ($row['type_id'] == 1) {
$row['type_name'] = '物资促销';
} else if($row['type_id'] == 2) {
$row['type_name'] = '赠品促销';
}
return $row;
});
} else {
$sql = "temp.price,
temp.quantity,
temp.ysy_num,
temp.wsy_num,
temp.product_id,
temp.id,
temp.promotion_sn,
temp.promotion_id,
temp.type_id,
temp.customer_id,
temp.promotion_data_id,
temp.customer_name,
temp.customer_code,
p.code AS product_code,
p.name AS product_name,
p.spec AS product_spec,
u.name AS product_unit,
p.weight,
temp.promotion_id as fee_src_id,
temp.promotion_sn as fee_src_sn,
temp.id as promotion_data_id
FROM (SELECT isnull(a.price, 0) AS price,
isnull(a.quantity, 0) AS quantity,
isnull(d.quantity, 0) AS ysy_num,
isnull(a.quantity, 0) - isnull(d.quantity, 0) AS wsy_num,
a.product_id,
a.id,
b.sn AS promotion_sn,
b.id AS promotion_id,
b.type_id,
b.customer_id,
d.promotion_data_id,
c.name AS customer_name,
c.code AS customer_code
FROM promotion_data a
LEFT JOIN promotion b ON a.promotion_id = b.id
LEFT JOIN customer c ON b.customer_id = c.id
LEFT JOIN ( SELECT sum(isnull(customer_order_data.delivery_quantity, 0)) AS quantity,
customer_order_data.promotion_data_id
FROM customer_order_data
WHERE (customer_order_data.promotion_data_id IS NOT NULL)
GROUP BY customer_order_data.promotion_data_id
) d ON a.id = d.promotion_data_id
) temp
LEFT JOIN product p ON temp.product_id = p.id
LEFT JOIN product_unit u ON p.unit_id = u.id";
$model = DB::query()->selectRaw($sql);
$model->whereRaw('isnull(temp.wsy_num, 0) > 0')
->whereIn('type_id', [1, 2])
->where('customer_id', $query['customer_id'])
->whereIn('promotion_id', (array)$query['ids']);
if ($query['sort'] && $query['order']) {
$model->orderBy($query['sort'], $query['order']);
}
/*
'17' as fee_src_type_id,
'6' as fee_category_id,
'赠品' as fee_category_id_name,
'2' as type_id,
'赠品' as type_id_name
*/
$rows = $model->get();
$rows->transform(function ($row) {
// 赠品
if ($row['type_id'] == 2) {
$row['fee_src_type_id'] = 17;
$row['fee_category_id'] = 6;
$row['fee_category_id_name'] = '赠品';
$row['type_id'] = 2;
$row['type_id_name'] = '赠品';
// 物料
} else if ($row['type_id'] == 1) {
$row['fee_src_type_id'] = 17;
$row['fee_category_id'] = 7;
$row['fee_category_id_name'] = '物料';
$row['type_id'] = 4;
$row['type_id_name'] = '物料';
}
return $row;
});
}
return $this->json($rows, true);
}
return $this->render([
'search' => $search,
'query' => $query,
]);
}
// 产品明细
public function productAction()
{
$query = Request::all();
if (Request::method() == 'POST') {
$rows = DB::table('promotion_data')
->leftJoin('product', 'product.id', '=', 'promotion_data.product_id')
->where('promotion_id', $query['id'])
->orderBy('product.code', 'asc')
->get(['product.*']);
return $this->json($rows, true);
}
return $this->render(['query' => $query]);
}
public function closeAction()
{
$gets = Request::all();
if (Request::method() == 'POST') {
$row = DB::table('promotion')->where('id', $gets['id'])->first();
DB::table('promotion')->where('id', $gets['id'])->update([
'is_close' => !$row['is_close']
]);
return $this->json('操作成功。', true);
}
}
// 可用列表
public function useCountAction()
{
$customer_id = Request::get('customer_id');
$count = DB::table('promotion')
->where('promotion.customer_id', $customer_id)
->whereRaw('isnull(promotion.is_close, 0) = 0 and promotion.id in (select promotion_id from ('.PromotionService::getSurplusPromotionSql().') as sp where type_id in (1,2))')
->count('promotion.id');
return $this->json($count, true);
}
// 核销对话框
public function dialogAction()
{
$search = search_form(
['advanced' => ''], [
['form_type' => 'text', 'name' => '客户名称', 'field' => 'customer_id_customer.name', 'options' => []],
['form_type' => 'text', 'name' => '促销编号', 'field' => 'promotion.sn', 'options' => []],
], 'model');
$header = Grid::header([
'code' => 'promotion',
]);
$_search = $header['search_form'];
$query = $search['query'];
if (Request::method() == 'POST') {
if ($query['master']) {
$model = DB::table('promotion');
foreach ($header['join'] as $join) {
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
}
$model->whereRaw('NOT EXISTS (select apply_id from promotion_review where apply_id = promotion.id and apply_id IS NOT NULL)')
->where('promotion.need_review', 1)
->where('promotion.status', 1)
->whereRaw('isnull(promotion.is_close, 0) = 0')
->orderBy('promotion.id', 'desc');
if ($query['sort'] && $query['order']) {
$model->orderBy($query['sort'], $query['order']);
}
foreach ($search['where'] as $where) {
if ($where['active']) {
$model->search($where);
}
}
// 客户权限
$region = regionCustomer('customer_id_customer');
if ($region['authorise']) {
foreach ($region['whereIn'] as $key => $where) {
$model->whereIn($key, $where);
}
}
$model->selectRaw('
promotion.sn,
promotion.created_at as apply_dt,
promotion.start_dt,
promotion.end_dt,
promotion.promote_scope,
'.sql_float_varchar('promotion.apply_fee', 20).' AS apply_money,
'.sql_float_varchar('promotion.undertake_money', 20).' AS undertake_money,
'.sql_float_varchar('promotion.undertake_money', 20).' AS verification_cost,
promotion.status as master_status,
promotion.id as master_id,
promotion.id,
promotion.customer_id,
customer_id_customer.region_id,
customer_id_region_id_customer_region.name as region_name,
customer_id_customer.code as customer_code,
customer_id_customer.name as customer_name,
customer_id_customer.warehouse_contact,
customer_id_customer.warehouse_phone,
customer_id_customer.warehouse_address
');
$rows = $model->get();
$rows = Grid::dataFilters($rows, $header);
} else {
$model = DB::table('promotion_data')
->leftJoin('product', 'product.id', '=', 'promotion_data.product_id')
->leftJoin('promotion', 'promotion.id', '=', 'promotion_data.promotion_id')
->leftJoin('product_unit', 'product_unit.id', '=', 'product.unit_id');
$model->whereRaw('NOT EXISTS (select apply_id from promotion_review where apply_id = promotion.id and apply_id IS NOT NULL)')
->whereIn('promotion.id', (array)$query['ids']);
if ($query['sort'] && $query['order']) {
$model->orderBy($query['sort'], $query['order']);
}
$model->selectRaw("
promotion_data.*,
promotion.id as promotion_id,
promotion.sn as promotion_sn,
product.code as product_code,
product.name as product_name,
product.spec as product_spec,
product.barcode as product_barcode,
product.unit_id as unit_id,
product_unit.name as product_unit,
product.weight,
promotion.id as apply_id,
'1' as apply_type_id,
promotion_data.id as apply_data_id
");
$rows = $model->get();
}
return $this->json($rows, true);
}
return $this->render([
'search' => $search,
'query' => $query,
]);
}
// 批量编辑
public function batchEditAction()
{
$gets = Request::all();
if (Request::method() == 'POST') {
$ids = explode(',', $gets['ids']);
DB::table('promotion')->whereIn('id', $ids)->update([
$gets['field'] => $gets['search_0'],
]);
return $this->json('修改完成。', true);
}
$header = Grid::batchEdit([
'code' => 'promotion',
'columns' => ['customer_id', 'tax_id'],
]);
return view('batchEdit', [
'gets' => $gets,
'header' => $header
]);
}
// 删除促销
public function deleteAction()
{
if (Request::method() == 'POST') {
$ids = Request::get('id');
return Form::remove(['code' => 'promotion', 'ids' => $ids]);
}
}
}
@@ -0,0 +1,175 @@
<?php namespace Gdoo\Promotion\Controllers;
use DB;
use Request;
use Validator;
use Gdoo\User\Models\User;
use Gdoo\Promotion\Models\PromotionReview;
use Gdoo\Model\Grid;
use Gdoo\Model\Form;
use Gdoo\Index\Controllers\WorkflowController;
class ReviewController extends WorkflowController
{
public $permission = ['dialog', 'reference', 'useCount', 'feeDetail'];
public function indexAction()
{
// 客户权限
$region = regionCustomer('customer_id_customer');
$header = Grid::header([
'code' => 'promotion_review',
'referer' => 1,
'search' => ['by' => ''],
]);
$cols = $header['cols'];
$cols['actions']['options'] = [[
'name' => '显示',
'action' => 'show',
'display' => $this->access['show'],
]];
$search = $header['search_form'];
$query = $search['query'];
if (Request::method() == 'POST') {
$model = DB::table($header['table'])->setBy($header);
foreach ($header['join'] as $join) {
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
}
$model->orderBy($header['sort'], $header['order']);
foreach ($search['where'] as $where) {
if ($where['active']) {
$model->search($where);
}
}
if ($region['authorise']) {
foreach ($region['whereIn'] as $key => $where) {
$model->whereIn($key, $where);
}
}
$model->select($header['select']);
$rows = $model->paginate($query['limit'])->appends($query);
$items = Grid::dataFilters($rows, $header);
return $items->toJson();
}
$header['buttons'] = [
//['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
];
$header['left_buttons'] = [
['name' => '批量编辑', 'color' => 'default', 'icon' => 'fa-pencil-square-o', 'action' => 'batchEdit', 'display' => $this->access['batchEdit']],
];
$header['cols'] = $cols;
$header['tabs'] = PromotionReview::$tabs;
$header['bys'] = PromotionReview::$bys;
$header['js'] = Grid::js($header);
return $this->display([
'header' => $header,
]);
}
// 新建促销
public function createAction($action = 'edit')
{
$id = (int)Request::get('id');
// 客户权限
$header['region'] = ['field' => 'customer_id'];
$header['authorise'] = ['action' => 'index', 'field' => 'created_id'];
$header['action'] = $action;
$header['code'] = 'promotion_review';
$header['id'] = $id;
$header['joint'] = [
['name' => '申请单', 'action' => 'apply', 'field' => 'apply_id'],
['name' => '兑现明细', 'action' => 'cash_detail', 'field' => 'apply_id'],
];
$form = Form::make($header);
$tpl = $action == 'print' ? 'print' : 'create';
return $this->display([
'form' => $form,
], $tpl);
}
// 编辑促销
public function editAction()
{
return $this->createAction();
}
// 审核促销
public function auditAction()
{
return $this->createAction('audit');
}
// 显示促销
public function showAction()
{
return $this->createAction('show');
}
// 显示促销
public function printAction()
{
$this->layout = 'layouts.print2';
print_prince($this->createAction('print'));
}
// 批量编辑
public function batchEditAction()
{
$gets = Request::all();
if (Request::method() == 'POST') {
$ids = explode(',', $gets['ids']);
DB::table('promotion_review')->whereIn('id', $ids)->update([
$gets['field'] => $gets['search_0'],
]);
return $this->json('修改完成。', true);
}
$header = Grid::batchEdit([
'code' => 'promotion_review',
'columns' => ['customer_id', 'tax_id'],
]);
return view('batchEdit', [
'gets' => $gets,
'header' => $header
]);
}
// 兑现明细
public function feeDetailAction()
{
$query = Request::all();
if (Request::method() == 'POST') {
$rows = DB::table('promotion_review')->where('apply_id', $query['id'])->orderBy('id', 'desc')->get();
return $this->json($rows, true);
}
return $this->render(['query' => $query]);
}
// 删除促销
public function deleteAction()
{
if (Request::method() == 'POST') {
$ids = Request::get('id');
return Form::remove(['code' => 'promotion_review', 'ids' => $ids]);
}
}
}