'/index.php/Retail/Supplier/supplierSet',
'delete' => '/index.php/Retail/Supplier/delete',
'batch' => '/index.php/Retail/Supplier/batch',
'exportOperation' => '/index.php/Retail/Supplier/exportList'
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
public function supplierList()
{
$map['merchantid'] = $this->merchant_id;
$map['status'] = 1;
$key = I("post.text");
if (!empty($key)) {
$map['code|supplier_name'] = array('like', '%' . $key . '%');
}
$count = M("retail_supplier")->where($map)->count();
$info = M("retail_supplier")->where($map)->page($_POST['page'], $_POST['limit'])->order("addtime asc")->select();
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'] = intval($count);
$res['data'] = $info ? $info : array();
$this->ajaxReturn($res);
}
/*
* 导出供货商列表
* @param $user 商户信息
* @param $key 编码或者供货商名称
*/
public function exportList()
{
$map['merchantid'] = $this->merchant_id;
$map['status'] = 1;
$key = I("get.text");
if (!empty($key)) {
$map['code|supplier_name'] = array('like', '%' . $key . '%');
}
$info = M("retail_supplier")->where($map)->order("addtime asc")->select();
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()
{
$map['merchantid'] = $this->merchant_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;
$find = M("retail_supplier")->where($map)->find();
if (empty($find)) {
$data['merchantid'] = $this->merchant_id;
$data['addtime'] = time();
$create = M("retail_supplier")->where(array('id' => $data['id']))->save($data);
if ($create) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台: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'];
$find = M("retail_supplier")->where($map)->find();
if (empty($find)) {
$data['merchantid'] = $this->merchant_id;
$data['addtime'] = time();
$create = M("retail_supplier")->add($data);
if ($create) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台: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);
} else {
//编辑
$id = I('get.id');
$info = M("retail_supplier")->where(array('id' => $id))->find();
$bank = M("bank")->select();
$this->assign('info', $info);
$this->assign('bank', json_encode($bank));
$this->display();
}
}
/**
* 删除
*/
public function delete()
{
if ($_POST) {
$id = $_POST['id'];
if (!$id) {
$res['status'] = 0;
$res['msg'] = '参数有误,请刷新重试';
} else {
$data['status'] = 2;
$change = M("retail_supplier")->where(array('id' => $id))->save($data);
if ($change) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台: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 batch()
{
$SSupplier = D("SSupplier");
$data = I("post.");
$store_id = $data['store_id'];
$supplier = $data['Selection'];
if (!$store_id || !$supplier || count($store_id) == 0 || count($supplier) == 0) {
$res['status'] = 0;
$res['msg'] = '请确认门店与供货商';
$this->ajaxReturn($res);
}
$time = time();
foreach ($store_id as $val) {
foreach ($supplier as $v) {
$id = $SSupplier->getFindField(array('mer_supplier_id' => $v['id'], 'status' => 1, 'store_id' => $val), "id");
$content = $v;
$content['add_time'] = $time;
$content['status'] = 1;
$content['store_id'] = $val;
$content['merchant_id'] = $v['merchantid'];
$content['mer_supplier_id'] = $v['id'];
unset($content['id']);
unset($content['merchantid']);
unset($content['advance_money']);
if ($id) {
unset($content['add_time']);
unset($content['status']);
unset($content['mer_supplier_id']);
$SSupplier->updateData(array('id' => $id), $content);
} else {
$SSupplier->addData($content);
}
}
}
$res['status'] = 1;
$res['msg'] = '操作成功';
$this->ajaxReturn($res);
}
/**
* 获取商户用来选择的供货商列表
*/
public function getUsedSupplierList(){
$SupplierApi = new Supplier();
$data = $SupplierApi->getmerUsedSupplierList($this->merchant_id);
$this->ajaxReturn(array(
'status' => 1,
'msg' => $data ? '获取成功' : '暂无数据',
'data' => $data,
));
}
//+=======================================================================
//- 省市区三级联动
//+=======================================================================
//省
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 = '';
foreach ($cityinfo as $key => $value) {
$opt .= "";
}
echo json_encode($opt);
}
public function Area()
{
$district = M('citys');
$cityid['parentid'] = $_POST['city_id'];
$districtinfo = $district->where($cityid)->select();
$opt = '';
foreach ($districtinfo as $key => $value) {
$opt .= "";
}
echo json_encode($opt);
}
}