Commit 72b348e9 by lzzzzl

新增修改

parent 2545e46b
......@@ -76,6 +76,14 @@ class ServicesController extends Controller
}
/**
* 获取仓库列表
*/
public function ApiStoreList($request) {
$data = (new StoreModel())->storeList();
return $this->apiReturn($Errcode = 0, $level = 1 , $dataArr=$data);
}
/**
* 插入仓库信息
*/
public function ApiInsertStoreInfo($request) {
......@@ -133,20 +141,29 @@ class ServicesController extends Controller
* 获取区域信息
*/
public function ApiZoneInfo($request) {
$params = $request->only(['limit','page','zone_sn','zone_name','store_name']);
$params = $request->only(['limit','page','zone_sn','zone_name','store_name','store_id']);
$arr = array(
'limit' => !empty($params['limit'])?$params['limit']:10,
'page' => !empty($params['page'])?$params['page']:1,
'zone_sn' => !empty($params['zone_sn'])?$params['zone_sn']:'',
'zone_name' => !empty($params['zone_name'])?$params['zone_name']:'',
'store_name' => !empty($params['store_name'])?$params['store_name']:''
'store_name' => !empty($params['store_name'])?$params['store_name']:'',
'store_id' => $params['store_id']
);
$data = (new ZoneModel())->zoneInfo($arr);
return $this->apiReturn($Errcode = 0, $level = 1 , $dataArr=$data);
}
/**
* 获取仓库列表
*/
public function ApiZoneList($request) {
$data = (new ZoneModel())->zoneList();
return $this->apiReturn($Errcode = 0, $level = 1 , $dataArr=$data);
}
/**
* 插入仓库信息
*/
public function ApiInsertZoneInfo($request) {
......@@ -201,13 +218,14 @@ class ServicesController extends Controller
* 获取货位信息
*/
public function ApiLocationInfo($request) {
$params = $request->only(['limit','page','location_name','zone_name']);
$params = $request->only(['limit','page','location_name','zone_name','store_id']);
$arr = array(
'limit' => !empty($params['limit'])?$params['limit']:10,
'page' => !empty($params['page'])?$params['page']:1,
'location_name' => !empty($params['location_name'])?$params['location_name']:'',
'zone_name' => !empty($params['zone_name'])?$params['zone_name']:'',
'store_id' => $params['store_id']
);
$data = (new LocationModel())->locInfo($arr);
return $this->apiReturn($Errcode = 0, $level = 1 , $dataArr=$data);
......@@ -287,12 +305,40 @@ class ServicesController extends Controller
*/
public function ApiInsertGoodsInfo($request) {
$params = $request->only(['goods_name','goods_cn_name','brand_name','erp_goods_id','admin_name','admin_id']);
if (empty($params['goods_name']) || empty($params['goods_cn_name']) || empty($params['brand_name']) || empty($params['erp_goods_id']) || empty($params['admin_id']) || empty($params['admin_name']))
if (empty($params['goods_name']) || empty($params['brand_name']) || empty($params['erp_goods_id']) || empty($params['admin_id']) || empty($params['admin_name']))
return $this->apiReturn($Errcode = 101, $level = 1 , $dataArr=[]);
$params['add_time'] = time();
$params['update_time'] = time();
$data = (new GoodsModel())->InsertGoodsInfo($params);
$result = (new GoodsModel())->InsertGoodsInfo($params);
if (!$result)
return $this->apiReturn($Errcode = 102, $level = 1 , $dataArr=[]);
else
return $this->apiReturn($Errcode = 100, $level = 1 , $dataArr=[]);
}
public function ApiUpdateGoodsInfo($request) {
$params = $request->only(['goods_name','goods_cn_name','brand_name','erp_goods_id','admin_name','admin_id']);
if (empty($params['admin_id']) || empty($params['admin_name']) || empty($params['erp_goods_id']))
return $this->apiReturn($Errcode = 101, $level = 1 , $dataArr=[]);
$arr = array();
$arr['admin_id'] = $params['admin_id'];
$arr['admin_name'] = $params['admin_name'];
$arr['erp_goods_id'] = $params['erp_goods_id'];
$arr['update_time'] = time();
if (!empty($params['goods_name']))
$arr['goods_name'] = $params['goods_name'];
if (!empty($params['goods_cn_name']))
$arr['goods_cn_name'] = $params['goods_cn_name'];
if (!empty($params['brand_name']))
$arr['brand_name'] = $params['brand_name'];
$result = (new GoodsModel())->updateGoodsInfo($arr);
if (!$result)
return $this->apiReturn($Errcode = 103, $level = 1 , $dataArr=[]);
else
return $this->apiReturn($Errcode = 100, $level = 1 , $dataArr=[]);
}
/**
......@@ -338,12 +384,12 @@ class ServicesController extends Controller
* 更新客户信息
*/
public function ApiUpdateCustomerInfo($request) {
$params = $request->only(['customer_id','erp_client_sn','customer_name','erp_customer_id','admin_id','admin_name']);
if (empty($params['customer_id']) || empty($params['admin_id']) || empty($params['admin_name']))
$params = $request->only(['erp_client_sn','customer_name','erp_customer_id','admin_id','admin_name']);
if (empty($params['erp_customer_id']) || empty($params['admin_id']) || empty($params['admin_name']))
return $this->apiReturn($Errcode = 101, $level = 1 , $dataArr=[]);
$arr = array();
$arr['customer_id'] = $params['customer_id'];
$arr['erp_customer_id'] = $params['erp_customer_id'];
$arr['admin_id'] = $params['admin_id'];
$arr['admin_name'] = $params['admin_name'];
$arr['update_time'] = time();
......@@ -351,8 +397,6 @@ class ServicesController extends Controller
$arr['erp_client_sn'] = $params['erp_client_sn'];
if (!empty($params['customer_name']))
$arr['customer_name'] = $params['customer_name'];
if (!empty($params['erp_customer_id']))
$arr['erp_customer_id'] = $params['erp_customer_id'];
$result = (new CustomerModel())->updateCustomerInfo($arr);
if (!$result)
......@@ -362,6 +406,29 @@ class ServicesController extends Controller
}
/**
* 更新客户状态
*/
public function ApiUpdateCustomerStatus($request) {
$params = $request->only(['status','erp_customer_id','admin_id','admin_name']);
if (empty($params['erp_customer_id']) || empty($params['admin_id']) || empty($params['admin_name']) || $params['status'] == "")
return $this->apiReturn($Errcode = 101, $level = 1 , $dataArr=[]);
$arr = array();
$arr['erp_customer_id'] = $params['erp_customer_id'];
$arr['status'] = (int)$params['status'];
$arr['admin_id'] = $params['admin_id'];
$arr['admin_name'] = $params['admin_name'];
$arr['update_time'] = time();
$result = (new CustomerModel())->updateCustomerStatus($arr);
if (!$result)
return $this->apiReturn($Errcode = 103, $level = 1 , $dataArr=[]);
else
return $this->apiReturn($Errcode = 100, $level = 1 , $dataArr=[]);
}
/**
* 获取供应商信息
*/
public function ApiSupplierInfo($request) {
......@@ -404,12 +471,12 @@ class ServicesController extends Controller
* 更新供应商信息
*/
public function ApiUpdateSupplierInfo($request) {
$params = $request->only(['supplier_id','erp_supplier_sn','supplier_name','erp_supplier_id','admin_id','admin_name']);
if (empty($params['supplier_id']) || empty($params['admin_id']) || empty($params['admin_name']))
$params = $request->only(['erp_supplier_sn','supplier_name','erp_supplier_id','admin_id','admin_name']);
if (empty($params['erp_supplier_id']) || empty($params['admin_id']) || empty($params['admin_name']))
return $this->apiReturn($Errcode = 101, $level = 1 , $dataArr=[]);
$arr = array();
$arr['supplier_id'] = $params['supplier_id'];
$arr['erp_supplier_id'] = $params['erp_supplier_id'];
$arr['admin_id'] = $params['admin_id'];
$arr['admin_name'] = $params['admin_name'];
$arr['update_time'] = time();
......@@ -417,9 +484,7 @@ class ServicesController extends Controller
$arr['erp_supplier_sn'] = $params['erp_supplier_sn'];
if (!empty($params['supplier_name']))
$arr['supplier_name'] = $params['supplier_name'];
if (!empty($params['erp_supplier_id']))
$arr['erp_supplier_id'] = $params['erp_supplier_id'];
$result = (new SupplierModel())->updateSupplierInfo($arr);
if (!$result)
return $this->apiReturn($Errcode = 103, $level = 1 , $dataArr=[]);
......@@ -427,4 +492,48 @@ class ServicesController extends Controller
return $this->apiReturn($Errcode = 100, $level = 1 , $dataArr=[]);
}
/**
* 更新供应商状态
*/
public function ApiUpdateSupplierStatus($request) {
$params = $request->only(['status','erp_supplier_id','admin_id','admin_name']);
if (empty($params['erp_supplier_id']) || empty($params['admin_id']) || empty($params['admin_name']) || $params['status'] == "")
return $this->apiReturn($Errcode = 101, $level = 1 , $dataArr=[]);
$arr = array();
$arr['erp_supplier_id'] = $params['erp_supplier_id'];
$arr['status'] = (int)$params['status'];
$arr['admin_id'] = $params['admin_id'];
$arr['admin_name'] = $params['admin_name'];
$arr['update_time'] = time();
$result = (new SupplierModel())->updateSupplierStatus($arr);
if (!$result)
return $this->apiReturn($Errcode = 103, $level = 1 , $dataArr=[]);
else
return $this->apiReturn($Errcode = 100, $level = 1 , $dataArr=[]);
}
/**
* 更新供应商状态
*/
public function ApiUpdateGoodsStatus($request) {
$params = $request->only(['status','erp_goods_id','admin_id','admin_name']);
if (empty($params['erp_goods_id']) || empty($params['admin_id']) || empty($params['admin_name']) || $params['status'] == "")
return $this->apiReturn($Errcode = 101, $level = 1 , $dataArr=[]);
$arr = array();
$arr['erp_goods_id'] = $params['erp_goods_id'];
$arr['status'] = (int)$params['status'];
$arr['admin_id'] = $params['admin_id'];
$arr['admin_name'] = $params['admin_name'];
$arr['update_time'] = time();
$result = (new GoodsModel())->updateGoodsStatus($arr);
if (!$result)
return $this->apiReturn($Errcode = 103, $level = 1 , $dataArr=[]);
else
return $this->apiReturn($Errcode = 100, $level = 1 , $dataArr=[]);
}
}
......@@ -2,6 +2,7 @@
namespace App\Http\Model;
use Common\Model\RedisModel;
use Illuminate\Database\Eloquent\Model;
use Config;
use DB;
......@@ -15,6 +16,16 @@ class CustomerModel extends Model
protected $table = 'customer';
public $timestamps = false;
public function __construct($connection = false)
{
parent::__construct();
if($connection){
$this->connection= $connection;
}
$this->redis = new RedisModel();
}
/**
* 客户信息
*/
......@@ -29,11 +40,15 @@ class CustomerModel extends Model
}
$data = $this->
select('erp_client_sn','customer_name','erp_customer_id')->
select('erp_client_sn','customer_name','erp_customer_id','status')->
where($map)->
paginate($limit,['*'],'p',$page)->
toArray();
foreach($data['data'] as $k => $v) {
$data['data'][$k]['status'] = $v['status'] = 0 ? '删除':'存在';
}
return $data;
}
......@@ -41,13 +56,50 @@ class CustomerModel extends Model
* 写入客户信息
*/
public function insertCustomerInfo($arr) {
return $this->insert($arr);
$str = DB::connection($this->connection)->transaction(function() use($arr){
$erp_client_sn = $arr['erp_client_sn'];
$customer_id = $this->insertGetId($arr);
if (!$customer_id)
return new \Exception("Error Processing Request");
$c2r = $this->cusId2Redis($customer_id,json_encode($arr));
if (!$c2r)
return new \Exception("Error Processing Request");
$sn2r = $this->cusSn2Redis($erp_client_sn,$customer_id);
if (!$sn2r)
return new \Exception("Error Processing Request");
return true;
});
return $str;
}
/**
* 更新客户信息
*/
public function updateCustomerInfo($arr) {
return $this->where('customer_id', '=', $arr)->update($arr);
return $this->where('erp_customer_id', '=', $arr)->update($arr);
}
/**
* 更新客户状态
*/
public function updateCustomerStatus($arr) {
return $this->where('erp_customer_id', '=', $arr)->update($arr);
}
/**
* 缓存客户信息
*/
private function cusId2Redis($customer_id,$customer) {
return $this->redis->hset('scm_customer',$customer_id,$customer);
}
/**
* 缓存客户sn
*/
private function cusSn2Redis($erp_client_sn,$customer_id) {
$encrypt_sn = md5($erp_client_sn);
return $this->redis->hset('scm_customer_erp_client_sn',$encrypt_sn,$customer_id);
}
}
\ No newline at end of file
......@@ -39,12 +39,16 @@ class GoodsModel extends Model
}
$data = $this->
select('goods_name','goods_cn_name','goods_sn','brand_name','erp_goods_id')->
select('goods_name','goods_cn_name','goods_sn','brand_name','erp_goods_id','status')->
where($map)->
leftJoin('brand','brand.brand_id','goods.goods_id')->
leftJoin('brand','brand.brand_id','goods.brand_id')->
paginate($limit,['*'],'p',$page)->
toArray();
foreach($data['data'] as $k => $v) {
$data['data'][$k]['status'] = $v['status'] = 0 ? '删除':'存在';
}
return $data;
}
......@@ -58,41 +62,106 @@ class GoodsModel extends Model
$admin_id = $arr['admin_id'];
$erp_id = $arr['erp_goods_id'];
$brand_exist = DB::connection('mysql')->table('brand')->select('brand_id')->where('brand_name','=',$brand_name)->first();
// 品牌参数
$brand_params = array(
'brand_name' => $brand_name,
'admin_name' => $admin_name,
'admin_id' => $admin_id,
'add_time' => time(),
'update_time' => time()
);
// 获取品牌ID,品牌不存在,则进行写入
if (!$brand_exist) {
$brand_params = array(
'brand_name' => $brand_name,
'admin_name' => $admin_name,
'admin_id' => $admin_id,
'add_time' => time(),
'update_time' => time()
);
$brand_id = DB::connection('mysql')->table('brand')->insertGetId($brand_params);
// 缓存品牌
$this->brand2Redis($brand_id,$brand_name);
} else {
$brand_id = $brand_exist->brand_id;
}
$arr['brand_id'] = $brand_id;
$arr['goods_sn'] = (new SnModel())->sn("goods_sn");
unset($arr['brand_name']);
// 写入DB
$goods_id = $this->insertGetId($arr);
// 品牌不存在
if (!$brand_exist) {
// 缓存品牌->品牌Id
$this->brandName2BrandId($brand_name,$brand_id);
// 缓存品牌id->品牌信息
$this->brandId2BrandInfo($brand_id,json_encode($brand_params));
}
// ERPID GOODSID REDIS
$this->erpId2GoodsId($erp_id,$goods_id);
// GOODSID GOODS REDIS
$this->goodsId2Goods($goods_id,json_encode($arr));
return true;
});
return $str;
}
/**
* 更新物料数据
*/
public function updateGoodsInfo($arr) {
$str = DB::connection($this->connection)->transaction(function() use($arr){
$erp_goods_id = $arr['erp_goods_id'];
$admin_name = $arr['admin_name'];
$admin_id = $arr['admin_id'];
// 判断是否需要更新品牌
if (!empty($arr['brand_name'])) {
$brand_name = $arr['brand_name'];
$brand_exist = DB::connection('mysql')->table('brand')->select('brand_id')->where('brand_name','=',$brand_name)->first();
$brand_params = array(
'brand_name' => $brand_name,
'admin_name' => $admin_name,
'admin_id' => $admin_id,
'add_time' => time(),
'update_time' => time()
);
if (!$brand_exist) {
$brand_id = DB::connection('mysql')->table('brand')->insertGetId($brand_params);
} else {
$brand_id = $brand_exist->brand_id;
}
// 更新DB
unset($arr['brand_name']);
$arr['brand_id'] = $brand_id;
$this->where('erp_goods_id', '=', $erp_goods_id)->update($arr);
// 缓存品牌->品牌Id
$this->brandName2BrandId($brand_name,$brand_id);
// 缓存品牌id->品牌信息
$this->brandId2BrandInfo($brand_id,json_encode($brand_params));
} else {
// 更新DB
$this->where('erp_goods_id', '=', $erp_goods_id)->update($arr);
}
return true;
});
return $str;
}
/**
* 缓存品牌名(加密)、品牌Id
*/
private function brandName2BrandId($brand_name,$brand_id) {
$encrypt_bn = md5($brand_name);
return $this->redis->hset('scm_brand_name',$encrypt_bn,$brand_id);
}
/**
* 缓存品牌
* 缓存品牌Id、品牌信息
*/
private function brand2Redis($brand_id,$brand_name) {
$encrypt_bi = md5($brand_id);
$this->redis->hset('scm_brand',$encrypt_bi,$brand_name);
private function brandId2BrandInfo($brand_id,$brand_info) {
return $this->redis->hset('scm_brand_info',$brand_id,$brand_info);
}
/**
......@@ -100,15 +169,20 @@ class GoodsModel extends Model
*/
private function erpId2GoodsId($erp_id,$goods_id) {
$encrypt_ei = md5($erp_id);
$this->redis->hset('scm_goods_erp_id',$encrypt_ei,$goods_id);
return $this->redis->hset('scm_goods_erp_id',$encrypt_ei,$goods_id);
}
/**
* GOODSID、GOODS 缓存
*/
private function goodsId2Goods($goods_id,$goods) {
$encrypt_gi = md5($goods_id);
$this->redis->hset('scm_goods_goods_id',$encrypt_gi,$goods);
return $this->redis->hset('scm_goods_goods_id',$goods_id,$goods);
}
/**
* 更新物料状态
*/
public function updateGoodsStatus($arr) {
return $this->where('erp_goods_id', '=', $arr)->update($arr);
}
}
\ No newline at end of file
......@@ -23,8 +23,10 @@ class LocationModel extends Model
$page = $arr['page'];
$location_name = $arr['location_name'];
$zone_name = $arr['zone_name'];
$store_id = $arr['store_id'];
$map = [];
$map[] = ['location.store_id','=',$store_id];
if (!empty($zone_name)) {
$map[] = ['zone_name', '=', $zone_name];
}
......@@ -33,9 +35,10 @@ class LocationModel extends Model
}
$data = $this->
select('location_id','location_name','zone_name')->
select('location_id','location_sn','location_name','zone_name','store_name')->
where($map)->
leftJoin('zone','zone.zone_id','location.zone_id')->
leftJoin('store','store.store_id','location.store_id')->
paginate($limit,['*'],'p',$page)->
toArray();
......
......@@ -2,6 +2,7 @@
namespace App\Http\Model;
use Common\Model\RedisModel;
use Illuminate\Database\Eloquent\Model;
use Config;
use DB;
......@@ -15,6 +16,15 @@ class StoreModel extends Model
protected $table = 'store';
public $timestamps = false;
public function __construct($connection = false)
{
parent::__construct();
if($connection){
$this->connection= $connection;
}
$this->redis = new RedisModel();
}
/**
* 仓库基本信息
*/
......@@ -46,10 +56,33 @@ class StoreModel extends Model
}
/**
* 仓库列表
*/
public function storeList() {
$data = $this->select('store_id','store_name')->get();
return $data;
}
/**
* 写入仓库信息
*/
public function insertStoreInfo($arr) {
return $this->insert($arr);
$str = DB::connection($this->connection)->transaction(function() use($arr){
$erp_store_id = $arr['erp_store_id'];
$store_id = $this->insertGetId($arr);
if (!$store_id)
return new \Exception("Error Processing Request");
$s2r = $this->storeId2Redis($store_id,json_encode($arr));
if (!$s2r)
return new \Exception("Error Processing Request");
$sn2r = $this->erpId2Redis($erp_store_id,$store_id);
if (!$sn2r)
return new \Exception("Error Processing Request");
return true;
});
return $str;
}
/**
......@@ -57,6 +90,20 @@ class StoreModel extends Model
*/
public function updateStoreInfo($arr) {
return $this->where('store_id', '=', $arr)->update($arr);
}
/**
* 缓存仓库信息
*/
private function storeId2Redis($store_id,$store) {
return $this->redis->hset('scm_store_info',$store_id,$store);
}
/**
* 缓存客户sn
*/
private function erpId2Redis($erp_id,$store_id) {
$encrypt_ei = md5($erp_id);
return $this->redis->hset('scm_store_erp_id',$encrypt_ei,$store_id);
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
namespace App\Http\Model;
use Common\Model\RedisModel;
use Illuminate\Database\Eloquent\Model;
use Config;
use DB;
......@@ -15,6 +16,15 @@ class SupplierModel extends Model
protected $table = 'supplier';
public $timestamps = false;
public function __construct($connection = false)
{
parent::__construct();
if($connection){
$this->connection= $connection;
}
$this->redis = new RedisModel();
}
/**
* 区域信息
*/
......@@ -29,11 +39,15 @@ class SupplierModel extends Model
}
$data = $this->
select('erp_supplier_sn','supplier_name','erp_supplier_id')->
select('erp_supplier_sn','supplier_name','erp_supplier_id','status')->
where($map)->
paginate($limit,['*'],'p',$page)->
toArray();
foreach($data['data'] as $k => $v) {
$data['data'][$k]['status'] = $v['status'] = 0 ? '删除':'存在';
}
return $data;
}
......@@ -41,14 +55,51 @@ class SupplierModel extends Model
* 写入供应商信息
*/
public function insertSupplierInfo($arr) {
return $this->insert($arr);
$str = DB::connection($this->connection)->transaction(function() use($arr){
$erp_supplier_sn = $arr['erp_supplier_sn'];
$supplier_id = $this->insertGetId($arr);
if (!$supplier_id)
return new \Exception("Error Processing Request");
$s2r = $this->supId2Redis($supplier_id,json_encode($arr));
if (!$s2r)
return new \Exception("Error Processing Request");
$sn2r = $this->supSn2Redis($erp_supplier_sn,$supplier_id);
if (!$sn2r)
return new \Exception("Error Processing Request");
return true;
});
return $str;
}
/**
* 更新供应商信息
*/
public function updateSupplierInfo($arr) {
return $this->where('supplier_id', '=', $arr)->update($arr);
return $this->where('erp_supplier_id', '=', $arr)->update($arr);
}
/**
* 更新供应商状态
*/
public function updateSupplierStatus($arr) {
return $this->where('erp_supplier_id', '=', $arr)->update($arr);
}
/**
* 缓存供应商信息
*/
private function supId2Redis($supplier_id,$supplier) {
return $this->redis->hset('scm_supplier',$supplier_id,$supplier);
}
/**
* 缓存供应商sn
*/
private function supSn2Redis($erp_supplier_sn,$supplier_id) {
$encrypt_sn = md5($erp_supplier_sn);
return $this->redis->hset('scm_supplier_erp_supplier_sn',$encrypt_sn,$supplier_id);
}
}
\ No newline at end of file
......@@ -24,8 +24,10 @@ class ZoneModel extends Model
$zone_sn = $arr['zone_sn'];
$zone_name = $arr['zone_name'];
$store_name = $arr['store_name'];
$store_id = $arr['store_id'];
$map = [];
$map[] = ['zone.store_id','=',$store_id];
if (!empty($zone_sn)) {
$map[] = ['zone_sn', '=', $zone_sn];
}
......@@ -47,6 +49,14 @@ class ZoneModel extends Model
}
/**
* 区域列表
*/
public function zoneList() {
$data = $this->select('zone_id','zone_name')->get();
return $data;
}
/**
* 写入仓库信息
*/
public function insertZoneInfo($arr) {
......
scm_wms_common @ 65e023eb
Subproject commit 64218b258abb792578ff19cc0270d218625a734a
Subproject commit 65e023eb6471c8502f3306414c8982f58be7255b
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment