创建版本
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
<?php namespace Gdoo\Customer\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Auth;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Form;
|
||||
use Gdoo\Model\Grid;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Customer\Services\CustomerService;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class AccountReportController extends DefaultController
|
||||
{
|
||||
public $permission = [];
|
||||
|
||||
// 客户对账单
|
||||
public function indexAction()
|
||||
{
|
||||
$sdate = date('Y-01-01');
|
||||
$edate = date('Y-m-d');
|
||||
$search = search_form([
|
||||
'advanced' => 0,
|
||||
], [
|
||||
['form_type' => 'date2', 'name' => '日期', 'field' => 'date', 'value' => [$sdate, $edate], 'options' => []],
|
||||
['form_type' => 'dialog', 'name' => '客户', 'field' => 'customer_id', 'options' => [
|
||||
'url' => 'customer/customer/dialog', 'query' => ['multi'=>0]
|
||||
]],
|
||||
['form_type' => 'dialog', 'name' => '开票单位', 'field' => 'tax_id', 'options' => [
|
||||
'url' => 'customer/tax/dialog', 'query' => ['multi'=>0]
|
||||
]],
|
||||
], 'model');
|
||||
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
|
||||
$fields = [];
|
||||
foreach($search['forms']['field'] as $i => $field) {
|
||||
$fields[$field] = $search['forms']['search'][$i];
|
||||
}
|
||||
|
||||
$start_dt = $fields['date'][0];
|
||||
$end_dt = $fields['date'][1];
|
||||
|
||||
$customer_id = (int)$fields['customer_id'];
|
||||
|
||||
$tax_id = $fields['tax_id'];
|
||||
if ($tax_id > 0) {
|
||||
$tax = DB::table('customer_tax')->find($tax_id);
|
||||
$customer_id = $tax['customer_id'];
|
||||
}
|
||||
$taxs = DB::table('customer_tax')->where('customer_id', $customer_id)->get();
|
||||
$tax_names = [];
|
||||
$tax_names2 = [];
|
||||
foreach($taxs as $tax) {
|
||||
$tax_names[$tax['code']] = $tax['name'];
|
||||
$tax_names2[$tax['id']] = $tax['name'];
|
||||
}
|
||||
|
||||
$ret = [];
|
||||
if ($start_dt && $end_dt && $customer_id) {
|
||||
|
||||
$json = collect();
|
||||
$one = [];
|
||||
|
||||
// 获取用友数据
|
||||
$res = plugin_sync_api('acclist/code/'.$taxs->implode('code', ',').'/start_dt/'.$start_dt.'/end_dt/'.$end_dt);
|
||||
if (count($res['data'])) {
|
||||
// 获取初期余额
|
||||
$one = array_shift($res['data']);
|
||||
foreach($res['data'] as $row) {
|
||||
if ($row['dgst'] == '合计') {
|
||||
continue;
|
||||
}
|
||||
$row['tax_name'] = $tax_names[$row['cdwcode']];
|
||||
$json->push($row);
|
||||
}
|
||||
}
|
||||
|
||||
$rows = CustomerService::getAccList($customer_id, $start_dt, $end_dt);
|
||||
$ye = (float)$one['ye'];
|
||||
foreach($rows as $row) {
|
||||
if ($row['dgst'] == '合计') {
|
||||
continue;
|
||||
}
|
||||
if ($row['dgst'] == '期初余额') {
|
||||
$row['ye'] = $row['ye'] + $ye;
|
||||
}
|
||||
$row['tax_name'] = $tax_names2[$row['tax_id']];
|
||||
$json->push($row);
|
||||
}
|
||||
|
||||
// 多字段排序
|
||||
$json = $json->multiSortBy(['orderNum' => 'asc', 'dDate' => 'asc', 'orderD' => 'asc']);
|
||||
|
||||
$ye = 0;
|
||||
$json->transform(function($row) use (&$ye) {
|
||||
if ($row['dgst'] == '期初余额') {
|
||||
$ye = $row['ye'];
|
||||
} else {
|
||||
$ye = $ye + $row['df'] - $row['jf'] - $row['bcsyfy'];
|
||||
}
|
||||
$row['ye'] = $ye;
|
||||
return $row;
|
||||
});
|
||||
|
||||
$json->push([
|
||||
'dgst' => '合计',
|
||||
'orderNum' => 3,
|
||||
'qtfy' => $json->sum('qtfy'),
|
||||
'xzfy' => $json->sum('xzfy'),
|
||||
'bcsyfy' => $json->sum('bcsyfy'),
|
||||
'jf' => $json->sum('jf'),
|
||||
'df' => $json->sum('df'),
|
||||
'sl' => $json->sum('sl'),
|
||||
'ye' => $ye,
|
||||
]);
|
||||
|
||||
$bills = DB::table('model_bill')->get()->keyBy('id');
|
||||
|
||||
foreach($json as $row) {
|
||||
|
||||
$bill = $bills[$row['srcMasterBillType']];
|
||||
$row['bill_name'] = $bill['name'];
|
||||
$row['url'] = $bill['uri'].'/show';
|
||||
$ret[] = $row;
|
||||
}
|
||||
|
||||
}
|
||||
return $this->json($ret, true);
|
||||
}
|
||||
$search['table'] = 'material_plan';
|
||||
return $this->display([
|
||||
'search' => $search,
|
||||
'query' => $query,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php namespace Gdoo\Customer\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Session;
|
||||
use Request;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Index\Controllers\Controller;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
/**
|
||||
* 经销商业务员登录专用接口
|
||||
*/
|
||||
public function salemanAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
|
||||
if (empty($gets['username'])) {
|
||||
return $this->json('客户代码不能为空。');
|
||||
}
|
||||
|
||||
$user = User::where('username', $gets['username'])
|
||||
->where('status', 1)
|
||||
->where('group_id', 2)->first();
|
||||
|
||||
if ($user->id > 0) {
|
||||
Auth::login($user, true);
|
||||
Session::put('auth_totp', true);
|
||||
return $this->json('登录成功。', true);
|
||||
} else {
|
||||
return $this->json('登录失败,客户代码无效。');
|
||||
}
|
||||
}
|
||||
return $this->json('登录失败。');
|
||||
}
|
||||
|
||||
public function json($data, $status = false, $type = 'primary')
|
||||
{
|
||||
$json = [];
|
||||
$json['status'] = $status;
|
||||
$json['state'] = $status;
|
||||
$json['info'] = $type;
|
||||
$json['data'] = $data;
|
||||
return response()->json($json);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
<?php namespace Gdoo\Customer\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Request;
|
||||
use Validator;
|
||||
use DB;
|
||||
|
||||
use Gdoo\Customer\Models\Business;
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Index\Models\Attachment;
|
||||
|
||||
use Gdoo\Index\Services\NotificationService;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
use Gdoo\Index\Services\AttachmentService;
|
||||
|
||||
class BusinessController extends DefaultController
|
||||
{
|
||||
public $permission = ['index','salesman','store'];
|
||||
|
||||
// 商机列表
|
||||
public function indexAction()
|
||||
{
|
||||
// 筛选客户
|
||||
$filter = select::customer();
|
||||
$columns = [
|
||||
['text','customer_business.name','客户名称'],
|
||||
];
|
||||
if ($filter['role_type'] == 'salesman') {
|
||||
$columns[] = ['text','customer_business.address','客户地区'];
|
||||
$columns[] = ['text','customer_business.type','客户类型'];
|
||||
}
|
||||
|
||||
if ($filter['role_type'] == 'all') {
|
||||
$columns[] = ['text','user.name','创建者'];
|
||||
$columns[] = ['owner','customer_business.user_id','负责人'];
|
||||
$columns[] = ['text','customer_business.address','客户地区'];
|
||||
$columns[] = ['text','customer_business.type','客户类型'];
|
||||
}
|
||||
|
||||
$search = search_form([
|
||||
'status' => 1,
|
||||
'referer' => 1
|
||||
], $columns);
|
||||
|
||||
$query = $search['query'];
|
||||
|
||||
$model = Business::leftJoin('user', 'user.id', '=', 'customer_business.created_id')
|
||||
->select(['customer_business.*']);
|
||||
|
||||
$level = authorise();
|
||||
if ($level < 4) {
|
||||
$model->where('customer_business.user_id', Auth::id());
|
||||
}
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
if ($query['order'] && $query['srot']) {
|
||||
$model->orderBy($query['srot'], $query['order']);
|
||||
} else {
|
||||
$model->orderBy('customer_business.id', 'desc');
|
||||
}
|
||||
|
||||
$rows = $model->paginate($query['limit']);
|
||||
|
||||
if (Request::wantsJson()) {
|
||||
return $rows->toJson();
|
||||
}
|
||||
|
||||
$rows = $rows->appends($query);
|
||||
|
||||
return $this->display(array(
|
||||
'rows' => $rows,
|
||||
'search' => $search,
|
||||
));
|
||||
}
|
||||
|
||||
// 客户资料查看
|
||||
public function showAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$row = DB::table('customer_business')
|
||||
->leftJoin('user', 'user.id', '=', 'customer_business.user_id')
|
||||
->where('customer_business.id', $id)
|
||||
->first(['customer_business.*','user.name']);
|
||||
|
||||
// 返回json
|
||||
$row['address'] = str_replace("\n", " ", $row['address']);
|
||||
$attachments = AttachmentService::show($row['attachment']);
|
||||
$row['attachments'] = $attachments['main'];
|
||||
return response()->json($row);
|
||||
}
|
||||
|
||||
// 负责人列表
|
||||
public function salesmanAction()
|
||||
{
|
||||
if (Request::wantsJson()) {
|
||||
$users = User::leftJoin('role', 'role.id', '=', 'user.role_id')
|
||||
->where('role.name', 'salesman')
|
||||
->where('user.status', 1)
|
||||
->get(['user.id', 'user.username', 'user.name']);
|
||||
return $this->json($users);
|
||||
}
|
||||
}
|
||||
|
||||
// 储存商机
|
||||
public function storeAction()
|
||||
{
|
||||
if (Request::isJson()) {
|
||||
$gets = json_decode(Request::getContent(), true);
|
||||
} else {
|
||||
$gets = Request::all();
|
||||
}
|
||||
|
||||
$row = new Business;
|
||||
|
||||
$rules = [
|
||||
'source' => 'required',
|
||||
'user_id' => 'required',
|
||||
'name' => 'required',
|
||||
// 'attachment' => 'min:1|array|required',
|
||||
];
|
||||
|
||||
$v = Validator::make($gets, $rules, Business::$_messages);
|
||||
if ($v->fails()) {
|
||||
return $this->json($v->errors());
|
||||
}
|
||||
|
||||
// 地区
|
||||
if (is_array($gets['address'])) {
|
||||
$gets['address'] = join("\n", $gets['address']);
|
||||
}
|
||||
|
||||
// 保存base64图片数据
|
||||
// $gets['attachment'] = Attachment::base64($gets['attachment'], 'customer');
|
||||
|
||||
if (is_array($gets['attachment'])) {
|
||||
$gets['attachment'] = AttachmentService::base64($gets['attachment'], 'customer');
|
||||
} else {
|
||||
$gets['attachment'] = AttachmentService::files('image', 'customer');
|
||||
}
|
||||
|
||||
$row->fill($gets)->save();
|
||||
|
||||
$user = User::find($gets['user_id']);
|
||||
|
||||
NotificationService::sms([$gets['contacts_phone']], '感谢您对川南公司的关注', '负责您的业务人员是'.$user['name'].',电话'.$user['phone'].'。您可与其沟通或登陆www.cnnzfood.com');
|
||||
|
||||
return $this->json('恭喜你,操作成功。', true);
|
||||
}
|
||||
|
||||
// 删除商机
|
||||
public function destroyAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$id = Request::get('id');
|
||||
$rows = Business::whereIn('id', $id)->get();
|
||||
if ($rows) {
|
||||
foreach ($rows as $row) {
|
||||
AttachmentService::remove($row->attachment);
|
||||
$row->delete();
|
||||
}
|
||||
}
|
||||
return $this->success('index', '恭喜你,删除成功。');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
<?php namespace Gdoo\Customer\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Auth;
|
||||
use Paginator;
|
||||
|
||||
use Gdoo\Customer\Models\CustomerComplaint;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Index\Controllers\WorkflowController;
|
||||
|
||||
class ComplaintController extends WorkflowController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
/**
|
||||
* 订单列表
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
// 客户权限
|
||||
$region = regionCustomer('customer_id_customer');
|
||||
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_complaint',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => ''],
|
||||
]);
|
||||
|
||||
$search = $header['search_form'];
|
||||
$query = $search['query'];
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '显示',
|
||||
'action' => 'show',
|
||||
'display' => $this->access['show'],
|
||||
]];
|
||||
|
||||
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-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = CustomerComplaint::$tabs;
|
||||
$header['bys'] = CustomerComplaint::$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'] = 'customer_complaint';
|
||||
$header['id'] = $id;
|
||||
|
||||
// 客户权限
|
||||
$header['region'] = ['field' => 'customer_id'];
|
||||
$header['authorise'] = ['action' => 'index', 'field' => 'created_id'];
|
||||
|
||||
$form = Form::make($header);
|
||||
$row = $form['row'];
|
||||
$tpl = $action == 'print' ? 'print' : 'create';
|
||||
|
||||
if ($action == 'print') {
|
||||
$this->layout = 'layouts.print_'.$form['print_type'];
|
||||
}
|
||||
|
||||
return $this->display(['form' => $form], $tpl);
|
||||
}
|
||||
|
||||
// 编辑促销
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 显示促销
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
// 显示促销
|
||||
public function printAction()
|
||||
{
|
||||
return $this->createAction('print');
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单删除
|
||||
*/
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$id = Request::get('id');
|
||||
return Form::remove(['code' => 'customer_complaint', 'ids' => $id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
<?php namespace Gdoo\Customer\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
use Gdoo\Customer\Models\Customer;
|
||||
use Gdoo\Customer\Models\Contact;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class ContactController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_contact',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => ''],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
// 客户权限
|
||||
$region = regionCustomer('customer_id_customer');
|
||||
|
||||
$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($header['sort'], $header['order'])
|
||||
->orderBy('id', 'desc');
|
||||
|
||||
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']],
|
||||
];
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = Contact::$tabs;
|
||||
$header['bys'] = Contact::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建客户联系人
|
||||
public function createAction($action = 'edit')
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'customer_contact','id' => $id, 'action' => $action]);
|
||||
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_contact', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出层信息
|
||||
*/
|
||||
public function dialogAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_contact',
|
||||
]);
|
||||
$search = $header['search_form'];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table']);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// 客户圈权限
|
||||
$region = regionCustomer();
|
||||
if ($region['authorise']) {
|
||||
foreach ($region['whereIn'] as $key => $where) {
|
||||
$model->whereIn($key, $where);
|
||||
}
|
||||
}
|
||||
|
||||
if ($query['region_id']) {
|
||||
$model->where('customer.region_id', $query['region_id']);
|
||||
}
|
||||
|
||||
$model->select($header['select']);
|
||||
|
||||
$rows = $model->paginate($query['limit']);
|
||||
$items = Grid::dataFilters($rows, $header, function($item) {
|
||||
$item['text'] = $item['name'];
|
||||
return $item;
|
||||
});
|
||||
return response()->json($items);
|
||||
}
|
||||
$query['form_id'] = $query['jqgrid'] == '' ? $query['id'] : $query['jqgrid'];
|
||||
return $this->render([
|
||||
'search' => $search,
|
||||
'query' => $query,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php namespace Gdoo\Customer\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Customer\Models\CustomerApply;
|
||||
use Gdoo\User\Models\User;
|
||||
|
||||
use Gdoo\Index\Controllers\WorkflowController;
|
||||
|
||||
class CustomerApplyController extends WorkflowController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_apply',
|
||||
'referer' => 1,
|
||||
'sort' => 'customer_apply.id',
|
||||
'order' => 'asc',
|
||||
'search' => ['by' => 'todo'],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '显示',
|
||||
'action' => 'show',
|
||||
'display' => $this->access['show'],
|
||||
]/*,[
|
||||
'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($header['sort'], $header['order']);
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
if ($query['by']) {
|
||||
if ($query['by'] == 'end') {
|
||||
$model->where('customer_apply.status', 1);
|
||||
} else {
|
||||
$model->where('customer_apply.status', '<>', 1);
|
||||
}
|
||||
}
|
||||
|
||||
// 客户权限
|
||||
$region = regionCustomer('customer_apply');
|
||||
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, function($item) {
|
||||
return $item;
|
||||
});
|
||||
return $items->toJson();
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '导出', 'icon' => 'fa-mail-reply', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = CustomerApply::$tabs;
|
||||
$header['bys'] = CustomerApply::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建客户联系人
|
||||
public function createAction($action = 'create')
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
|
||||
// 客户权限
|
||||
$header['region'] = ['field' => 'id'];
|
||||
$header['authorise'] = ['action' => 'index', 'field' => 'created_id'];
|
||||
|
||||
$header['code'] = 'customer_apply';
|
||||
$header['id'] = $id;
|
||||
$header['action'] = $action;
|
||||
|
||||
$form = Form::make($header);
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 创建客户联系人
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction('edit');
|
||||
}
|
||||
|
||||
// 审核
|
||||
public function auditAction()
|
||||
{
|
||||
return $this->createAction('audit');
|
||||
}
|
||||
|
||||
// 显示客户联系人
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'customer_apply', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php namespace Gdoo\Customer\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Customer\Models\CustomerClass;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class CustomerClassController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$display = $this->access;
|
||||
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_class',
|
||||
'referer' => 1,
|
||||
'search' => [],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '编辑',
|
||||
'action' => 'edit',
|
||||
'display' => $display['edit'],
|
||||
]];
|
||||
unset($cols['checkbox']);
|
||||
|
||||
$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('customer_class.code', 'asc');
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$model->select($header['select'])
|
||||
->addSelect(DB::raw('parent_id'));
|
||||
|
||||
$items = $model->get()->toNested('name');
|
||||
$items = Grid::dataFilters($items, $header, function($item) {
|
||||
return $item;
|
||||
});
|
||||
return $this->json($items, true);
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '删除','icon' => 'fa-remove','action' => 'delete','display' => $display['delete']],
|
||||
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = CustomerClass::$tabs;
|
||||
$header['bys'] = CustomerClass::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
public function createAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'customer_class', 'id' => $id]);
|
||||
return $this->render([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
public function dialogAction()
|
||||
{
|
||||
$search = search_form([], [
|
||||
['text','customer_class.name','名称'],
|
||||
['text','customer_class.code','编码'],
|
||||
['text','customer_class.id','ID'],
|
||||
]);
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = CustomerClass::orderBy('code', 'asc');
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
// $model->where('end', 1);
|
||||
$rows = $model->get();
|
||||
return response()->json(['data' => $rows]);
|
||||
}
|
||||
return $this->render([
|
||||
'search' => $search
|
||||
]);
|
||||
}
|
||||
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$id = Request::get('id');
|
||||
$id = array_filter((array)$id);
|
||||
if (empty($id)) {
|
||||
return $this->json('最少选择一行记录。');
|
||||
}
|
||||
$has = CustomerClass::whereIn('parent_id', $id)->count();
|
||||
if ($has) {
|
||||
return $this->json('存在子节点不允许删除。');
|
||||
}
|
||||
CustomerClass::whereIn('id', $id)->delete();
|
||||
return $this->json('删除成功。', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
<?php namespace Gdoo\Customer\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Customer\Models\Customer;
|
||||
use Gdoo\User\Models\User;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class CustomerController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'customer',
|
||||
'referer' => 1,
|
||||
'sort' => 'customer.id',
|
||||
'order' => 'asc',
|
||||
'search' => ['by' => 'enabled'],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
$cols['actions']['options'] = [[
|
||||
'name' => '显示',
|
||||
'action' => 'show',
|
||||
'display' => $this->access['show'],
|
||||
],[
|
||||
'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($header['sort'], $header['order']);
|
||||
|
||||
if ($query['by']) {
|
||||
if ($query['by'] == 'enabled') {
|
||||
$model->where('customer.status', 1);
|
||||
}
|
||||
if ($query['by'] == 'disabled') {
|
||||
$model->where('customer.status', 0);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
// 客户权限
|
||||
$region = regionCustomer();
|
||||
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, function($item) {
|
||||
return $item;
|
||||
});
|
||||
return $items->toJson();
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
|
||||
['name' => '导出', 'icon' => 'fa-mail-reply', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['left_buttons'] = [
|
||||
['name' => '批量编辑', 'color' => 'default', 'icon' => 'fa-pencil-square-o', 'action' => 'batchEdit', 'display' => $this->access['batchEdit']],
|
||||
['name' => '销售产品价格', 'color' => 'default', 'icon' => 'fa-pencil-square-o', 'action' => 'priceEdit', 'display' => $this->access['priceEdit']],
|
||||
];
|
||||
|
||||
$header['right_buttons'] = [
|
||||
['name' => '导入', 'color' => 'default', 'icon' => 'fa-mail-reply', 'action' => 'import', 'display' => $this->access['import']],
|
||||
];
|
||||
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = Customer::$tabs;
|
||||
$header['bys'] = Customer::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建客户联系人
|
||||
public function createAction($action = 'create')
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
|
||||
// 客户权限
|
||||
$header['region'] = ['field' => 'id'];
|
||||
$header['authorise'] = ['action' => 'index', 'field' => 'created_id'];
|
||||
|
||||
$header['code'] = 'customer';
|
||||
$header['id'] = $id;
|
||||
$header['action'] = $action;
|
||||
|
||||
$form = Form::make($header);
|
||||
|
||||
$taxs = [];
|
||||
if ($action == 'show') {
|
||||
$taxs = DB::table('customer_tax')->where('customer_id', $id)->get();
|
||||
}
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
'taxs' => $taxs,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 创建客户联系人
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction('edit');
|
||||
}
|
||||
|
||||
// 批量编辑
|
||||
public function batchEditAction()
|
||||
{
|
||||
$gets = Request::all();
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = explode(',', $gets['ids']);
|
||||
DB::table('customer')->whereIn('id', $ids)->update([
|
||||
$gets['field'] => $gets['search_0'],
|
||||
]);
|
||||
return $this->json('修改完成。', true);
|
||||
}
|
||||
$header = Grid::batchEdit([
|
||||
'code' => 'customer',
|
||||
'columns' => ['region3_id', 'region2_id', 'region_id', 'grade_id', 'type_id', 'class2_id', 'class_id', 'department_id', 'status'],
|
||||
]);
|
||||
return view('batchEdit', [
|
||||
'gets' => $gets,
|
||||
'header' => $header
|
||||
]);
|
||||
}
|
||||
|
||||
// 销售产品价格
|
||||
public function priceEditAction()
|
||||
{
|
||||
$gets = Request::all();
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = explode(',', $gets['ids']);
|
||||
$product_id = $gets['product_id'];
|
||||
$price = floatval($gets['price']);
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
foreach($ids as $id) {
|
||||
// 查找客户价格本
|
||||
$count = DB::table('customer_price')
|
||||
->where('customer_id', $id)
|
||||
->where('product_id', $product_id)
|
||||
->count();
|
||||
|
||||
if ($count == 0) {
|
||||
DB::table('customer_price')->insert([
|
||||
'customer_id' => $id,
|
||||
'product_id' => $product_id,
|
||||
'price' => $price,
|
||||
]);
|
||||
}
|
||||
}
|
||||
// 提交事务
|
||||
DB::commit();
|
||||
return $this->json('更新成功。', true);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
abort_error($e->getMessage());
|
||||
}
|
||||
}
|
||||
return $this->render([
|
||||
'gets' => $gets,
|
||||
]);
|
||||
}
|
||||
|
||||
// 显示客户联系人
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
// 数据导入
|
||||
public function importAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
return Form::import(['table' => 'customer', 'keys' => ['code', 'username']]);
|
||||
}
|
||||
$tips = '注意:表格里必须包含[客户代码]列。';
|
||||
return $this->render(['tips' => $tips], 'layouts.import');
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'customer', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出层信息
|
||||
*/
|
||||
public function dialogAction()
|
||||
{
|
||||
$search = search_form(
|
||||
['advanced' => ''], [
|
||||
['form_type' => 'text', 'name' => '客户名称', 'field' => 'customer.name', 'options' => []],
|
||||
['form_type' => 'text', 'name' => '客户编码', 'field' => 'customer.code', 'options' => []],
|
||||
['form_type' =>'dialog', 'field' => 'customer.region_id', 'name' => '销售区域', 'options' => ['url' => 'customer/region/dialog', 'query' => ['layer' => 3]]],
|
||||
], 'model');
|
||||
|
||||
$header = Grid::header([
|
||||
'code' => 'customer',
|
||||
]);
|
||||
$_search = $header['search_form'];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table']);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// 客户权限
|
||||
$region = regionCustomer();
|
||||
if ($region['authorise']) {
|
||||
foreach ($region['whereIn'] as $key => $where) {
|
||||
$model->whereIn($key, $where);
|
||||
}
|
||||
}
|
||||
|
||||
if ($query['region_id']) {
|
||||
$model->where('customer.region_id', $query['region_id']);
|
||||
}
|
||||
|
||||
$header['select'][] = 'customer.user_id';
|
||||
$model->select($header['select']);
|
||||
|
||||
// 获取默认收货地址
|
||||
$sqlsrv = $pgsql = '';
|
||||
if ($this->dbType == 'sqlsrv') {
|
||||
$sqlsrv = 'top 1';
|
||||
} else if($this->dbType == 'pgsql') {
|
||||
$pgsql = 'LIMIT 1';
|
||||
}
|
||||
$model->leftJoin(DB::raw('(select '.$sqlsrv.' max(id) as delivery_address_id, customer_id, name as warehouse_contact2, phone as warehouse_phone2, address as warehouse_address2, tel as warehouse_tel2
|
||||
FROM customer_delivery_address
|
||||
where is_default = 1
|
||||
GROUP BY customer_id, name, phone, address, tel
|
||||
'.$pgsql.'
|
||||
) cda
|
||||
'), 'customer.id', '=', 'cda.customer_id');
|
||||
|
||||
$model->addSelect(DB::raw('cda.*'));
|
||||
|
||||
if ($query['suggest']) {
|
||||
if ($query['q']) {
|
||||
$q = $query['q'];
|
||||
$model->whereRaw("(customer.code like '%$q%' or customer.name like '%$q%')");
|
||||
}
|
||||
$rows = $model->limit(15)->get();
|
||||
$data = Grid::dataFilters($rows, $header, function($item) {
|
||||
return $item;
|
||||
});
|
||||
$items['data'] = $data;
|
||||
} else {
|
||||
$rows = $model->paginate($query['limit']);
|
||||
$items = Grid::dataFilters($rows, $header, function($item) {
|
||||
$item['text'] = $item['name'];
|
||||
$item['sid'] = 'u'.$item['user_id'];
|
||||
return $item;
|
||||
});
|
||||
}
|
||||
return response()->json($items);
|
||||
}
|
||||
return $this->render([
|
||||
'search' => $search,
|
||||
'query' => $query,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
<?php namespace Gdoo\Customer\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Customer\Models\DeliveryAddress;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class DeliveryAddressController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_delivery_address',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => ''],
|
||||
]);
|
||||
|
||||
$cols = $header['cols'];
|
||||
|
||||
// 客户权限
|
||||
$region = regionCustomer('customer_id_customer');
|
||||
|
||||
$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($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']],
|
||||
];
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = DeliveryAddress::$tabs;
|
||||
$header['bys'] = DeliveryAddress::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建客户联系人
|
||||
public function createAction($action = 'edit')
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'customer_delivery_address','id' => $id, 'action' => $action]);
|
||||
return $this->render([
|
||||
'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_delivery_address', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出层信息
|
||||
*/
|
||||
public function dialogAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_delivery_address',
|
||||
'prefix' => '',
|
||||
]);
|
||||
$search = $header['search_form'];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table']);
|
||||
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 (isset($query['select2']) && $query['q']) {
|
||||
$model->where('customer_delivery_address.address', 'like', '%'. $query['q'] .'%');
|
||||
}
|
||||
|
||||
// 搜索条件
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$model->whereRaw('customer_delivery_address.customer_id > 0 and customer_delivery_address.customer_id = ?', [$query['customer_id']]);
|
||||
|
||||
$header['select'][] = 'customer_delivery_address.id';
|
||||
$header['select'][] = 'customer_delivery_address.address as text';
|
||||
|
||||
if ($query['related'] == '0') {
|
||||
$header['select'][] = 'customer_delivery_address.address as id';
|
||||
}
|
||||
|
||||
$model->select($header['select']);
|
||||
|
||||
$rows = $model->paginate($query['limit']);
|
||||
|
||||
if (isset($query['autocomplete'])) {
|
||||
return response()->json($rows->items());
|
||||
}
|
||||
return response()->json($rows);
|
||||
}
|
||||
return $this->render([
|
||||
'search' => $search,
|
||||
'query' => $query,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
<?php namespace Gdoo\Customer\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Customer\Models\CustomerPrice;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Product\Models\Product;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class PriceController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog', 'list', 'referCustomer'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_price',
|
||||
'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($header['sort'], $header['order']);
|
||||
$model->where('customer_id_customer.id', '>', 0);
|
||||
$model->where('product_id_product.id', '>', 0);
|
||||
$model->where('product_id_product.status', 1);
|
||||
|
||||
// 客户权限
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
$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' => '导入', 'icon' => 'fa-mail-reply', 'color' => 'default', 'action' => 'import', 'display' => $this->access['import']],
|
||||
];
|
||||
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = CustomerPrice::$tabs;
|
||||
$header['bys'] = CustomerPrice::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建促销
|
||||
public function createAction($action = 'edit')
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'customer_price', 'id' => $id, 'action' => $action]);
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 编辑促销
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
// 显示促销
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('edit');
|
||||
}
|
||||
|
||||
// 客户价格列表
|
||||
public function listAction()
|
||||
{
|
||||
$gets = Request::all();
|
||||
if ($gets['customer_id']) {
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_price',
|
||||
]);
|
||||
$model = CustomerPrice::where('customer_id', $gets['customer_id']);
|
||||
foreach ($header['join'] as $join) {
|
||||
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
|
||||
}
|
||||
|
||||
$model->where('product_id_product.status', 1);
|
||||
$model->orderBy('customer_price.id', 'asc');
|
||||
|
||||
$rows = $model->get($header['select']);
|
||||
$rows = Grid::dataFilters($rows, $header, function($row) {
|
||||
$row['product_name'] = $row['product_id_name'];
|
||||
return $row;
|
||||
});
|
||||
} else {
|
||||
$rows = [];
|
||||
}
|
||||
return $this->json($rows, true);
|
||||
}
|
||||
|
||||
// 参考客户价格
|
||||
public function referCustomerAction()
|
||||
{
|
||||
$search = search_form(
|
||||
['advanced' => ''], [
|
||||
['form_type' => 'dialog', 'name' => '客户', 'field' => 'customer_price.customer_id', 'options' => [
|
||||
'url' => 'customer/customer/dialog', 'query' => ['multi'=>0]
|
||||
]],
|
||||
], 'model');
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
|
||||
$active = false;
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$active = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($active) {
|
||||
$model = CustomerPrice::query();
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_price',
|
||||
]);
|
||||
foreach ($header['join'] as $join) {
|
||||
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
|
||||
}
|
||||
$model->where('product_id_product.status', 1);
|
||||
$model->orderBy('customer_price.id', 'asc');
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
$rows = $model->get($header['select']);
|
||||
$rows = Grid::dataFilters($rows, $header, function($row) {
|
||||
$row['product_name'] = $row['product_id_name'];
|
||||
return $row;
|
||||
});
|
||||
} else {
|
||||
$rows = [];
|
||||
}
|
||||
return $this->json($rows, true);
|
||||
}
|
||||
$search['query']['id'] = 'refer_customer';
|
||||
return $this->render([
|
||||
'search' => $search,
|
||||
]);
|
||||
}
|
||||
|
||||
// 数据导入
|
||||
public function importAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
return Form::import(['table' => 'customer_price', 'keys' => ['customer_id', 'product_id']]);
|
||||
}
|
||||
$tips = '注意:表格里必须包含[存货编码,客户代码]列。';
|
||||
return $this->render(['tips' => $tips], 'layouts.import');
|
||||
}
|
||||
|
||||
// 删除促销
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'customer_price', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
<?php namespace Gdoo\Customer\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Customer\Models\Customer;
|
||||
use Gdoo\Customer\Models\CustomerType;
|
||||
use Gdoo\Index\Models\Region;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class ReconcileController extends DefaultController
|
||||
{
|
||||
public $permission = [];
|
||||
|
||||
// 单客户查询对账数据
|
||||
public function queryAction()
|
||||
{
|
||||
$search = search_form([
|
||||
'customer' => '',
|
||||
'start_at' => '',
|
||||
'end_at' => '',
|
||||
], []);
|
||||
|
||||
$query = $search['query'];
|
||||
|
||||
if ($query['customer']) {
|
||||
$customer = DB::table('customer')
|
||||
->leftJoin('user', 'customer.user_id', '=', 'user.id')
|
||||
->where('customer.id', $query['customer'])
|
||||
->first();
|
||||
|
||||
$ch = curl_init(env('YONYOU_URL').'/yonyou.php?do=ar&start_at='.$query['start_at'].'&end_at='.$query['end_at'].'&customer_code='.$customer['username']);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$res = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
$data = json_decode($res, true);
|
||||
|
||||
$lists = [];
|
||||
foreach ($data as $row) {
|
||||
$cDwCode = $row['cDwCode'];
|
||||
$lists[$cDwCode][] = $row;
|
||||
}
|
||||
|
||||
$res = [];
|
||||
$total_start = $total_end = 0;
|
||||
foreach ($lists as $code => $rows) {
|
||||
$ye = 0;
|
||||
foreach ($rows as $i => $row) {
|
||||
|
||||
$ye = $ye + $row['ye'];
|
||||
$ye = $ye + $row['jf'] - $row['df'];
|
||||
|
||||
if($row['iYear'] && $row['iMonth'] && $row['iDay']) {
|
||||
$date = date('Y-m-d', strtotime($row['iYear'].'-'.$row['iMonth'].'-'.$row['iDay']));
|
||||
$jf = number_format($row['jf'], 2);
|
||||
$df = number_format($row['df'], 2);
|
||||
$res[] = [
|
||||
'code' => $code,
|
||||
'date' => $date,
|
||||
'jmoney' => $jf,
|
||||
'dmoney' => $df,
|
||||
'balance' => number_format($ye, 2),
|
||||
'ccusname' => $row['ccusname'],
|
||||
'digest' => $row['cDigest'],
|
||||
'ddh' => $row['ddh'],
|
||||
'zp' => number_format($row['zp'], 2),
|
||||
];
|
||||
} else {
|
||||
$res[] = [
|
||||
'balance' => number_format($row['ye'], 2),
|
||||
'ccusname' => $row['ccusname'],
|
||||
'code' => $code,
|
||||
'digest' => $row['cDigest'],
|
||||
];
|
||||
$total_start += $row['ye'];
|
||||
}
|
||||
}
|
||||
$res[] = [
|
||||
'balance' => number_format($ye, 2),
|
||||
'ccusname' => $rows[0]['ccusname'],
|
||||
'code' => $code,
|
||||
'digest' => '期末余额'
|
||||
];
|
||||
$total_end += $ye;
|
||||
}
|
||||
|
||||
array_unshift($res, [
|
||||
'balance' => number_format($total_start, 2),
|
||||
'digest' => '总期初余额',
|
||||
'ccusname' => '总期初合计',
|
||||
]);
|
||||
$res[] = [
|
||||
'balance' => number_format($total_end, 2),
|
||||
'digest' => '总期末余额',
|
||||
'ccusname' => '总期末合计',
|
||||
];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
return response()->json($res);
|
||||
}
|
||||
}
|
||||
return $this->display();
|
||||
}
|
||||
|
||||
// 生成对账单
|
||||
public function createAction()
|
||||
{
|
||||
set_time_limit(0);
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
|
||||
$rules = [
|
||||
'start_at' => 'required|date',
|
||||
'end_at' => 'required|date',
|
||||
];
|
||||
|
||||
$v = Validator::make($gets, $rules, [], ['start_at' => '开始日期', 'end_at' => '结束日期']);
|
||||
if ($v->fails()) {
|
||||
return $this->json($v->errors()->all());
|
||||
}
|
||||
|
||||
/** 数据同步 **/
|
||||
$ch = curl_init(env('YONYOU_URL').'/yonyou.php?do=ar&start_at='.$gets['start_at'].'&end_at='.$gets['end_at']);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$res = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
$res = json_decode($res, true);
|
||||
|
||||
// 获取客户数据
|
||||
$customers = DB::table('user')
|
||||
->leftJoin('customer', 'customer.user_id', '=', 'user.id')
|
||||
->where('group_id', 2)
|
||||
->pluck('customer.id', 'user.username');
|
||||
|
||||
$rows = [];
|
||||
foreach ($res['data'] as $row) {
|
||||
if ($row['code']) {
|
||||
$rows[$row['code']][] = $row;
|
||||
/*
|
||||
if(empty($customers[$row['code']])) {
|
||||
return $this->json('订单系统不存在此客户代码: ['.$row['code'].']');
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
// 总余额
|
||||
$yes = $res['ye'];
|
||||
|
||||
foreach ($rows as $code => $row) {
|
||||
$account_id = DB::table('customer_account')->insertGetId([
|
||||
'sn' => date('Ymd').$code,
|
||||
'date' => date('Ymd'),
|
||||
'code' => $code,
|
||||
'customer_id' => (int)$customers[$code],
|
||||
'start_at' => $gets['start_at'],
|
||||
'end_at' => $gets['end_at'],
|
||||
]);
|
||||
|
||||
// 单客户余额
|
||||
$ye = $yes[$row['zcode']] > 0 ? $yes[$row['zcode']] : 0.00;
|
||||
|
||||
// 写入余额数据
|
||||
DB::table('customer_account_data')->insert([
|
||||
'code' => $code,
|
||||
'account_id' => $account_id,
|
||||
'balance' => $ye,
|
||||
'digest' => '期初余额小计',
|
||||
]);
|
||||
|
||||
foreach ($row as $i => $cell) {
|
||||
$ye = $ye + $cell['jf'] - $cell['df'];
|
||||
|
||||
$data = [
|
||||
'account_id' => $account_id,
|
||||
'sn' => date('Ymd').$i,
|
||||
'date' => $cell['date'],
|
||||
'ycode' => $cell['ycode'],
|
||||
'zcode' => $cell['zcode'],
|
||||
'code' => $cell['code'],
|
||||
'jmoney' => $cell['jf'],
|
||||
'dmoney' => $cell['df'],
|
||||
'balance' => $ye,
|
||||
'digest' => $cell['digest'],
|
||||
];
|
||||
|
||||
DB::table('customer_account_data')->insert($data);
|
||||
}
|
||||
|
||||
DB::table('customer_account_data')->insert([
|
||||
'code' => $code,
|
||||
'account_id' => $account_id,
|
||||
'balance' => $ye,
|
||||
'digest' => '期木余额小计',
|
||||
]);
|
||||
|
||||
// 更新余额
|
||||
DB::table('customer_account')->where('id', $account_id)->update([
|
||||
'balance' => $ye,
|
||||
]);
|
||||
}
|
||||
return $this->json('reload', true);
|
||||
}
|
||||
return $this->render();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php namespace Gdoo\Customer\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Customer\Models\CustomerRegion;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class RegionController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_region',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => ''],
|
||||
'trash_btn' => 0,
|
||||
]);
|
||||
|
||||
$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('lft', 'asc')
|
||||
->orderBy($header['sort'], $header['order']);
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
$model->select($header['select'])
|
||||
->addSelect(DB::raw('parent_id'));
|
||||
$rows = $model->get()->toNested('name');
|
||||
|
||||
$users = DB::table('user')->get()->keyBy('id');
|
||||
$items = Grid::dataFilters($rows, $header, function($item) use($users) {
|
||||
$owner_assist = explode(',', $item['owner_assist']);
|
||||
$_rows = [];
|
||||
foreach ($owner_assist as $user_id) {
|
||||
$_rows[] = $users[$user_id]['name'];
|
||||
}
|
||||
$item['owner_assist'] = join(',', $_rows);
|
||||
return $item;
|
||||
});
|
||||
return $this->json($items, true);
|
||||
}
|
||||
|
||||
$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'] = CustomerRegion::$tabs;
|
||||
$header['bys'] = CustomerRegion::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建客户联系人
|
||||
public function createAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
|
||||
// 客户权限
|
||||
$header['region'] = ['field' => 'customer_id'];
|
||||
$header['authorise'] = ['action' => 'index', 'field' => 'created_id'];
|
||||
$header['code'] = 'customer_region';
|
||||
$header['id'] = $id;
|
||||
|
||||
$form = Form::make($header);
|
||||
|
||||
return $this->render([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 创建客户联系人
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
public function dialogAction()
|
||||
{
|
||||
$search = search_form([], [
|
||||
['text','customer_region.name','名称'],
|
||||
['text','customer_region.id','ID'],
|
||||
]);
|
||||
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = CustomerRegion::leftJoin('user', 'user.id', '=', 'customer_region.owner_user_id')
|
||||
->orderBy('customer_region.lft', 'asc');
|
||||
|
||||
// 客户圈权限
|
||||
$region = regionCustomer();
|
||||
if ($region['authorise']) {
|
||||
$model->whereIn('customer_region.id', $region['regionIn']);
|
||||
}
|
||||
|
||||
if (isset($query['layer'])) {
|
||||
$model->where('customer_region.layer', $query['layer']);
|
||||
}
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
$rows = $model->get([
|
||||
'customer_region.*',
|
||||
'customer_region.name as text',
|
||||
'user.name as owner_user_id_name'
|
||||
]);
|
||||
$rows = array_nest($rows);
|
||||
|
||||
$json = [];
|
||||
foreach($rows as $row) {
|
||||
$json[] = $row;
|
||||
}
|
||||
return response()->json(['data' => $json]);
|
||||
}
|
||||
return $this->render([
|
||||
'search' => $search
|
||||
]);
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'customer_region', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,314 @@
|
||||
<?php namespace Gdoo\Customer\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Customer\Models\CustomerRegionTask;
|
||||
|
||||
use Gdoo\Index\Controllers\AuditController;
|
||||
|
||||
class RegionTaskController extends AuditController
|
||||
{
|
||||
public $permission = [];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_region_task',
|
||||
'referer' => 1,
|
||||
'sort' => 'customer_region_task_data.id',
|
||||
'order' => 'asc',
|
||||
'search' => [],
|
||||
]);
|
||||
|
||||
$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('customer_region as region2', 'region2.id', '=', 'region_id_customer_region.parent_id')
|
||||
->leftJoin('user as region2_user', 'region2_user.id', '=', 'region2.owner_user_id');
|
||||
|
||||
$model->orderBy($header['sort'], $header['order']);
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
if ($where['field'] == 'customer_region_task_data.region2_id') {
|
||||
$where['field'] = 'region2.id';
|
||||
}
|
||||
if ($where['field'] == 'customer_region_task_data.region2_user') {
|
||||
$where['field'] = 'region2_user.id';
|
||||
}
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
// 客户权限
|
||||
$region = regionCustomer();
|
||||
if ($region['authorise']) {
|
||||
$model->whereIn('customer_region_task_data.region_id', $region['regionIn']);
|
||||
}
|
||||
|
||||
$header['select'][] = 'region2.name as region2_id';
|
||||
$header['select'][] = 'region2_user.name as region2_user';
|
||||
|
||||
$model->select($header['select']);
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
$rows = Grid::dataFilters($rows, $header);
|
||||
return $rows->toJson();
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
|
||||
['name' => '导出', 'icon' => 'fa-mail-reply', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['right_buttons'] = [
|
||||
];
|
||||
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = CustomerRegionTask::$tabs;
|
||||
$header['bys'] = CustomerRegionTask::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建客户联系人
|
||||
public function createAction($action = 'create')
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
|
||||
$form = Form::make([
|
||||
'code' => 'customer_region_task',
|
||||
'id' => $id,
|
||||
'action' => $action,
|
||||
'select' => '
|
||||
(customer_region_task_data.month1 + customer_region_task_data.month2 + customer_region_task_data.month3) as quarter1,
|
||||
(customer_region_task_data.month4 + customer_region_task_data.month5 + customer_region_task_data.month6) as quarter2,
|
||||
(customer_region_task_data.month7 + customer_region_task_data.month8 + customer_region_task_data.month9) as quarter3,
|
||||
(customer_region_task_data.month10 + customer_region_task_data.month11 + customer_region_task_data.month12) as quarter4
|
||||
',
|
||||
]);
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 创建客户联系人
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction('edit');
|
||||
}
|
||||
|
||||
// 显示客户联系人
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
/**
|
||||
* 区域进度
|
||||
*/
|
||||
public function progressAction()
|
||||
{
|
||||
$year = date('Y');
|
||||
$search = search_form([], [[
|
||||
'form_type' => 'year',
|
||||
'field' => 'date',
|
||||
'name' => '年份',
|
||||
'value' => $year,
|
||||
],[
|
||||
'form_type' =>'dialog',
|
||||
'field' => 'region_id',
|
||||
'name' => '销售团队',
|
||||
'options' => ['url' => 'customer/region/dialog', 'query' => ['layer' => 3]]
|
||||
],
|
||||
], 'model');
|
||||
|
||||
$query = [];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
|
||||
foreach($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$query[$where['field']] = $where['search'];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($query['date'])) {
|
||||
$query['date'] = $year;
|
||||
}
|
||||
|
||||
$region = DB::table('customer_region as r')
|
||||
->where('r.layer', 3);
|
||||
|
||||
$task = DB::table('customer_region_task_data as d')
|
||||
->leftJoin('customer_region_task as m', 'm.id', '=', 'd.task_id')
|
||||
->where('m.status', 1)
|
||||
->whereRaw('m.year = ?', [$query['date']]);
|
||||
|
||||
$delivery = DB::table('stock_delivery_data as d')
|
||||
->leftJoin('product', 'product.id', '=', 'd.product_id')
|
||||
->leftJoin('stock_delivery as m', 'm.id', '=', 'd.delivery_id')
|
||||
->leftJoin('customer as c', 'c.id', '=', 'm.customer_id')
|
||||
->whereRaw('d.product_id <> 20226 and isnull(product.product_type, 0) = 1')
|
||||
->whereRaw(sql_year('m.invoice_dt').' = ?', [$query['date']])
|
||||
->selectRaw('c.region_id, '.sql_month('m.invoice_dt').' as [month], sum(isnull(d.money, 0) - isnull(d.other_money, 0)) money')
|
||||
->groupBy('c.region_id', DB::raw(sql_month('m.invoice_dt')));
|
||||
|
||||
$cancel = DB::table('stock_cancel_data as d')
|
||||
->leftJoin('product', 'product.id', '=', 'd.product_id')
|
||||
->leftJoin('stock_cancel as m', 'm.id', '=', 'd.cancel_id')
|
||||
->leftJoin('customer as c', 'c.id', '=', 'm.customer_id')
|
||||
->whereRaw('d.product_id <> 20226 and isnull(product.product_type, 0) = 1')
|
||||
->whereRaw(sql_year('m.invoice_dt').' = ?', [$query['date']])
|
||||
->selectRaw('c.region_id, '.sql_month('m.invoice_dt').' as [month], sum(isnull(d.money, 0) - isnull(d.other_money, 0)) money')
|
||||
->groupBy('c.region_id', DB::raw(sql_month('m.invoice_dt')));
|
||||
|
||||
$direct = DB::table('stock_direct_data as d')
|
||||
->leftJoin('product', 'product.id', '=', 'd.product_id')
|
||||
->leftJoin('stock_direct as m', 'm.id', '=', 'd.direct_id')
|
||||
->leftJoin('customer as c', 'c.id', '=', 'm.customer_id')
|
||||
->whereRaw('d.product_id <> 20226 and isnull(product.product_type, 0) = 1')
|
||||
->whereRaw(sql_year('m.invoice_dt').' = ?', [$query['date']])
|
||||
->selectRaw('c.region_id, '.sql_month('m.invoice_dt').' as [month], sum(isnull(d.money, 0) - isnull(d.other_money, 0)) money')
|
||||
->groupBy('c.region_id', DB::raw(sql_month('m.invoice_dt')));
|
||||
|
||||
if ($query['region_id']) {
|
||||
$region_ids = explode(',', $query['region_id']);
|
||||
$region->whereIn('r.id', $region_ids);
|
||||
$delivery->whereIn('c.region_id', $region_ids);
|
||||
$cancel->whereIn('c.region_id', $region_ids);
|
||||
$direct->whereIn('c.region_id', $region_ids);
|
||||
$task->whereIn('d.region_id', $region_ids);
|
||||
}
|
||||
|
||||
// 客户圈权限
|
||||
$_region = regionCustomer();
|
||||
if ($_region['authorise']) {
|
||||
$region->whereIn('r.id', $_region['regionIn']);
|
||||
$delivery->whereIn('c.region_id', $_region['regionIn']);
|
||||
$cancel->whereIn('c.region_id', $_region['regionIn']);
|
||||
$direct->whereIn('c.region_id', $_region['regionIn']);
|
||||
$task->whereIn('d.region_id', $_region['regionIn']);
|
||||
}
|
||||
|
||||
$_rows = $cancel->unionAll($delivery)->unionAll($direct)->get();
|
||||
$_tasks = $task->get()->toArray();
|
||||
|
||||
$rows = [];
|
||||
foreach($_rows as $row) {
|
||||
$rows[$row['region_id']]['month'.$row['month']] += $row['money'];
|
||||
}
|
||||
|
||||
$tasks = [];
|
||||
foreach($_tasks as $task) {
|
||||
$tasks[$task['region_id']] = $task;
|
||||
}
|
||||
|
||||
$regions = $region->get(['r.id as region_id', 'r.name as region_name'])->toArray();
|
||||
foreach($regions as &$region) {
|
||||
|
||||
$quarters = [];
|
||||
|
||||
$total_money = 0;
|
||||
$total_task = 0;
|
||||
|
||||
$task = $tasks[$region['region_id']];
|
||||
|
||||
// 计算月进度
|
||||
for ($i=1; $i <= 12; $i++) {
|
||||
$month = $task['month'.$i];
|
||||
|
||||
$region['month'.$i] = $month;
|
||||
|
||||
$money = $rows[$region['region_id']]['month'.$i] / 10000;
|
||||
$money = sprintf('%.4f', $money);
|
||||
|
||||
$total_money += $money;
|
||||
$total_task += $month;
|
||||
|
||||
$quarter = ceil($i / 3);
|
||||
$quarters[$quarter]['money'] += $money;
|
||||
$quarters[$quarter]['task'] += $month;
|
||||
|
||||
$region['month_'.$i.'_money'] = $money;
|
||||
|
||||
if ($month > 0) {
|
||||
$region['month_'.$i.'_rate'] = sprintf('%.2f', ($money / $month) * 100);
|
||||
} else {
|
||||
$region['month_'.$i.'_rate'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ($total_money > 0 && $total_task > 0) {
|
||||
$region['total_rate'] = sprintf('%.2f', ($total_money / $total_task) * 100);
|
||||
} else {
|
||||
$region['total_rate'] = 0;
|
||||
}
|
||||
|
||||
$region['total_task'] = $total_task;
|
||||
$region['total_money'] = $total_money;
|
||||
|
||||
// 计算季度进度
|
||||
for ($i=1; $i <= 4; $i++) {
|
||||
$quarter = $quarters[$i];
|
||||
$region['quarter_'.$i] = $quarter['task'];
|
||||
$region['quarter_'.$i.'_money'] = sprintf('%.4f', $quarter['money']);
|
||||
if ($quarter['money'] > 0 && $quarter['task'] > 0) {
|
||||
$region['quarter_'.$i.'_rate'] = sprintf('%.2f', ($quarter['money'] / $quarter['task']) * 100);
|
||||
} else {
|
||||
$region['quarter_'.$i.'_rate'] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $this->json($regions, true);
|
||||
}
|
||||
|
||||
$header = [
|
||||
'table' => 'region_task',
|
||||
'master_table' => 'region_task',
|
||||
'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,
|
||||
]);
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'customer_region_task', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,378 @@
|
||||
<?php namespace Gdoo\Customer\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Customer\Models\CustomerTask;
|
||||
|
||||
use Gdoo\Index\Controllers\AuditController;
|
||||
|
||||
class TaskController extends AuditController
|
||||
{
|
||||
public $permission = ['importExcel'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_task',
|
||||
'referer' => 1,
|
||||
'sort' => 'id',
|
||||
'order' => 'desc',
|
||||
'search' => [],
|
||||
]);
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
// 客户权限
|
||||
$region = regionCustomer('customer_id_customer');
|
||||
if ($region['authorise']) {
|
||||
foreach ($region['whereIn'] as $key => $where) {
|
||||
$model->whereIn($key, $where);
|
||||
}
|
||||
}
|
||||
|
||||
$model->select($header['select']);
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
$rows = Grid::dataFilters($rows, $header);
|
||||
return $rows->toJson();
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
|
||||
['name' => '导出', 'icon' => 'fa-mail-reply', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['right_buttons'] = [
|
||||
];
|
||||
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = CustomerTask::$tabs;
|
||||
$header['bys'] = CustomerTask::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建客户联系人
|
||||
public function createAction($action = 'create')
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make([
|
||||
'code' => 'customer_task',
|
||||
'id' => $id,
|
||||
'action' => $action,
|
||||
'select' => '
|
||||
(customer_task_data.month1 + customer_task_data.month2 + customer_task_data.month3) as quarter1,
|
||||
(customer_task_data.month4 + customer_task_data.month5 + customer_task_data.month6) as quarter2,
|
||||
(customer_task_data.month7 + customer_task_data.month8 + customer_task_data.month9) as quarter3,
|
||||
(customer_task_data.month10 + customer_task_data.month11 + customer_task_data.month12) as quarter4
|
||||
',
|
||||
]);
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 创建客户联系人
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction('edit');
|
||||
}
|
||||
|
||||
// 显示客户联系人
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
/**
|
||||
* 区域进度
|
||||
*/
|
||||
public function progressAction()
|
||||
{
|
||||
$year = date('Y');
|
||||
$search = search_form([], [[
|
||||
'form_type' => 'year',
|
||||
'field' => 'date',
|
||||
'name' => '年份',
|
||||
'value' => $year,
|
||||
],[
|
||||
'form_type' =>'dialog',
|
||||
'field' => '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');
|
||||
|
||||
$query = [];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
|
||||
foreach($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$query[$where['field']] = $where['search'];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($query['date'])) {
|
||||
$query['date'] = $year;
|
||||
}
|
||||
|
||||
$customer = DB::table('customer')
|
||||
->leftJoin('customer_region as r', 'r.id', '=', 'customer.region_id');
|
||||
|
||||
$task = DB::table('customer_task_data as d')
|
||||
->leftJoin('customer_task as m', 'm.id', '=', 'd.task_id')
|
||||
->leftJoin('customer', 'customer.id', '=', 'd.customer_id')
|
||||
->where('m.status', 1)
|
||||
->whereRaw('m.year = ?', [$query['date']]);
|
||||
|
||||
$delivery = DB::table('stock_delivery_data as d')
|
||||
->leftJoin('product', 'product.id', '=', 'd.product_id')
|
||||
->leftJoin('stock_delivery as m', 'm.id', '=', 'd.delivery_id')
|
||||
->leftJoin('customer', 'customer.id', '=', 'm.customer_id')
|
||||
->whereRaw('d.product_id <> 20226 and isnull(product.product_type, 0) = 1')
|
||||
->whereRaw(sql_year('m.invoice_dt').' = ?', [$query['date']])
|
||||
->selectRaw('m.customer_id, count(DISTINCT m.id) as [count], '.sql_month('m.invoice_dt').' as [month], sum(isnull(d.money, 0) - isnull(d.other_money, 0)) money')
|
||||
->groupBy('m.customer_id', DB::raw(sql_month('m.invoice_dt')));
|
||||
|
||||
$cancel = DB::table('stock_cancel_data as d')
|
||||
->leftJoin('product', 'product.id', '=', 'd.product_id')
|
||||
->leftJoin('stock_cancel as m', 'm.id', '=', 'd.cancel_id')
|
||||
->leftJoin('customer', 'customer.id', '=', 'm.customer_id')
|
||||
->whereRaw('d.product_id <> 20226 and isnull(product.product_type, 0) = 1')
|
||||
->whereRaw(sql_year('m.invoice_dt').' = ?', [$query['date']])
|
||||
->selectRaw('m.customer_id, 0 as [count], '.sql_month('m.invoice_dt').' as [month], sum(isnull(d.money, 0) - isnull(d.other_money, 0)) money')
|
||||
->groupBy('m.customer_id', DB::raw(sql_month('m.invoice_dt')));
|
||||
|
||||
$direct = DB::table('stock_direct_data as d')
|
||||
->leftJoin('product', 'product.id', '=', 'd.product_id')
|
||||
->leftJoin('stock_direct as m', 'm.id', '=', 'd.direct_id')
|
||||
->leftJoin('customer', 'customer.id', '=', 'm.customer_id')
|
||||
->whereRaw('d.product_id <> 20226 and isnull(product.product_type, 0) = 1')
|
||||
->whereRaw(sql_year('m.invoice_dt').' = ?', [$query['date']])
|
||||
->selectRaw('m.customer_id, count(DISTINCT m.id) as [count], '.sql_month('m.invoice_dt').' as [month], sum(isnull(d.money, 0) - isnull(d.other_money, 0)) money')
|
||||
->groupBy('m.customer_id', DB::raw(sql_month('m.invoice_dt')));
|
||||
|
||||
if ($query['region_id']) {
|
||||
$region_ids = explode(',', $query['region_id']);
|
||||
$customer->whereIn('customer.region_id', $region_ids);
|
||||
$task->whereIn('customer.region_id', $region_ids);
|
||||
$delivery->whereIn('customer.region_id', $region_ids);
|
||||
$cancel->whereIn('customer.region_id', $region_ids);
|
||||
$direct->whereIn('customer.region_id', $region_ids);
|
||||
}
|
||||
|
||||
if ($query['customer_id']) {
|
||||
$customer_ids = explode(',', $query['customer_id']);
|
||||
$customer->whereIn('customer.id', $customer_ids);
|
||||
$task->whereIn('customer.id', $customer_ids);
|
||||
$delivery->whereIn('customer.id', $customer_ids);
|
||||
$cancel->whereIn('customer.id', $customer_ids);
|
||||
$direct->whereIn('customer.id', $customer_ids);
|
||||
}
|
||||
|
||||
// 客户圈权限
|
||||
$_region = regionCustomer();
|
||||
if ($_region['authorise']) {
|
||||
foreach($_region['whereIn'] as $key => $whereIn) {
|
||||
$customer->whereIn($key, $whereIn);
|
||||
$task->whereIn($key, $whereIn);
|
||||
$delivery->whereIn($key, $whereIn);
|
||||
$cancel->whereIn($key, $whereIn);
|
||||
$direct->whereIn($key, $whereIn);
|
||||
}
|
||||
}
|
||||
$_rows = $cancel->unionAll($delivery)->unionAll($direct)->get();
|
||||
|
||||
$_tasks = $task->get()->toArray();
|
||||
|
||||
$rows = [];
|
||||
foreach($_rows as $row) {
|
||||
$rows[$row['customer_id']]['month'.$row['month']] += $row['money'];
|
||||
$rows[$row['customer_id']]['count'.$row['month']] += $row['count'];
|
||||
}
|
||||
|
||||
$tasks = [];
|
||||
foreach($_tasks as $task) {
|
||||
$tasks[$task['customer_id']] = $task;
|
||||
}
|
||||
|
||||
$customers = $customer->get([
|
||||
'r.name as region_name',
|
||||
'customer.id as customer_id',
|
||||
'customer.name as customer_name',
|
||||
'customer.code as customer_code',
|
||||
'customer.status'
|
||||
])->toArray();
|
||||
|
||||
foreach($customers as &$customer) {
|
||||
|
||||
$quarters = [];
|
||||
|
||||
$task = $tasks[$customer['customer_id']];
|
||||
|
||||
$total_money = 0;
|
||||
$total_task = 0;
|
||||
$total_count = 0;
|
||||
|
||||
// 计算月进度
|
||||
for ($i=1; $i <= 12; $i++) {
|
||||
$month = $task['month'.$i];
|
||||
|
||||
$customer['month'.$i] = $month;
|
||||
|
||||
$money = $rows[$customer['customer_id']]['month'.$i] / 10000;
|
||||
$money = sprintf('%.4f', $money);
|
||||
|
||||
$quarter = ceil($i / 3);
|
||||
$quarters[$quarter]['money'] += $money;
|
||||
$quarters[$quarter]['task'] += $month;
|
||||
|
||||
$total_money += $money;
|
||||
$total_task += $month;
|
||||
|
||||
// 总订单数量
|
||||
$count = $rows[$customer['customer_id']]['count'.$i];
|
||||
$total_count += $count;
|
||||
|
||||
$customer['month_'.$i.'_money'] = $money;
|
||||
if ($money > 0 && $month > 0) {
|
||||
$customer['month_'.$i.'_rate'] = sprintf('%.2f', ($money / $month) * 100);
|
||||
} else {
|
||||
$customer['month_'.$i.'_rate'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ($total_money > 0 && $total_task > 0) {
|
||||
$customer['total_rate'] = sprintf('%.2f', ($total_money / $total_task) * 100);
|
||||
} else {
|
||||
$customer['total_rate'] = 0;
|
||||
}
|
||||
$customer['total_task'] = $total_task;
|
||||
$customer['total_money'] = $total_money;
|
||||
$customer['total_count'] = $total_count;
|
||||
|
||||
// 计算季度进度
|
||||
for ($i=1; $i <= 4; $i++) {
|
||||
$quarter = $quarters[$i];
|
||||
$customer['quarter_'.$i] = $quarter['task'];
|
||||
$customer['quarter_'.$i.'_money'] = sprintf('%.4f', $quarter['money']);
|
||||
if ($quarter['money'] > 0 && $quarter['task'] > 0) {
|
||||
$customer['quarter_'.$i.'_rate'] = sprintf('%.2f', ($quarter['money'] / $quarter['task']) * 100);
|
||||
} else {
|
||||
$customer['quarter_'.$i.'_rate'] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return $this->json($customers, true);
|
||||
}
|
||||
|
||||
$header = [
|
||||
'table' => 'customer_task',
|
||||
'master_table' => 'customer_task',
|
||||
'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,
|
||||
]);
|
||||
}
|
||||
|
||||
public function importExcelAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$file = Request::file('file');
|
||||
if ($file->isValid()) {
|
||||
$customers = DB::table('customer')->get()->keyBy('code');
|
||||
/*
|
||||
[0] => 合同编号
|
||||
[1] => 客户编码
|
||||
[2] => 数量
|
||||
[3] => 单价
|
||||
[4] => 备注
|
||||
*/
|
||||
$rows = readExcel($file->getPathName(), $file->getClientOriginalExtension());
|
||||
$items = [];
|
||||
foreach($rows as $i => $row) {
|
||||
if ($i > 1) {
|
||||
$customer = $customers[$row[1]];
|
||||
if (empty($customer)) {
|
||||
return $this->json('客户编码'.$row[1].'客户档案不存在。');
|
||||
}
|
||||
$item = [
|
||||
'code' => $row[0],
|
||||
'customer_id' => $customer['id'],
|
||||
'customer_id_name' => $customer['name'],
|
||||
'month1' => $row[4],
|
||||
'month2' => $row[5],
|
||||
'month3' => $row[6],
|
||||
'month4' => $row[7],
|
||||
'month5' => $row[8],
|
||||
'month6' => $row[9],
|
||||
'month7' => $row[10],
|
||||
'month8' => $row[11],
|
||||
'month9' => $row[12],
|
||||
'month10' => $row[13],
|
||||
'month11' => $row[14],
|
||||
'month12' => $row[15],
|
||||
];
|
||||
$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_task', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
<?php namespace Gdoo\Customer\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Customer\Models\CustomerTax;
|
||||
|
||||
use Gdoo\Index\Controllers\AuditController;
|
||||
|
||||
class TaxController extends AuditController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_tax',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => ''],
|
||||
'sort' => 'customer_tax.customer_id',
|
||||
'order' => 'desc',
|
||||
'trash_btn' => 0,
|
||||
]);
|
||||
|
||||
$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($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']) {
|
||||
$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['left_buttons'] = [
|
||||
['name' => '批量编辑', 'color' => 'default', 'icon' => 'fa-pencil-square-o', 'action' => 'batchEdit', 'display' => $this->access['batchEdit']],
|
||||
];
|
||||
|
||||
$header['cols'] = $cols;
|
||||
$header['tabs'] = CustomerTax::$tabs;
|
||||
$header['bys'] = CustomerTax::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建客户联系人
|
||||
public function createAction($action = 'edit')
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'customer_tax', 'id' => $id, 'action' => $action]);
|
||||
return $this->display([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 创建客户联系人
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction('edit');
|
||||
}
|
||||
|
||||
// 创建客户联系人
|
||||
public function showAction()
|
||||
{
|
||||
return $this->createAction('show');
|
||||
}
|
||||
|
||||
public function dialogAction()
|
||||
{
|
||||
$search = search_form(
|
||||
['advanced' => ''], [
|
||||
['form_type' => 'text', 'name' => '开票名称', 'field' => 'customer_tax.name', 'options' => []],
|
||||
['form_type' => 'text', 'name' => '开票编码', 'field' => 'customer_tax.code', 'options' => []],
|
||||
['form_type' => 'text', 'name' => '客户名称', 'field' => 'customer.name', 'options' => []],
|
||||
['form_type' => 'text', 'name' => '客户编码', 'field' => 'customer.code', 'options' => []]
|
||||
], 'model');
|
||||
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = CustomerTax::leftJoin('customer', 'customer_tax.customer_id', '=', 'customer.id');
|
||||
|
||||
if (isset($query['customer_id'])) {
|
||||
$model->where('customer_id', $query['customer_id']);
|
||||
}
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
|
||||
// 客户权限
|
||||
$region = regionCustomer();
|
||||
if ($region['authorise']) {
|
||||
foreach ($region['whereIn'] as $key => $where) {
|
||||
$model->whereIn($key, $where);
|
||||
}
|
||||
}
|
||||
|
||||
$model->select(['customer_tax.*','customer.code as customer_code', 'customer.name as customer_name']);
|
||||
$rows = $model->paginate($query['limit']);
|
||||
return response()->json($rows);
|
||||
}
|
||||
return $this->render([
|
||||
'search' => $search,
|
||||
'query' => $query,
|
||||
]);
|
||||
}
|
||||
|
||||
// 批量编辑
|
||||
public function batchEditAction()
|
||||
{
|
||||
$gets = Request::all();
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = explode(',', $gets['ids']);
|
||||
DB::table('customer_tax')->whereIn('id', $ids)->update([
|
||||
$gets['field'] => $gets['search_0'],
|
||||
]);
|
||||
return $this->json('修改完成。', true);
|
||||
}
|
||||
$header = Grid::batchEdit([
|
||||
'code' => 'customer_tax',
|
||||
'columns' => ['class_id', 'department_id', 'status'],
|
||||
]);
|
||||
return view('batchEdit', [
|
||||
'gets' => $gets,
|
||||
'header' => $header
|
||||
]);
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$ids = Request::get('id');
|
||||
return Form::remove(['code' => 'customer_tax', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php namespace Gdoo\Customer\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Session;
|
||||
use Request;
|
||||
|
||||
use Gdoo\User\Models\UserAsset;
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Customer\Models\Customer;
|
||||
use Gdoo\Customer\Models\Contact;
|
||||
|
||||
use Gdoo\User\Controllers\TokenController as Controller;
|
||||
use Gdoo\User\Services\UserAssetService;
|
||||
|
||||
class TokenController extends Controller
|
||||
{
|
||||
public function salesmanAction()
|
||||
{
|
||||
if (Request::isJson()) {
|
||||
$gets = json_decode(Request::getContent(), true);
|
||||
} else {
|
||||
$gets = Request::all();
|
||||
}
|
||||
|
||||
$username = trim($gets['username']);
|
||||
$password = trim($gets['password']);
|
||||
|
||||
if ($username == '') {
|
||||
return response()->json(['message'=>'客户代码不能为空。']);
|
||||
}
|
||||
|
||||
if ($password == '') {
|
||||
return response()->json(['message'=>'联系人手机不能为空。']);
|
||||
}
|
||||
|
||||
// 获取登录用户
|
||||
$user = User::where('username', $username)
|
||||
->where('group_id', 2)
|
||||
->where('status', 1)
|
||||
->first();
|
||||
|
||||
if ($user) {
|
||||
// 获取客户档案
|
||||
$customer = Customer::where('user_id', $user->id)->first();
|
||||
|
||||
// 登录的客户业务员信息
|
||||
$contact = Contact::leftJoin('user', 'user.id', '=', 'customer_contact.user_id')
|
||||
->where('customer_contact.customer_id', $customer->id)
|
||||
->where('user.phone', $password)
|
||||
->first(['user.*', 'customer_contact.id as contact_id']);
|
||||
|
||||
if ($contact) {
|
||||
$assets = UserAssetService::getRoleAssets($user->role_id);
|
||||
return response()->json([
|
||||
'token' => $this->createToken($user->id),
|
||||
'contact_id' => $contact->contact_id,
|
||||
'access' => $assets,
|
||||
]);
|
||||
} else {
|
||||
return response()->json(['message'=>'客户代码或联系人手机错误。']);
|
||||
}
|
||||
}
|
||||
return response()->json(['message'=>'客户代码或联系人手机错误。']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php namespace Gdoo\Customer\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Customer\Models\CustomerType;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class TypeController extends DefaultController
|
||||
{
|
||||
public $permission = ['dialog'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$header = Grid::header([
|
||||
'code' => 'customer_type',
|
||||
'referer' => 1,
|
||||
'search' => ['by' => ''],
|
||||
'trash_btn' => 0,
|
||||
]);
|
||||
|
||||
$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($header['sort'], $header['order'])
|
||||
->orderBy('id', 'desc');
|
||||
|
||||
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'] = CustomerType::$tabs;
|
||||
$header['bys'] = CustomerType::$bys;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建客户联系人
|
||||
public function createAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$form = Form::make(['code' => 'customer_type', 'id' => $id]);
|
||||
return $this->render([
|
||||
'form' => $form,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
// 创建客户联系人
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
public function dialogAction()
|
||||
{
|
||||
$search = search_form([], [
|
||||
['text','customer_type.name','名称'],
|
||||
['text','customer_type.id','ID'],
|
||||
]);
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = CustomerType::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_type', 'ids' => $ids]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php namespace Gdoo\Customer\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class WidgetController extends DefaultController
|
||||
{
|
||||
public $permission = ['birthday'];
|
||||
|
||||
// 生日提醒
|
||||
public function birthdayAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
|
||||
$model = DB::table('customer');
|
||||
$region = regionCustomer();
|
||||
if ($region['authorise']) {
|
||||
foreach ($region['whereIn'] as $key => $where) {
|
||||
$model->whereIn($key, $where);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->dbType == 'sqlsrv') {
|
||||
$model->whereRaw('
|
||||
(datediff(dd, getdate(), dateadd(year, datediff(year, head_birthday, getdate()), head_birthday)) between 0 and 7)
|
||||
OR
|
||||
(datediff(dd, getdate(), dateadd(year, datediff(year, head_birthday, getdate())+1, head_birthday)) between 0 and 7)')
|
||||
->selectRaw('id, code, name, head_name, head_phone, head_birthday')
|
||||
->get();
|
||||
} else if($this->dbType == 'pgsql') {
|
||||
$model->whereRaw("
|
||||
(concat(date_part('year', current_date), '-', date_part('month', head_birthday), '-', date_part('day', head_birthday))::date - current_date between 0 and 7)
|
||||
OR
|
||||
(concat(date_part('year', current_date) + 1, '-', date_part('month', head_birthday), '-', date_part('day', head_birthday))::date - current_date between 0 and 7)")
|
||||
->selectRaw("id, code, name, head_name, head_phone, concat(date_part('year', current_date), '-', date_part('month', head_birthday), '-', date_part('day', head_birthday))::date as head_birthday");
|
||||
}
|
||||
|
||||
else if($this->dbType == 'mysql') {
|
||||
$model->whereRaw("
|
||||
(concat(year(now()), DATE_FORMAT(birthday,'-%m-%d')) BETWEEN DATE_FORMAT(now(),'%Y-%m-%d') AND DATE_FORMAT(DATE_ADD(now(), interval 10 day),'%Y-%m-%d'))
|
||||
OR
|
||||
(concat(year(now()) + 1, DATE_FORMAT(birthday,'-%m-%d')) BETWEEN DATE_FORMAT(now(),'%Y-%m-%d') AND DATE_FORMAT(DATE_ADD(now(), interval 10 day),'%Y-%m-%d'))")
|
||||
->selectRaw("id, code, name, head_name, head_phone, concat(year(now()), DATE_FORMAT(birthday,'-%m-%d')) as head_birthday");
|
||||
}
|
||||
|
||||
$rows = $model->get();
|
||||
|
||||
$json['total'] = sizeof($rows);
|
||||
$json['data'] = $rows;
|
||||
return response()->json($json);
|
||||
}
|
||||
return $this->render();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user