212 行
7.4 KiB
PHP
可执行文件
212 行
7.4 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Retail\Controller;
|
||
|
||
use Common\Business\Warehouse;
|
||
use Think\Controller;
|
||
|
||
//[1.5.70]
|
||
class SPurchaseWarehouseController extends BaseController
|
||
{
|
||
/*
|
||
* *************************************************采购仓库管理用到的参数及外部方法**********************************************
|
||
* PurchaseWarehouseModel.class.php
|
||
* @param $data['name'] 仓库名称
|
||
* @param $data['number'] 仓库编号
|
||
* @param $data['province'] 省
|
||
* @param $data['city'] 市
|
||
* @param $data['area'] 区
|
||
* @param $data['address'] 地址
|
||
* @param $data['measure_area'] 面积
|
||
* @param $data['person_name'] 负责人姓名
|
||
* @param $data['person_phone'] 负责人手机号
|
||
* @param $data['remarks'] 备注
|
||
* @param $data['default'] 是否默认 1默认 2不默认
|
||
* function paramJudge() 判断参数id是否正确 路径 Common/function.php
|
||
*/
|
||
/*
|
||
* *****************************************省市区*****************************************************
|
||
*/
|
||
//省
|
||
public function Province()
|
||
{
|
||
$province = M('citys');
|
||
$prov = $province->where(array('parentid' => 0))->select();
|
||
return $prov;
|
||
}
|
||
|
||
public function getCity()
|
||
{
|
||
if (IS_POST) {
|
||
$pid = I('post.pid');
|
||
$list = M('citys')->where(array('parentid' => $pid))->select();
|
||
$res['status'] = 1;
|
||
$res['data'] = $list;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
/*
|
||
* *************************************************查询信息**************************************************
|
||
*/
|
||
/*
|
||
* 商户下的所有仓库信息
|
||
*/
|
||
public function index()
|
||
{
|
||
$arr = array(
|
||
'addWarehouse' => '/index.php/Retail/SPurchaseWarehouse/addWarehouse',
|
||
'setWarehouse' => '/index.php/Retail/SPurchaseWarehouse/addWarehouse',
|
||
'delWarehouse' => '/index.php/Retail/SPurchaseWarehouse/deleteWarehouseOperation',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$this->display();
|
||
}
|
||
|
||
public function warehouseList()
|
||
{
|
||
$user = session("ls_userinfo");
|
||
$store_id = session("storeid");
|
||
$page = I("post.page");
|
||
$limit = I("post.limit");
|
||
$where['merchant_id'] = $user['merchantid'];
|
||
$where['store_id'] = $store_id;
|
||
$where['status'] = 1;
|
||
$info = D('SPurchaseWarehouse')->getSelect($where, $page, $limit, "*");
|
||
if ($info) {
|
||
$count = D('SPurchaseWarehouse')->getCount($where);
|
||
foreach ($info as $key => &$val) {
|
||
$val['index'] = $key + 1;
|
||
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
|
||
$val['region'] = $val['province'] . $val['city'] . $val['area'];
|
||
$val['measure_area'] = round($val['measure_area'], 2);
|
||
}
|
||
} else {
|
||
$info = array();
|
||
$count = 0;
|
||
}
|
||
$res['status'] = 1;
|
||
$res['msg'] = '';
|
||
$res['data'] = $info;
|
||
$res['count'] = $count;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/*
|
||
* 添加与编辑仓库的信息
|
||
* @param $id 编辑的仓库id
|
||
*/
|
||
public function addWarehouse()
|
||
{
|
||
$arr = array(
|
||
'onSubmit' => '/index.php/Retail/SPurchaseWarehouse/addWarehouseOperation',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$prov = $this->Province();
|
||
$this->assign('prov', json_encode($prov));
|
||
$id = I("get.id");
|
||
if ($id) { //编辑
|
||
$where['id'] = $id;
|
||
$info = D('SPurchaseWarehouse')->getFind($where);
|
||
if ($info) {
|
||
$info['measure_area'] = round($info['measure_area'], 2);
|
||
$parentid = M('citys')->where(array('city_name' => $info['city']))->getField('cityid');
|
||
$city = M('citys')->where(array('parentid' => $parentid))->select();
|
||
$parentid = M('citys')->where(array('city_name' => $info['area']))->getField('cityid');
|
||
$area = M('citys')->where(array('parentid' => $parentid))->select();
|
||
$this->assign('city', json_encode($city));
|
||
$this->assign('area', json_encode($area));
|
||
} else {
|
||
$info = array();
|
||
}
|
||
$this->assign('id', $id);
|
||
$this->assign('data', $info);
|
||
} else {//添加
|
||
$city = array();
|
||
$area = array();
|
||
$this->assign('city', json_encode($city));
|
||
$this->assign('area', json_encode($area));
|
||
}
|
||
$this->display();
|
||
}
|
||
/*
|
||
* *********************************************操作接口******************************************************
|
||
*/
|
||
|
||
|
||
/*
|
||
*添加采购仓库操作
|
||
*
|
||
*/
|
||
public function addWarehouseOperation()
|
||
{
|
||
$data = I('post.');
|
||
$data['merchant_id'] = $this->merchant_id;
|
||
$data['store_id'] = $this->store_id;
|
||
$WarehouseClass = new Warehouse();
|
||
$result = $WarehouseClass->storePurchaseWarehouseOperation($data);
|
||
if ($result['status'] == 1) {
|
||
if (!empty($data['id'])) {
|
||
$desc = '采购仓库管理-编辑';//操作行为描述
|
||
} else {
|
||
$desc = '采购仓库管理-新增仓库';//操作行为描述
|
||
}
|
||
$source = 0;//请求来源: 0pc系统 1小助手
|
||
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST);//请求参数 json数据
|
||
action_log($source, $type, $request_data, $desc);
|
||
}
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
/*
|
||
* 删除仓库
|
||
*/
|
||
public function deleteWarehouseOperation()
|
||
{
|
||
$userInfo = session("ls_userinfo");
|
||
$store_id = session("storeid");
|
||
$id = I("post.id");
|
||
$res = $this->judgeId($id);
|
||
if ($res['status'] == 1) {
|
||
$map['merchant_id'] = $userInfo['merchantid'];
|
||
$map['warehouse_id'] = $id;
|
||
$map['surplus_num'] = array('gt', 0);
|
||
$map['store_id'] = $store_id;
|
||
$existence = D('SPurchaseGoods')->getFind($map);
|
||
if ($existence) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '该仓库已存在商品,不能删除';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$where['id'] = $id;
|
||
$data['status'] = 0;
|
||
$res = D('SPurchaseWarehouse')->updateData($where, $data);
|
||
if ($res) {
|
||
//操作日志记录
|
||
$source = 0;//请求来源: 0pc系统 1小助手
|
||
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST);//请求参数 json数据
|
||
$desc = '仓库管理-删除';//操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
}
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/*
|
||
* 判断id
|
||
*/
|
||
public function judgeId($id)
|
||
{
|
||
if (!$id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数缺失';
|
||
} else {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '成功';
|
||
}
|
||
return $res;
|
||
}
|
||
} |