文件
mashangyoujiu/Application/Retail/Controller/SSupplierController.class.php

320 行
12 KiB
PHP
可执行文件

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace Retail\Controller;
use Common\User\Supplier;
//[1.5.66]
/**
* 门店供应商
* Class SSupplierController
* @package Retail\Controller
*/
class SSupplierController extends BaseController
{
public function index()
{
$arr = array(
'add' => '/index.php/Retail/SSupplier/supplierSet',
'deleteOperation' => '/index.php/Retail/SSupplier/delete'
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
public function supplierList()
{
$page = I("post.page");
$limit = I("post.limit");
$key = I("post.text");
$where['merchant_id'] = $this->merchant_id;
$where['status'] = 1;
$where['store_id'] = $this->store_id;
if (!empty($key)) {
$where['code|supplier_name'] = array('like', '%' . $key . '%');
}
$count = D('SSupplier')->getCount($where);
$info = D('SSupplier')->getSelect($where, $page, $limit);
if (!empty($info)) {
foreach ($info as $key => $value) {
$info[$key]['index'] = $key + 1;
$info[$key]['place'] = $value['province'] . $value['city'] . $value['arae'] . $value['address'];
}
}
$res['status'] = 1;
$res['msg'] = '获取成功';
$res['count'] = $count;
$res['data'] = $info;
$this->ajaxReturn($res);
}
/*
* 导出供货商列表
* @param $user 商户信息
* @param $key 编码或者供货商名称
*/
public function exportList()
{
$map['merchant_id'] = $this->merchant_id;
$map['status'] = 1;
$map['store_id'] = $this->store_id;
$key = I("get.text");
if (!empty($key)) {
$map['code|supplier_name'] = array('like', '%' . $key . '%');
}
$info = D('SSupplier')->getSelect($map);
if (!empty($info)) {
foreach ($info as $key => $value) {
$info[$key]['index'] = $key + 1;
$info[$key]['place'] = $value['province'] . $value['city'] . $value['arae'] . $value['address'];
}
}
$filed_name = '供货商列表';
$arr = array(
array('index', '序号'),
array('code', '编码'),
array('supplier_name', '供货商名称'),
array('linkman', '联系人'),
array('phone', '联系方式'),
array('place', '地址信息'),
array('operation_mode', '经营方式'),
array('settlement_method', '结算方式'),
array('settlement_days', '结算天数'),
array('bank_card', '银行卡号')
);
$str = "导出时间:" . date('Y-m-d H:i:s', time());
$this->getExcel($filed_name, $arr, $info, $str);
}
/*导出公共方法
* @param $expTitle 文件名称
* @param $expCellName 二维数组字段名称
* @param $expTableData 导出的数组
*
*/
private function getExcel($expTitle, $expCellName, $expTableData, $str = "")
{
$xlsTitle = iconv('utf-8', 'gb2312', $expTitle);//文件名称
$fileName = $expTitle . date('_YmdHis');//or $xlsTitle 文件名称可根据自己情况设定
$cellNum = count($expCellName);
$dataNum = count($expTableData);
$common = $str;
vendor("PHPExcel.PHPExcel");
$objPHPExcel = new \PHPExcel();
$cellName = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ');
$objPHPExcel->getActiveSheet(0)->mergeCells('A1:' . $cellName[$cellNum - 1] . '1');//合并单元格
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', $common);
// $objPHPExcel->setActiveSheetIndex(1)->setCellValue('A1', $str);
for ($i = 0; $i < $cellNum; $i++) {
$objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i] . '2', $expCellName[$i][1]);
}
for ($i = 0; $i < $dataNum; $i++) {
for ($j = 0; $j < $cellNum; $j++) {
$objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j] . ($i + 3), ' ' . $expTableData[$i][$expCellName[$j][0]]);
}
}
foreach ($cellName as $value) {
$objPHPExcel->getActiveSheet()->getColumnDimension($value)->setWidth(20);
}
header('pragma:public');
header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $xlsTitle . '.xls"');
header("Content-Disposition:attachment;filename=$fileName.xls");//attachment新窗口打印inline本窗口打印
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit();
}
/**
* 编辑
*/
public function supplierSet()
{
$arr = array(
'save_btn' => '/index.php/Retail/SSupplier/Submission',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$id = I('get.id');
if (!empty($id)) {
$rows = D('SSupplier')->getFind(array('id' => $id));
$this->assign('info', $rows);
}
$bank = M("bank")->select();
$this->assign('bank', $bank ? json_encode($bank) : array());
$this->display();
}
//提交
public function Submission()
{
$store_id = $this->store_id;
if ($_POST) {
$data = $_POST;
$data['province'] = M('citys')->where(array('cityid' => $data['provinceid']))->getField('city_name');
$data['city'] = M('citys')->where(array('cityid' => $data['cityid']))->getField('city_name');
$data['area'] = M('citys')->where(array('cityid' => $data['areaid']))->getField('city_name');
if ($data['id']) {
$map['code'] = $data['code'];
$map['id'] = array('neq', $data['id']);
$map['status'] = 1;
$map['store_id'] = $store_id;
$find = D('SSupplier')->getFind($map);
if (empty($find)) {
$data['merchant_id'] = $this->merchant_id;
$data['add_time'] = time();
$data['store_id'] = $store_id;
$create = D('SSupplier')->updateData(array('id' => $data['id']), $data);
if ($create['status'] == 1) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '供货商管理-供货商添加';//操作行为描述
action_log($source, $type, $request_data, $desc);
$res['status'] = 1;
$res['msg'] = '修改成功';
} else {
$res['status'] = 0;
$res['msg'] = '修改失败';
}
} else {
$res['status'] = 0;
$res['msg'] = '编码已存在,请更换编码';
}
} else {
//编码不能重复
$map['code'] = $data['code'];
$map['store_id'] = $store_id;
$map['status'] = 1;
$find = D('SSupplier')->getFind($map);
if (empty($find)) {
$data['merchant_id'] = $this->merchant_id;
$data['add_time'] = time();
$data['store_id'] = $store_id;
unset($data['id']);
$create = D('SSupplier')->addData($data);
if ($create['status'] == 1) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '供货商管理-编辑';//操作行为描述
action_log($source, $type, $request_data, $desc);
$res['status'] = 1;
$res['msg'] = '添加成功';
} else {
$res['status'] = 0;
$res['msg'] = '添加失败';
}
} else {
$res['status'] = 0;
$res['msg'] = '编码已存在,请更换编码';
}
}
$this->ajaxReturn($res);
}
}
/**
* 删除
*/
public function delete()
{
if ($_POST) {
$id = I('post.id');
if (!$id) {
$res['status'] = 0;
$res['msg'] = '参数有误,请刷新重试';
} else {
$data['status'] = 2;
$change = D('SSupplier')->updateData(array('id' => $id, 'store_id' => $this->store_id), $data);
if ($change) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '供应商管理-删除';//操作行为描述
action_log($source, $type, $request_data, $desc);
$res['status'] = 1;
$res['msg'] = '删除成功';
} else {
$res['status'] = 0;
$res['msg'] = '删除失败';
}
}
$this->ajaxReturn($res);
}
}
//+=======================================================================
//- 省市区三级联动
//+=======================================================================
//省
public function Province()
{
$province = M('citys');
$prov = $province->where(array('parentid' => 0))->select();
return $prov;
}
//市
public function City()
{
$city = M('citys');
$provinceid['parentid'] = $_POST['pro_id'];
$cityinfo = $city->where($provinceid)->select();
$opt = '<option>--请选择市区--</option>';
foreach ($cityinfo as $key => $value) {
$opt .= "<option value='{$value['cityid']}'>{$value['city_name']}</option>";
}
echo json_encode($opt);
}
public function Area()
{
$district = M('citys');
$cityid['parentid'] = $_POST['city_id'];
$districtinfo = $district->where($cityid)->select();
$opt = '<option>--请选择市县--</option>';
foreach ($districtinfo as $key => $value) {
$opt .= "<option value='{$value['cityid']}'>{$value['city_name']}</option>";
}
echo json_encode($opt);
}
/**
* 获取用来使用的供货商列表
*/
public function getUsedSupplierList()
{
$SupplierApi = new Supplier();
$data = $SupplierApi->getStoreUsedSupplierList($this->store_id);
$this->ajaxReturn(array(
'status' => 1,
'msg' => $data ? '获取成功' : '暂无数据',
'data' => $data,
));
}
}