Commit 72b348e9 by lzzzzl

新增修改

parent 2545e46b
......@@ -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