创建版本
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
<?php namespace Gdoo\CustomerCost\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\CustomerCost\Models\Adjust;
|
||||
use Gdoo\CustomerCost\Models\CostData;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Index\Controllers\AuditController;
|
||||
|
||||
class AdjustController extends AuditController
|
||||
{
|
||||
public $permission = [];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_cost_adjust',
|
||||
'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']);
|
||||
$model->where('customer_cost.type_id', 86);
|
||||
|
||||
// 客户权限
|
||||
$region = regionCustomer('customer_id_customer');
|
||||
if ($region['authorise']) {
|
||||
foreach ($region['whereIn'] as $key => $where) {
|
||||
$model->whereIn($key, $where);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$header['select'][] = 'customer_cost_data.cost_id';
|
||||
$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['right_buttons'] = [
|
||||
['name' => '关闭', 'color' => 'default', 'icon' => 'fa-lock', 'action' => 'close', 'display' => $this->access['close']],
|
||||
];
|
||||
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = Adjust::$tabs;
|
||||
$header['bys'] = Adjust::$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['code'] = 'customer_cost_adjust';
|
||||
$header['id'] = $id;
|
||||
$header['action'] = $action;
|
||||
|
||||
$form = Form::make($header);
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 编辑促销
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 显示促销
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
// 删除促销
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'customer_cost_adjust', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php namespace Gdoo\CustomerCost\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\CustomerCost\Models\Category;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class CategoryController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_cost_category',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => ''],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '编辑',
|
||||
'action' => 'edit',
|
||||
'display' => $this->access['edit'],
|
||||
]];
|
||||
|
||||
$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('sort', 'asc');
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($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['cols'] = $cols;
|
||||
$header['tabs'] = Category::$tabs;
|
||||
$header['bys'] = Category::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建客户联系人
|
||||
public function createAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'customer_cost_category', 'id' => $id]);
|
||||
return $this->render([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 创建客户联系人
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 显示客户联系人
|
||||
public function showAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$group = Category::find($id);
|
||||
$options = [
|
||||
'table' => 'customer_cost_category',
|
||||
'row' => $group,
|
||||
];
|
||||
$tpl = Form::show($options);
|
||||
return $this->display([
|
||||
'tpl' => $tpl,
|
||||
]);
|
||||
}
|
||||
|
||||
public function dialogAction()
|
||||
{
|
||||
$search = search_form([], [
|
||||
['text','customer_cost_category.name','名称'],
|
||||
['text','customer_cost_category.id','ID'],
|
||||
]);
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = Type::orderBy('sort', 'asc');
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
$rows = $model->get(['*', 'name as text']);
|
||||
return response()->json(['data' => $rows]);
|
||||
}
|
||||
return $this->render([
|
||||
'get' => Request::all()
|
||||
]);
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'customer_cost_category', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
<?php namespace Gdoo\CustomerCost\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\CustomerCost\Models\Compen;
|
||||
use Gdoo\CustomerCost\Models\CostData;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Index\Controllers\AuditController;
|
||||
|
||||
class CompenController extends AuditController
|
||||
{
|
||||
public $permission = ['importExcel'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_cost_compen',
|
||||
'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']);
|
||||
$model->where('customer_cost.type_id', 87);
|
||||
|
||||
// 客户权限
|
||||
$region = regionCustomer('customer_id_customer');
|
||||
if ($region['authorise']) {
|
||||
foreach ($region['whereIn'] as $key => $where) {
|
||||
$model->whereIn($key, $where);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$header['select'][] = 'customer_cost_data.cost_id';
|
||||
$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['cols'] = $cols;
|
||||
$header['tabs'] = Compen::$tabs;
|
||||
$header['bys'] = Compen::$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['code'] = 'customer_cost_compen';
|
||||
$header['id'] = $id;
|
||||
$header['action'] = $action;
|
||||
|
||||
$form = Form::make($header);
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 编辑促销
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 显示促销
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
public function importExcelAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$file = Request::file('file');
|
||||
if ($file->isValid()) {
|
||||
$types = DB::table('customer_order_type')->get()->keyBy('name');
|
||||
|
||||
/*
|
||||
[0] => 客户编码
|
||||
[1] => 客户名称
|
||||
[2] => 金额
|
||||
*/
|
||||
|
||||
$rows = readExcel($file->getPathName());
|
||||
$items = [];
|
||||
|
||||
$codes = [];
|
||||
foreach($rows as $i => $row) {
|
||||
if ($i > 1) {
|
||||
$codes[] = $row[0];
|
||||
}
|
||||
}
|
||||
|
||||
$customers = DB::table('customer')->whereIn('code', $codes)->get()->keyBy('code');
|
||||
foreach($rows as $i => $row) {
|
||||
if ($i > 1) {
|
||||
$customer = $customers[$row[0]];
|
||||
if (empty($customer)) {
|
||||
return $this->json('客户编码'.$row[0].'不存在。');
|
||||
}
|
||||
$item = [
|
||||
'customer_id' => $customer['id'],
|
||||
'customer_id_name' => $customer['name'],
|
||||
'money' => $row[2],
|
||||
];
|
||||
$items[] = $item;
|
||||
}
|
||||
}
|
||||
return $this->json($items, true);
|
||||
}
|
||||
}
|
||||
return view('importExcel');
|
||||
}
|
||||
|
||||
// 删除促销
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'customer_cost_compen', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
<?php namespace Gdoo\CustomerCost\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\CustomerCost\Models\Cost;
|
||||
use Gdoo\CustomerCost\Models\CostData;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Index\Controllers\AuditController;
|
||||
|
||||
class CostController extends AuditController
|
||||
{
|
||||
public $permission = ['dialog', 'serviceSaleOrder', 'useCount'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_cost',
|
||||
'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']);
|
||||
|
||||
// 客户权限
|
||||
$region = regionCustomer('customer_id_customer');
|
||||
if ($region['authorise']) {
|
||||
foreach ($region['whereIn'] as $key => $where) {
|
||||
$model->whereIn($key, $where);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
if ($where['field'] == 'customer_cost_data.tax_id') {
|
||||
$customer_ids = DB::table('customer_tax')->where('id', $where['search'])->pluck('customer_id');
|
||||
$model->whereIn('customer_cost_data.customer_id', $customer_ids);
|
||||
} else {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$header['select'][] = 'customer_cost_data.src_id';
|
||||
$header['select'][] = 'customer_cost_data.src_type_id';
|
||||
$header['select'][] = 'customer_cost_data.cost_id';
|
||||
$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['right_buttons'] = [
|
||||
['name' => '关闭', 'color' => 'default', 'icon' => 'fa-lock', 'action' => 'close', 'display' => $this->access['close']],
|
||||
['name' => '费用调整单', 'color' => 'info', 'icon' => 'fa-plus', 'action' => 'create4', 'display' => $this->access['create4']],
|
||||
];
|
||||
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = Cost::$tabs;
|
||||
$header['bys'] = Cost::$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['code'] = 'customer_cost';
|
||||
$header['id'] = $id;
|
||||
$header['action'] = $action;
|
||||
|
||||
$form = Form::make($header);
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 编辑促销
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 显示促销
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
// 费用参照到订单
|
||||
public function serviceSaleOrderAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_cost',
|
||||
'type' => 'dialog',
|
||||
]);
|
||||
$search = $header['search_form'];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table('customer_cost_data')
|
||||
->leftJoin('customer_cost', 'customer_cost.id', '=', 'customer_cost_data.cost_id')
|
||||
->leftJoin('customer', 'customer.id', '=', 'customer_cost_data.customer_id')
|
||||
->leftJoin('customer_cost_category', 'customer_cost_category.id', '=', 'customer_cost.category_id')
|
||||
->whereRaw('(isnull(customer_cost_data.remain_money, 0) > 0 and isnull(customer_cost_data.use_close, 0) = 0)')
|
||||
->where('customer_cost_data.customer_id', $query['customer_id'])
|
||||
->selectRaw("
|
||||
customer_cost_data.*,
|
||||
customer.name as customer_name,
|
||||
customer.code as customer_code,
|
||||
|
||||
customer_cost.sn,
|
||||
|
||||
customer_cost_data.src_sn as fee_src_sn,
|
||||
customer_cost_data.src_type_id as fee_src_type_id,
|
||||
customer_cost_data.src_id as fee_src_id,
|
||||
customer_cost_data.id as fee_data_id,
|
||||
|
||||
customer_cost_category.name as fee_category_id_name,
|
||||
customer_cost.category_id as fee_category_id,
|
||||
|
||||
'99001' as product_code,
|
||||
'20226' as product_id,
|
||||
'折扣额' as product_name,
|
||||
'元' as product_unit,
|
||||
'5' as type_id,
|
||||
'费用' as type_id_name,
|
||||
customer_cost_data.money as total_money,
|
||||
customer_cost_data.use_money,
|
||||
isnull(customer_cost_data.remain_money, 0) as money
|
||||
");
|
||||
|
||||
if ($query['sort'] && $query['order']) {
|
||||
$model->orderBy($query['sort'], $query['order']);
|
||||
}
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$rows = $model->get();
|
||||
|
||||
$rows->transform(function($row) {
|
||||
$unit = option('product.unit', $row['unit_id']);
|
||||
$row['unit_name'] = $unit;
|
||||
return $row;
|
||||
});
|
||||
return response()->json(['data' => $rows]);
|
||||
}
|
||||
|
||||
return $this->render([
|
||||
'search' => $search,
|
||||
'query' => $query,
|
||||
]);
|
||||
}
|
||||
|
||||
// 可用列表
|
||||
public function useCountAction()
|
||||
{
|
||||
$customer_id = Request::get('customer_id');
|
||||
$count = DB::table('customer_cost_data')
|
||||
->where('customer_id', $customer_id)
|
||||
->whereRaw('(isnull(remain_money, 0) > 0 and isnull(use_close, 0) = 0)')
|
||||
->count();
|
||||
return $this->json($count, true);
|
||||
}
|
||||
|
||||
// 批量编辑
|
||||
public function batchEditAction()
|
||||
{
|
||||
$gets = Request::all();
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = explode(',', $gets['ids']);
|
||||
DB::table('customer_cost_data')->whereIn('id', $ids)->update([
|
||||
$gets['field'] => $gets['search_0'],
|
||||
]);
|
||||
return $this->json('修改完成。', true);
|
||||
}
|
||||
$header = Grid::batchEdit([
|
||||
'code' => 'customer_cost',
|
||||
'columns' => ['customer_id'],
|
||||
]);
|
||||
return view('batchEdit', [
|
||||
'gets' => $gets,
|
||||
'header' => $header
|
||||
]);
|
||||
}
|
||||
|
||||
// 费用关闭
|
||||
public function closeAction()
|
||||
{
|
||||
$gets = Request::all();
|
||||
if (Request::method() == 'POST') {
|
||||
if (empty($gets['close_remark'])) {
|
||||
return $this->json('原因必须填写。');
|
||||
}
|
||||
$cost = CostData::find($gets['id']);
|
||||
$cost->close_remark = $gets['close_remark'];
|
||||
$cost->use_close = $cost->use_close == 1 ? 0 : 1;
|
||||
$cost->save();
|
||||
return $this->json('恭喜你,操作成功。', url_referer('index'));
|
||||
}
|
||||
return $this->render([
|
||||
'gets' => $gets,
|
||||
]);
|
||||
}
|
||||
|
||||
// 删除促销
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'customer_cost', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
<?php namespace Gdoo\CustomerCost\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\CustomerCost\Models\Rebate;
|
||||
use Gdoo\CustomerCost\Models\CostData;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Index\Controllers\AuditController;
|
||||
|
||||
class RebateController extends AuditController
|
||||
{
|
||||
public $permission = ['importExcel'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_cost_rebate',
|
||||
'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']);
|
||||
$model->where('customer_cost.type_id', 88);
|
||||
|
||||
// 客户权限
|
||||
$region = regionCustomer('customer_id_customer');
|
||||
if ($region['authorise']) {
|
||||
foreach ($region['whereIn'] as $key => $where) {
|
||||
$model->whereIn($key, $where);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$header['select'][] = 'customer_cost_data.cost_id';
|
||||
$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['cols'] = $cols;
|
||||
$header['tabs'] = Rebate::$tabs;
|
||||
$header['bys'] = Rebate::$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['code'] = 'customer_cost_rebate';
|
||||
$header['id'] = $id;
|
||||
$header['action'] = $action;
|
||||
|
||||
$form = Form::make($header);
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 编辑促销
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 显示促销
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
public function importExcelAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$file = Request::file('file');
|
||||
if ($file->isValid()) {
|
||||
$types = DB::table('customer_order_type')->get()->keyBy('name');
|
||||
|
||||
/*
|
||||
[0] => 客户编码
|
||||
[1] => 客户名称
|
||||
[2] => 金额
|
||||
*/
|
||||
|
||||
$rows = readExcel($file->getPathName());
|
||||
$items = [];
|
||||
|
||||
$codes = [];
|
||||
foreach($rows as $i => $row) {
|
||||
if ($i > 1) {
|
||||
$codes[] = $row[0];
|
||||
}
|
||||
}
|
||||
|
||||
$customers = DB::table('customer')->whereIn('code', $codes)->get()->keyBy('code');
|
||||
foreach($rows as $i => $row) {
|
||||
if ($i > 1) {
|
||||
$customer = $customers[$row[0]];
|
||||
if (empty($customer)) {
|
||||
return $this->json('客户编码'.$row[0].'不存在。');
|
||||
}
|
||||
$item = [
|
||||
'customer_id' => $customer['id'],
|
||||
'customer_id_name' => $customer['name'],
|
||||
'money' => $row[2],
|
||||
];
|
||||
$items[] = $item;
|
||||
}
|
||||
}
|
||||
return $this->json($items, true);
|
||||
}
|
||||
}
|
||||
return view('importExcel');
|
||||
}
|
||||
|
||||
// 删除促销
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'customer_cost_rebate', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php namespace Gdoo\CustomerCost\Controllers;
|
||||
|
||||
use DB;
|
||||
use View;
|
||||
use Request;
|
||||
|
||||
use Gdoo\Customer\Models\CustomerType;
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class ReportController extends DefaultController
|
||||
{
|
||||
/**
|
||||
* 费用使用统计
|
||||
*/
|
||||
public function saleOrderDetailAction()
|
||||
{
|
||||
$sdate = date('Y-m-01');
|
||||
$edate = date('Y-m-d');
|
||||
$search = search_form([],
|
||||
[['form_type' => 'date2', 'name' => '日期', 'field' => 'date', 'value' => [$sdate, $edate], 'options' => []],
|
||||
['form_type' => 'text', 'name' => '订单编号', 'field' => 'm.sn', 'options' => []],
|
||||
['form_type' => 'text', 'name' => '单据编号', 'field' => 'd.fee_src_sn', 'options' => []],
|
||||
[
|
||||
'form_type' =>'dialog',
|
||||
'field' => 'm.customer_id',
|
||||
'name' => '所属客户',
|
||||
'options' => ['url' => 'customer/customer/dialog', 'query' => []]
|
||||
]/*,[
|
||||
'form_type' =>'dialog',
|
||||
'field' => 'region_id',
|
||||
'name' => '销售团队',
|
||||
'options' => ['url' => 'customer/region/dialog', 'query' => ['layer' => 3]]
|
||||
],*/
|
||||
], 'model');
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$fields = [];
|
||||
foreach($search['forms']['field'] as $i => $field) {
|
||||
$fields[$field] = $search['forms']['search'][$i];
|
||||
}
|
||||
|
||||
$model = DB::table('customer_order_data as d')
|
||||
->leftJoin('product', 'product.id', '=', 'd.product_id')
|
||||
->leftJoin('customer_order as m', 'm.id', '=', 'd.order_id')
|
||||
->leftJoin('customer as c', 'c.id', '=', 'm.customer_id')
|
||||
->leftJoin('customer_cost_category as ccc', 'ccc.id', '=', 'd.fee_category_id')
|
||||
->selectRaw("
|
||||
m.sn,
|
||||
d.fee_src_sn,
|
||||
d.fee_src_type_id,
|
||||
Sum(d.money) as money,
|
||||
c.code as customer_code,
|
||||
c.name as customer_name,
|
||||
ccc.name as category_name,
|
||||
".sql_year_month('l.audit_date', 'ts')." as [ym]
|
||||
")
|
||||
->whereRaw('d.fee_src_sn is not null')
|
||||
->groupBy(DB::raw('c.code,c.name,ccc.name,m.sn,d.fee_src_sn,d.fee_src_type_id,'.sql_year_month('l.audit_date', 'ts')));
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
if ($where['field'] == 'date') {
|
||||
continue;
|
||||
}
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
// 销售会计审核日期
|
||||
$rows = $model->leftJoin(DB::raw("(select max(d.updated_at) as audit_date, m.data_id
|
||||
FROM model_run_log as d left join model_run as m on d.run_id = m.id where m.bill_id = 23 and d.run_name = '销售会计'
|
||||
GROUP BY m.data_id
|
||||
) as l
|
||||
"), 'l.data_id', '=', 'm.id')
|
||||
->whereRaw("(".sql_year_month('l.audit_date', 'ts')." BETWEEN ? AND ?)", $fields['date'])
|
||||
->orderBy(DB::raw(sql_year_month('l.audit_date', 'ts')), 'asc')
|
||||
->get()->toArray();
|
||||
|
||||
foreach($rows as &$row) {
|
||||
$money = abs($row['money']);
|
||||
$row['money'] = $money;
|
||||
}
|
||||
|
||||
return $this->json($rows, true);
|
||||
}
|
||||
|
||||
$header = [
|
||||
'table' => 'customer_cost',
|
||||
'master_table' => 'customer_cost',
|
||||
'buttons' => [],
|
||||
'search_form' => $search,
|
||||
'simple_search_form' => 0,
|
||||
];
|
||||
|
||||
$header['left_buttons'] = [
|
||||
['name' => '导出', 'color' => 'default', 'icon' => 'fa-mail-forward', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
return $this->display([
|
||||
'search' => $search,
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user