|
|
@@ -0,0 +1,1140 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Service;
|
|
|
+
|
|
|
+use App\Model\DDEmployee;
|
|
|
+use App\Model\FieldData;
|
|
|
+use App\Model\Inventory;
|
|
|
+use App\Model\Vendor;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+
|
|
|
+class U8XkyServerService extends Service
|
|
|
+{
|
|
|
+ //新增存货到本地-----------------------------------------------
|
|
|
+
|
|
|
+ public function inventoryAdd($data, $user){
|
|
|
+ list($status, $msg) = $this->inventoryRule($data, $user);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+
|
|
|
+ $inventoryData = [
|
|
|
+ 'order_number' => $this->generateBillNo([
|
|
|
+ 'type' => Inventory::Order_type,
|
|
|
+ 'period' => date("Ym")
|
|
|
+ ]),
|
|
|
+ 'code' => $data['code'] ?? "",
|
|
|
+ 'title' => $data['title'] ?? "",
|
|
|
+ 'size' => $data['size'] ?? "",
|
|
|
+ 'category_code' => $data['category_code'] ?? "",
|
|
|
+ 'category_code_title' => $data['category_code_title'] ?? "",
|
|
|
+ 'unit_group_type' => $data['unit_group_type'] ?? "",
|
|
|
+ 'unit_group_code' => $data['unit_group_code'] ?? "",
|
|
|
+ 'unit_group_code_title' => $data['unit_group_code_title'] ?? "",
|
|
|
+ 'unit_code' => $data['unit_code'] ?? "",
|
|
|
+ 'unit_code_title' => $data['unit_code_title'] ?? "",
|
|
|
+ 'vendor_code' => $data['vendor_code'] ?? "",
|
|
|
+ 'vendor_code_title' => $data['vendor_code_title'] ?? "",
|
|
|
+ 'bSale' => $data['bSale'] ?? 0, //内销
|
|
|
+ 'bExpSale' => $data['bExpSale'] ?? 0, //外销
|
|
|
+ 'bPurchase' => $data['bPurchase'] ?? 0, // 采购
|
|
|
+ 'bSelf' => $data['bSelf'] ?? 0, // 自制
|
|
|
+ 'bComsume' => $data['bComsume'] ?? 0, // 生产耗材
|
|
|
+ 'iImpTaxRate' => $data['iImpTaxRate'] ?? 0, // 进项税率
|
|
|
+ 'iTaxRate' => $data['iTaxRate'] ?? 0, // 销项税率
|
|
|
+ 'customs_change_rate' => $data['customs_change_rate'] ?? 0,
|
|
|
+ 'crt_id' => $user['userid'],
|
|
|
+ 'crt_time' => time(),
|
|
|
+ ];
|
|
|
+
|
|
|
+ Inventory::insert($inventoryData);
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ } catch (\Throwable $exception) {
|
|
|
+ DB::rollBack();
|
|
|
+ return [false, "创建存货失败: " . $exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function inventoryEdit($data, $user){
|
|
|
+ list($status, $msg) = $this->inventoryRule($data, $user);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+
|
|
|
+ $inventoryData = [
|
|
|
+ 'code' => $data['code'] ?? "",
|
|
|
+ 'title' => $data['title'] ?? "",
|
|
|
+ 'size' => $data['size'] ?? "",
|
|
|
+ 'category_code' => $data['category_code'] ?? "",
|
|
|
+ 'category_code_title' => $data['category_code_title'] ?? "",
|
|
|
+ 'unit_group_type' => $data['unit_group_type'] ?? "",
|
|
|
+ 'unit_group_code' => $data['unit_group_code'] ?? "",
|
|
|
+ 'unit_group_code_title' => $data['unit_group_code_title'] ?? "",
|
|
|
+ 'unit_code' => $data['unit_code'] ?? "",
|
|
|
+ 'unit_code_title' => $data['unit_code_title'] ?? "",
|
|
|
+ 'vendor_code' => $data['vendor_code'] ?? "",
|
|
|
+ 'vendor_code_title' => $data['vendor_code_title'] ?? "",
|
|
|
+ 'bSale' => $data['bSale'] ?? 0, //内销
|
|
|
+ 'bExpSale' => $data['bExpSale'] ?? 0, //外销
|
|
|
+ 'bPurchase' => $data['bPurchase'] ?? 0, // 采购
|
|
|
+ 'bSelf' => $data['bSelf'] ?? 0, // 自制
|
|
|
+ 'bComsume' => $data['bComsume'] ?? 0, // 生产耗材
|
|
|
+ 'iImpTaxRate' => $data['iImpTaxRate'] ?? 0, // 进项税率
|
|
|
+ 'iTaxRate' => $data['iTaxRate'] ?? 0, // 销项税率
|
|
|
+ 'customs_change_rate' => $data['customs_change_rate'] ?? 0,
|
|
|
+ 'upd_time' => time(),
|
|
|
+ ];
|
|
|
+
|
|
|
+ Inventory::where('id', $data['id'])->update($inventoryData);
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ } catch (\Throwable $exception) {
|
|
|
+ DB::rollBack();
|
|
|
+ return [false, "创建存货失败: " . $exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function inventoryRule(&$data, $user, $is_add = true){
|
|
|
+ if(! $is_add && empty($data['id'])) return [false, 'ID不能为空'];
|
|
|
+ $id = $data['id'] ?? 0;
|
|
|
+ $code = $data['code'] ?? "";
|
|
|
+ if(empty($data['title'])) return [false, '存货名称不能为空'];
|
|
|
+ $title = $data['title'];
|
|
|
+ if(empty($data['category_code'])) return [false, '存货分类编码不能为空'];
|
|
|
+ $category_code = $data['category_code'];
|
|
|
+ if(empty($data['category_code_title'])) return [false, '存货分类名不能为空'];
|
|
|
+ $category_code_title = $data['category_code_title'];
|
|
|
+ if(! isset($data['unit_group_type'])) return [false, '计量单位组类型不存在'];
|
|
|
+ $unit_group_type = $data['unit_group_type'] ?? "";
|
|
|
+ if(empty($data['unit_group_code'])) return [false, '计量单位组编码不能为空'];
|
|
|
+ $unit_group_code = $data['unit_group_code'] ?? "";
|
|
|
+ if(empty($data['unit_group_code_title'])) return [false, '计量单位组名不能为空'];
|
|
|
+ $unit_group_code_title = $data['unit_group_code_title'] ?? "";
|
|
|
+ if(empty($data['unit_code'])) return [false, '主计量单位编码不能为空'];
|
|
|
+ $unit_code = $data['unit_code'] ?? "";
|
|
|
+ if(empty($data['unit_code_title'])) return [false, '主计量单位名称不能为空'];
|
|
|
+ $unit_code_title = $data['unit_code_title'] ?? "";
|
|
|
+ if(! empty($data['vendor_code_title']) && empty($data['vendor_code'])) return [false, '生产企业编码不能为空'];
|
|
|
+ $vendor_code = $data['vendor_code'] ?? "";
|
|
|
+ $vendor_code_title = $data['vendor_code_title'] ?? "";
|
|
|
+ $bSale = $data['bSale'] ?? 0;
|
|
|
+ $bExpSale = $data['bExpSale'] ?? 0;
|
|
|
+ $bPurchase = $data['bPurchase'] ?? 0;
|
|
|
+ $bSelf = $data['bSelf'] ?? 0;
|
|
|
+ $bComsume = $data['bComsume'] ?? 0;
|
|
|
+ $iImpTaxRate = $data['iImpTaxRate'] ?? 0;
|
|
|
+ $iTaxRate = $data['iTaxRate'] ?? 0;
|
|
|
+ $res = $this->checkNumber($iImpTaxRate,2,'positive');
|
|
|
+ if(! $res['valid']) return [false,'进项税率:' . $res['error']];
|
|
|
+ $res = $this->checkNumber($iTaxRate,2,'positive');
|
|
|
+ if(! $res['valid']) return [false,'销项税率:' . $res['error']];
|
|
|
+ $customs_change_rate = $data['customs_change_rate'] ?? 0;
|
|
|
+ $res = $this->checkNumber($customs_change_rate,2,'positive');
|
|
|
+ if(! $res['valid']) return [false,'海关换算率:' . $res['error']];
|
|
|
+
|
|
|
+ if(! empty($code)){
|
|
|
+ $bool = Inventory::where('del_time', 0)
|
|
|
+ ->when(! empty($id), function ($query) use($id){
|
|
|
+ return $query->where('id', '<>', $id);
|
|
|
+ })
|
|
|
+ ->where('code', $code)
|
|
|
+ ->exists();
|
|
|
+ if($bool) return [false, '存货编码已存在记录,新增失败'];
|
|
|
+ }
|
|
|
+
|
|
|
+ if(! $is_add){
|
|
|
+ $bool = Inventory::where('del_time', 0)
|
|
|
+ ->where('id', $id)
|
|
|
+ ->where('status', '>', Inventory::STATE_ZERO)
|
|
|
+ ->exists();
|
|
|
+ if($bool) return [false, '存货记录状态已变更,编辑失败'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function inventoryCommon($data,$user, $field = []){
|
|
|
+ $model = Inventory::where('del_time',0)
|
|
|
+ ->where('crt_id', $user['userid'])
|
|
|
+ ->orderby('id', 'desc');
|
|
|
+
|
|
|
+ if(! empty($data['id'])) $model->where('id', $data['id']);
|
|
|
+ if(isset($data['status'])) $model->where('status', $data['status']);
|
|
|
+ if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
|
|
|
+ $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
|
|
|
+ $model->where('crt_time','>=',$return[0]);
|
|
|
+ $model->where('crt_time','<=',$return[1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $model;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function inventoryList($data, $user){
|
|
|
+ $model = $this->inventoryCommon($data, $user);
|
|
|
+ $list = $this->limit($model,'',$data);
|
|
|
+ $list = $this->fillInventoryData($list,$user);
|
|
|
+
|
|
|
+ return [true, $list];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fillInventoryData($data, $user){
|
|
|
+ if(empty($data['data'])) return $data;
|
|
|
+
|
|
|
+ foreach ($data['data'] as $key => $value){
|
|
|
+ $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
|
|
|
+ $data['data'][$key]['status_title'] = Inventory::$name[$value['status']] ?? '';
|
|
|
+ $data['data'][$key]['bSale'] = $value['bSale'] ? '是' : '否';
|
|
|
+ $data['data'][$key]['bExpSale'] = $value['bExpSale'] ? '是' : '否';
|
|
|
+ $data['data'][$key]['bPurchase'] = $value['bPurchase'] ? '是' : '否';
|
|
|
+ $data['data'][$key]['bSelf'] = $value['bSelf'] ? '是' : '否';
|
|
|
+ $data['data'][$key]['bComsume'] = $value['bComsume'] ? '是' : '否';
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function inventoryDel($data){
|
|
|
+ if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
|
|
|
+
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+ $time = time();
|
|
|
+
|
|
|
+ $bool = Inventory::where('del_time', 0)
|
|
|
+ ->whereIn('id', $data['id'])
|
|
|
+ ->where('status', '>', Inventory::STATE_ZERO)
|
|
|
+ ->exists();
|
|
|
+ if($bool) return [false, '存货记录状态已变更,删除失败'];
|
|
|
+
|
|
|
+ Inventory::where('del_time',0)
|
|
|
+ ->whereIn('id',$data['id'])
|
|
|
+ ->update(['del_time' => $time]);
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ return [false,$exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ //新增存货到本地-----------------------------------------------
|
|
|
+
|
|
|
+ //新增供应商到本地-----------------------------------------------
|
|
|
+
|
|
|
+ public function vendorAdd($data, $user){
|
|
|
+ list($status, $msg) = $this->vendorRule($data, $user);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+
|
|
|
+ $vendorData = [
|
|
|
+ 'order_number' => $this->generateBillNo([
|
|
|
+ 'type' => Vendor::Order_type,
|
|
|
+ 'period' => date("Ym")
|
|
|
+ ]),
|
|
|
+ 'code' => $data['code'] ?? "",
|
|
|
+ 'title' => $data['title'] ?? "",
|
|
|
+ 'easy_title' => $data['easy_title'] ?? "",
|
|
|
+ 'category_code' => $data['category_code'] ?? "",
|
|
|
+ 'category_code_title' => $data['category_code_title'] ?? "",
|
|
|
+ 'crt_id' => $user['userid'],
|
|
|
+ 'crt_time' => time(),
|
|
|
+ ];
|
|
|
+
|
|
|
+ Vendor::insert($vendorData);
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ } catch (\Throwable $exception) {
|
|
|
+ DB::rollBack();
|
|
|
+ return [false, "创建供应商失败: " . $exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function vendorEdit($data, $user){
|
|
|
+ list($status, $msg) = $this->vendorRule($data, $user);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+
|
|
|
+ $vendorData = [
|
|
|
+ 'code' => $data['code'] ?? "",
|
|
|
+ 'title' => $data['title'] ?? "",
|
|
|
+ 'easy_title' => $data['easy_title'] ?? "",
|
|
|
+ 'category_code' => $data['category_code'] ?? "",
|
|
|
+ 'category_code_title' => $data['category_code_title'] ?? "",
|
|
|
+ 'upd_time' => time(),
|
|
|
+ ];
|
|
|
+
|
|
|
+ Vendor::where('id', $data['id'])->update($vendorData);
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ } catch (\Throwable $exception) {
|
|
|
+ DB::rollBack();
|
|
|
+ return [false, "创建供应商失败: " . $exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function vendorRule(&$data, $user, $is_add = true){
|
|
|
+ if(! $is_add && empty($data['id'])) return [false, 'ID不能为空'];
|
|
|
+ $id = $data['id'] ?? 0;
|
|
|
+ $code = $data['code'] ?? "";
|
|
|
+ if(empty($data['title'])) return [false, '供应商全称不能为空'];
|
|
|
+ $title = $data['title'];
|
|
|
+ if(empty($data['easy_title'])) return [false, '供应商简称不能为空'];
|
|
|
+ $easy_title = $data['easy_title'];
|
|
|
+ if(empty($data['category_code'])) return [false, '供应商分类编码不能为空'];
|
|
|
+ $category_code = $data['category_code'];
|
|
|
+ if(empty($data['category_code_title'])) return [false, '供应商分类名不能为空'];
|
|
|
+ $category_code_title = $data['category_code_title'];
|
|
|
+
|
|
|
+ if(! empty($code)){
|
|
|
+ $bool = Vendor::where('del_time', 0)
|
|
|
+ ->when(! empty($id), function ($query) use($id){
|
|
|
+ return $query->where('id', '<>', $id);
|
|
|
+ })
|
|
|
+ ->where('code', $code)
|
|
|
+ ->exists();
|
|
|
+ if($bool) return [false, '供应商编码已存在记录,新增失败'];
|
|
|
+ }
|
|
|
+
|
|
|
+ if(! $is_add){
|
|
|
+ $bool = Vendor::where('del_time', 0)
|
|
|
+ ->where('id', $id)
|
|
|
+ ->where('status', '>', Vendor::STATE_ZERO)
|
|
|
+ ->exists();
|
|
|
+ if($bool) return [false, '供应商记录状态已变更,编辑失败'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function vendorCommon($data,$user, $field = []){
|
|
|
+ $model = Vendor::where('del_time',0)
|
|
|
+ ->where('crt_id', $user['userid'])
|
|
|
+ ->orderby('id', 'desc');
|
|
|
+
|
|
|
+ if(! empty($data['id'])) $model->where('id', $data['id']);
|
|
|
+ if(isset($data['status'])) $model->where('status', $data['status']);
|
|
|
+ if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
|
|
|
+ $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
|
|
|
+ $model->where('crt_time','>=',$return[0]);
|
|
|
+ $model->where('crt_time','<=',$return[1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $model;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function vendorList($data, $user){
|
|
|
+ $model = $this->vendorCommon($data, $user);
|
|
|
+ $list = $this->limit($model,'',$data);
|
|
|
+ $list = $this->fillVendorData($list,$user);
|
|
|
+
|
|
|
+ return [true, $list];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fillVendorData($data, $user){
|
|
|
+ if(empty($data['data'])) return $data;
|
|
|
+
|
|
|
+ foreach ($data['data'] as $key => $value){
|
|
|
+ $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
|
|
|
+ $data['data'][$key]['status_title'] = Vendor::$name[$value['status']] ?? '';
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function vendorDel($data){
|
|
|
+ if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
|
|
|
+
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+ $time = time();
|
|
|
+
|
|
|
+ $bool = Vendor::where('del_time', 0)
|
|
|
+ ->whereIn('id', $data['id'])
|
|
|
+ ->where('status', '>', Inventory::STATE_ZERO)
|
|
|
+ ->exists();
|
|
|
+ if($bool) return [false, '供应商记录状态已变更,删除失败'];
|
|
|
+
|
|
|
+ Vendor::where('del_time',0)
|
|
|
+ ->whereIn('id',$data['id'])
|
|
|
+ ->update(['del_time' => $time]);
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ return [false,$exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function filedCommon($data, $user, $field = []){
|
|
|
+ $model = FieldData::select([
|
|
|
+ 'userid',
|
|
|
+ 'type',
|
|
|
+ // 使用 GROUP_CONCAT 将 title 合并,并起别名为 titles
|
|
|
+ DB::raw('GROUP_CONCAT(title SEPARATOR ",") as titles')
|
|
|
+ ])
|
|
|
+ ->groupBy('userid', 'type')
|
|
|
+ ->orderBy('type', 'desc'); // 或者根据你的需求排序
|
|
|
+
|
|
|
+ return $model;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fieldList($data, $user){
|
|
|
+ $model = $this->filedCommon($data, $user);
|
|
|
+ $list = $this->limit($model,'',$data);
|
|
|
+
|
|
|
+ return [true, $list];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fieldDetail($data, $user){
|
|
|
+ if(! isset($data['type'])) return [false, 'type不能为空'];
|
|
|
+ if(! isset($data['userid'])) return [false, '人员id不能为空'];
|
|
|
+
|
|
|
+ return [true, FieldData::where('type', $data['type'])
|
|
|
+ ->where('userid', $data['userid'])
|
|
|
+ ->get()->toArray()];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setField($data, $user){
|
|
|
+ if(empty($user['qx'])) return [false, '权限不足,设置失败'];
|
|
|
+ if(empty($data['userid'])) return [false, '人员ID不能为空'];
|
|
|
+ if(! isset($data['field'])) return [false, '字段列不存在'];
|
|
|
+
|
|
|
+ $insert = [];
|
|
|
+ foreach ($data['field'] as $value){
|
|
|
+ $insert[] = [
|
|
|
+ 'userid' => $data['userid'],
|
|
|
+ 'key' => $value['key'],
|
|
|
+ 'title' => $value['title'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ FieldData::where('userid', $data['userid'])->delete();
|
|
|
+
|
|
|
+ if(! empty($insert)) FieldData::insert($insert);
|
|
|
+ } catch (\Throwable $exception) {
|
|
|
+ return [false, "异常: " . $exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function ddEmployeeList($data, $user){
|
|
|
+ $model = $this->ddEmployeeCommon($data, $user);
|
|
|
+ $list = $this->limit($model,'',$data);
|
|
|
+ $list = $this->fillDDEmployeeData($list,$user);
|
|
|
+
|
|
|
+ return [true, $list];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function ddEmployeeCommon($data,$user, $field = []){
|
|
|
+ $model = DDEmployee::where('del_time',0)
|
|
|
+ ->orderby('id', 'desc');
|
|
|
+
|
|
|
+ if(! empty($data['id'])) $model->where('id', $data['id']);
|
|
|
+ if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
|
|
|
+ $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
|
|
|
+ $model->where('crt_time','>=',$return[0]);
|
|
|
+ $model->where('crt_time','<=',$return[1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $model;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fillDDEmployeeData($data, $user){
|
|
|
+ if(empty($data['data'])) return $data;
|
|
|
+
|
|
|
+ foreach ($data['data'] as $key => $value){
|
|
|
+ $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ //新增供应商到本地-----------------------------------------------
|
|
|
+
|
|
|
+ //U8 存货库存列表
|
|
|
+ public function stockList($data, $user)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $field_list = [];
|
|
|
+ $employee = DDEmployee::where('userid', $user['userid'])->first();
|
|
|
+ $qx = $employee['qx'] ?? 0;
|
|
|
+ if(empty($qx)) {
|
|
|
+ $field_list = FieldData::where('userid', $user['userid'])
|
|
|
+ ->where('type', FieldData::STATE_ZERO)
|
|
|
+ ->pluck('key')
|
|
|
+ ->all();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 构建基础查询:关联现存量表和存货档案表
|
|
|
+ $query = DB::connection('sqlsrv')
|
|
|
+ ->table('CurrentStock as S')
|
|
|
+ ->select([
|
|
|
+ 'S.cWhCode', // 仓库编码
|
|
|
+ 'W.cWhName', // 仓库名称
|
|
|
+ 'S.cInvCode', // 存货编码
|
|
|
+ 'I.cInvName', // 存货名称
|
|
|
+ 'I.cInvStd', // 规格型号
|
|
|
+ 'I.cInvCCode', // 分类编码
|
|
|
+
|
|
|
+ // --- 数量字段对齐你的结构 ---
|
|
|
+ 'S.iQuantity', // 结存数量 (账面现存量)
|
|
|
+ 'S.fAvaQuantity', // 可用数量
|
|
|
+ 'S.fOutQuantity', // 待发货数量 (待出)
|
|
|
+ 'S.fInQuantity', // 待入库数量 (待入)
|
|
|
+ 'S.fStopQuantity', // 冻结数量
|
|
|
+
|
|
|
+ // --- 批次与日期 ---
|
|
|
+ 'S.cBatch', // 批号
|
|
|
+ 'S.dMdate', // 生产日期
|
|
|
+ 'S.dVDate', // 失效日期
|
|
|
+ ])
|
|
|
+ ->join('Inventory as I', 'S.cInvCode', '=', 'I.cInvCode')
|
|
|
+ ->leftJoin('Warehouse as W', 'S.cWhCode', '=', 'W.cWhCode')
|
|
|
+ ->leftJoin('InventoryClass as IC', 'I.cInvCCode', '=', 'IC.cInvCCode');
|
|
|
+
|
|
|
+ // 2. 过滤条件:存货名称 (支持模糊查询)
|
|
|
+ if (!empty($data['material_title'])) {
|
|
|
+ $query->where('I.cInvName', 'like', '%' . $data['material_title'] . '%');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 过滤条件:存货编码 (支持模糊查询)
|
|
|
+ if (!empty($data['material_code'])) {
|
|
|
+ $query->where('S.cInvCode', 'like', '%' . $data['material_code'] . '%');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 过滤条件:存货分类 (支持左匹配,即选大类查出所有子类)
|
|
|
+ if (!empty($data['category_code'])) {
|
|
|
+ // U8 分类是级次结构,用 like '01%' 可以查出 01 开头的所有子类
|
|
|
+ $query->where('I.cInvCCode', 'like', $data['category_code'] . '%');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 6. 排序
|
|
|
+ $query->orderBy('S.cInvCode', 'asc')->orderBy('S.cWhCode', 'asc');
|
|
|
+
|
|
|
+ // 7. 调用你定义的分页方法
|
|
|
+ $columns = ['*'];
|
|
|
+ $result = $this->limit($query, $columns, $data);
|
|
|
+
|
|
|
+ // 注意这里的 &$item,加了 & 符号才能直接修改原数组里的内容
|
|
|
+ foreach ($result['data'] as &$item) {
|
|
|
+ $numFields = ['iQuantity', 'fAvaQuantity', 'fOutQuantity', 'fInQuantity', 'fStopQuantity'];
|
|
|
+
|
|
|
+ foreach ($numFields as $field) {
|
|
|
+ if (isset($item->$field)) {
|
|
|
+ $item->$field = (float)$item->$field;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $item->dMdate = $item->dMdate ? date('Y-m-d', strtotime($item->dMdate)) : '';
|
|
|
+ $item->dVDate = $item->dVDate ? date('Y-m-d', strtotime($item->dVDate)) : '';
|
|
|
+
|
|
|
+ // 脱敏处理
|
|
|
+ if (!empty($field_list)) {
|
|
|
+ foreach ($field_list as $blackField) {
|
|
|
+ if (isset($item->$blackField)) {
|
|
|
+ $item->$blackField = '*****';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ unset($item); // 销毁引用
|
|
|
+
|
|
|
+ return [true, $result];
|
|
|
+
|
|
|
+ } catch (\Throwable $exception) {
|
|
|
+ return [false, "查询库存失败: " . $exception->getMessage()];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //U8 供应商列表
|
|
|
+ public function vendorU8List($data, $user)
|
|
|
+ {
|
|
|
+ // 1. 构建基础查询
|
|
|
+ $query = DB::connection('sqlsrv')
|
|
|
+ ->table('Vendor as V')
|
|
|
+ ->select([
|
|
|
+ 'V.cVenCode', // 供应商编码
|
|
|
+ 'V.cVenName', // 供应商名称
|
|
|
+ 'V.cVenAbbName', // 供应商简称
|
|
|
+ 'V.cVCCode', // 分类编码
|
|
|
+ 'VC.cVCName', // 分类名称 (来自 VendorClass)
|
|
|
+ 'V.cVenAddress', // 地址
|
|
|
+ 'V.cVenPhone', // 电话
|
|
|
+ 'V.dVenDevDate', // 发展日期
|
|
|
+ 'V.cCreatePerson', // 创建人
|
|
|
+ 'V.bVenTax', // 是否计税
|
|
|
+ 'V.iId' // 内部ID
|
|
|
+ ])
|
|
|
+ // 关联供应商分类表获取分类名称
|
|
|
+ ->leftJoin('VendorClass as VC', 'V.cVCCode', '=', 'VC.cVCCode');
|
|
|
+
|
|
|
+ // 2. 增加搜索逻辑 (可选)
|
|
|
+ if (!empty($data['keyword'])) {
|
|
|
+ $keyword = $data['keyword'];
|
|
|
+ $query->where(function($q) use ($keyword) {
|
|
|
+ $q->where('V.cVenCode', 'like', "%{$keyword}%")
|
|
|
+ ->orWhere('V.cVenName', 'like', "%{$keyword}%")
|
|
|
+ ->orWhere('V.cVenAbbName', 'like', "%{$keyword}%");
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 排序 (默认按编码排序)
|
|
|
+ $query->orderBy('V.cVenCode', 'ASC');
|
|
|
+
|
|
|
+ // 4. 调用你定义的分页方法
|
|
|
+ // 注意:limit 方法内部会执行 paginate 并将结果填充到 $data
|
|
|
+ $columns = ['*']; // select 已经在上面定义过了,这里传 * 即可
|
|
|
+ $result = $this->limit($query, $columns, $data);
|
|
|
+
|
|
|
+ return [true, $result];
|
|
|
+ }
|
|
|
+
|
|
|
+ // U8 供应商分类树结构
|
|
|
+ public function vendorClassTree($data, $user)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ // 1. 获取所有供应商分类 (表名: VendorClass)
|
|
|
+ $classes = DB::connection('sqlsrv')
|
|
|
+ ->table('VendorClass')
|
|
|
+ ->select('cVCCode', 'cVCName', 'iVCGrade', 'bVCEnd') // 编码、名称、级次
|
|
|
+ ->orderBy('cVCCode', 'asc')
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ if ($classes->isEmpty()) {
|
|
|
+ return [true, []];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 格式化数据,以编码为 Key
|
|
|
+ $classList = [];
|
|
|
+ foreach ($classes as $item) {
|
|
|
+ $classList[$item->cVCCode] = [
|
|
|
+ 'label' => $item->cVCName,
|
|
|
+ 'value' => $item->cVCCode, // 前端通常需要 value 字段
|
|
|
+ 'code' => $item->cVCCode,
|
|
|
+ 'grade' => $item->iVCGrade,
|
|
|
+ 'is_end' => $item->bVCEnd,
|
|
|
+ 'children' => []
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 构建引用树
|
|
|
+ $tree = [];
|
|
|
+ foreach ($classList as $code => &$node) {
|
|
|
+ // 获取父级编码
|
|
|
+ $parentCode = $this->getParentCode($code);
|
|
|
+
|
|
|
+ if ($parentCode === null || !isset($classList[$parentCode])) {
|
|
|
+ // 顶级节点
|
|
|
+ $tree[] = &$node;
|
|
|
+ } else {
|
|
|
+ // 挂载到父节点
|
|
|
+ $classList[$parentCode]['children'][] = &$node;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, $tree];
|
|
|
+
|
|
|
+ } catch (\Throwable $exception) {
|
|
|
+ return [false, "获取供应商分类树失败: " . $exception->getMessage()];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //U8 存货分类树结构
|
|
|
+ public function inventoryClassTree($data, $user)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ // 1. 从数据库获取所有存货分类
|
|
|
+ $classes = DB::connection('sqlsrv')
|
|
|
+ ->table('InventoryClass')
|
|
|
+ ->select('cInvCCode', 'cInvCName', 'iInvCGrade', 'bInvCEnd')
|
|
|
+ ->orderBy('cInvCCode', 'asc')
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ if ($classes->isEmpty()) return [true, []];
|
|
|
+
|
|
|
+ // 2. 将集合转换为数组并以编码作为 Key,方便查找
|
|
|
+ $classList = [];
|
|
|
+ foreach ($classes as $item) {
|
|
|
+ $classList[$item->cInvCCode] = [
|
|
|
+ 'label' => $item->cInvCName,
|
|
|
+ 'code' => $item->cInvCCode,
|
|
|
+ 'grade' => $item->iInvCGrade,
|
|
|
+ 'is_end' => $item->bInvCEnd,
|
|
|
+ 'children' => []
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 构建树形结构
|
|
|
+ $tree = [];
|
|
|
+ foreach ($classList as $code => &$node) {
|
|
|
+ // 获取当前分类的级次 (U8 逻辑通常根据编码长度判断父级)
|
|
|
+ // 比如 0101 的父级是 01
|
|
|
+ $parentCode = $this->getParentCode($code);
|
|
|
+
|
|
|
+ if ($parentCode === null || !isset($classList[$parentCode])) {
|
|
|
+ // 如果没有父级编码,或者父级编码不在列表里,说明是顶级分类
|
|
|
+ $tree[] = &$node;
|
|
|
+ } else {
|
|
|
+ // 将当前节点引用到父节点的 children 数组中
|
|
|
+ $classList[$parentCode]['children'][] = &$node;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, $tree];
|
|
|
+
|
|
|
+ } catch (\Throwable $exception) {
|
|
|
+ return [false, "获取分类树失败: " . $exception->getMessage()];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 辅助函数:根据 U8 编码规则获取父级编码
|
|
|
+ * U8 的级次通常存储在 GradeDef 表,但通用逻辑是截取末尾
|
|
|
+ */
|
|
|
+ private function getParentCode($code)
|
|
|
+ {
|
|
|
+ $len = strlen($code);
|
|
|
+ if ($len <= 2) return null; // 假设第一级是2位,小于等于2位则无父级
|
|
|
+
|
|
|
+ // 这里假设级次是 2-2-2-2 (最常见配置)
|
|
|
+ // 实际生产中,如果级次不固定,建议查询 GradeDef 表
|
|
|
+ return substr($code, 0, $len - 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ //U8 计量单位组(带默认主计量单位)
|
|
|
+ public function getUnitGroups($data, $user)
|
|
|
+ {
|
|
|
+ $list = DB::connection('sqlsrv')
|
|
|
+ ->select("
|
|
|
+ SELECT
|
|
|
+ G.cGroupCode,
|
|
|
+ G.cGroupName,
|
|
|
+ G.iGroupType,
|
|
|
+ U.cComUnitCode,
|
|
|
+ U.cComUnitName,
|
|
|
+ U.iNumber
|
|
|
+ FROM ComputationGroup AS G
|
|
|
+ OUTER APPLY (
|
|
|
+ SELECT TOP 1 cComUnitCode, cComUnitName, iNumber
|
|
|
+ FROM ComputationUnit
|
|
|
+ WHERE cGroupCode = G.cGroupCode
|
|
|
+ ORDER BY
|
|
|
+ bMainUnit DESC, -- 1. 优先主计量
|
|
|
+ iNumber ASC, -- 2. 序号最小 (若 NULL 会排在最前)
|
|
|
+ cComUnitCode ASC -- 3. 编码最小
|
|
|
+ ) AS U
|
|
|
+ ");
|
|
|
+
|
|
|
+ return [true, $list];
|
|
|
+ }
|
|
|
+
|
|
|
+ //U8 计量单位档案
|
|
|
+ public function getComputationUnitList($data, $user)
|
|
|
+ {
|
|
|
+ $list = DB::connection('sqlsrv')
|
|
|
+ ->table('ComputationUnit as U')
|
|
|
+ ->select(
|
|
|
+ 'U.cComUnitCode', // 单位编码
|
|
|
+ 'U.cComUnitName', // 单位名称
|
|
|
+ 'U.cGroupCode', // 所属组编码
|
|
|
+ 'U.bMainUnit', // 是否主单位
|
|
|
+ 'U.iNumber' // 排序序号
|
|
|
+ )
|
|
|
+ ->orderBy('U.cGroupCode', 'ASC')
|
|
|
+ ->orderBy('U.iNumber', 'ASC') // 按照你要求的 iNumber 排序
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ return [true, $list];
|
|
|
+ }
|
|
|
+
|
|
|
+ //U8 存货新增到用友
|
|
|
+ public function inventoryAdd1($data, $user){
|
|
|
+ $inventory = Inventory::where('del_time', 0)
|
|
|
+ ->where('id', $data['id'])
|
|
|
+ ->first();
|
|
|
+ if(empty($inventory)) return [false, '存货记录不存在或已被删除'];
|
|
|
+ $inventory = $inventory->toArray();
|
|
|
+ if($inventory['status'] != Inventory::STATE_TWO) return [false, '存货记录未审核通过'];
|
|
|
+
|
|
|
+ $title = $inventory['title'];
|
|
|
+ $category_code = $inventory['category_code'];
|
|
|
+ if(! empty($data['code'])){
|
|
|
+ //用户传入
|
|
|
+ $no = $inventory['code'];
|
|
|
+ $flag_title = "重填";
|
|
|
+ }else{
|
|
|
+ //生成编码
|
|
|
+ list($status, $msg) = $this->generate('inventory','1005');
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+ $no = $msg;
|
|
|
+ $flag_title = "重试";
|
|
|
+ }
|
|
|
+
|
|
|
+ $inventoryData = [
|
|
|
+ 'cInvCode' => $no,
|
|
|
+ 'cInvName' => $title,
|
|
|
+ 'cInvCCode' => $category_code,
|
|
|
+ 'cInvStd' => $inventory['size'] ?? null, // 规格型号
|
|
|
+ 'bSale' => $inventory['bSale'], //内销
|
|
|
+ 'bExpSale' => $inventory['bExpSale'], //外销
|
|
|
+ 'bPurchase' => $inventory['bPurchase'], // 采购
|
|
|
+ 'bSelf' => $inventory['bSelf'], // 自制
|
|
|
+ 'bComsume' => $inventory['bComsume'], // 生产耗材
|
|
|
+ 'iGroupType' => $inventory['unit_group_type'], // 计量单位组类别
|
|
|
+ 'cGroupCode' => $inventory['unit_group_code'], //计量单位组
|
|
|
+ 'cComUnitCode' => $inventory['unit_code'], // 主计量单位
|
|
|
+ 'cShopUnit' => $inventory['unit_code'], // 零售计量单位
|
|
|
+ 'iImpTaxRate' => $inventory['iImpTaxRate'], // 进项税率
|
|
|
+ 'iTaxRate' => $inventory['iTaxRate'], // 销项税率
|
|
|
+ 'dSDate' => date("Y-m-d 00:00:00.000"), // 启用日期
|
|
|
+ 'cEnterprise' => $inventory['vendor_code_title'] ?? null,
|
|
|
+ 'iSupplyType' => '0', // 供应类型
|
|
|
+ 'fConvertRate' => '1.0', // 转换因子
|
|
|
+ 'bInTotalCost' => '1', // 成本累计否
|
|
|
+ 'cPlanMethod' => 'R',
|
|
|
+ 'cSRPolicy' => 'PE',
|
|
|
+ 'bBomMain' => '0', // 允许BOM母件
|
|
|
+ 'bBomSub' => '0', // 允许BOM子件
|
|
|
+ 'bProductBill' => '0', // 允许生产订单
|
|
|
+ 'iPlanDefault' => '1',
|
|
|
+ 'iAllocatePrintDgt' => '4',
|
|
|
+ 'bService' => '0',
|
|
|
+ 'bAccessary' => '0',
|
|
|
+ 'iInvAdvance' => '0.0',
|
|
|
+ 'bInvQuality' => '0',
|
|
|
+ 'bInvBatch' => '0',
|
|
|
+ 'bInvEntrust' => '0',
|
|
|
+ 'bInvOverStock' => '0',
|
|
|
+ 'bFree1' => '0',
|
|
|
+ 'bFree2' => '0',
|
|
|
+ 'bInvType' => '0',
|
|
|
+ 'bFree3' => '0',
|
|
|
+ 'bFree4' => '0',
|
|
|
+ 'bFree5' => '0',
|
|
|
+ 'bFree6' => '0',
|
|
|
+ 'bFree7' => '0',
|
|
|
+ 'bFree8' => '0',
|
|
|
+ 'bFree9' => '0',
|
|
|
+ 'bFree10' => '0',
|
|
|
+ 'cCreatePerson' => 'demo',
|
|
|
+ 'cModifyPerson' => 'demo', // 变更
|
|
|
+ 'dModifyDate' => date("Y-m-d H:i:s.000"),
|
|
|
+ 'bFixExch' => '0',
|
|
|
+ 'bTrack' => '0',
|
|
|
+ 'bSerial' => '0',
|
|
|
+ 'bBarCode' => '0',
|
|
|
+ 'bSolitude' => '0',
|
|
|
+ 'bSpecialties' => '0',
|
|
|
+ 'bPropertyCheck' => '0',
|
|
|
+ 'iRecipeBatch' => '0',
|
|
|
+ 'bPromotSales' => '0',
|
|
|
+ 'bPlanInv' => '0',
|
|
|
+ 'bProxyForeign' => '0',
|
|
|
+ 'bATOModel' => '0',
|
|
|
+ 'bCheckItem' => '0',
|
|
|
+ 'bPTOModel' => '0',
|
|
|
+ 'bEquipment' => '0',
|
|
|
+ 'bMPS' => '0',
|
|
|
+ 'bROP' => '0',
|
|
|
+ 'bRePlan' => '0',
|
|
|
+ 'bBillUnite' => '0',
|
|
|
+ 'bCutMantissa' => '0',
|
|
|
+ 'bConfigFree1' => '0',
|
|
|
+ 'bConfigFree2' => '0',
|
|
|
+ 'bConfigFree3' => '0',
|
|
|
+ 'bConfigFree4' => '0',
|
|
|
+ 'bConfigFree5' => '0',
|
|
|
+ 'bConfigFree6' => '0',
|
|
|
+ 'bConfigFree7' => '0',
|
|
|
+ 'bConfigFree8' => '0',
|
|
|
+ 'bConfigFree9' => '0',
|
|
|
+ 'bConfigFree10' => '0',
|
|
|
+ 'bPeriodDT' => '0',
|
|
|
+ 'bOutInvDT' => '0',
|
|
|
+ 'bBackInvDT' => '0',
|
|
|
+ 'bDTWarnInv' => '0',
|
|
|
+ 'bImportMedicine' => '0',
|
|
|
+ 'bFirstBusiMedicine' => '0',
|
|
|
+ 'bForeExpland' => '0',
|
|
|
+ 'bInvModel' => '0',
|
|
|
+ 'bKCCutMantissa' => '0',
|
|
|
+ 'bReceiptByDT' => '0',
|
|
|
+ 'bCheckBSATP' => '0',
|
|
|
+ 'bCheckFree1' => '0',
|
|
|
+ 'bCheckFree2' => '0',
|
|
|
+ 'bCheckFree3' => '0',
|
|
|
+ 'bCheckFree4' => '0',
|
|
|
+ 'bCheckFree5' => '0',
|
|
|
+ 'bCheckFree6' => '0',
|
|
|
+ 'bCheckFree7' => '0',
|
|
|
+ 'bCheckFree8' => '0',
|
|
|
+ 'bCheckFree9' => '0',
|
|
|
+ 'bCheckFree10' => '0',
|
|
|
+ 'iCheckATP' => '0',
|
|
|
+ 'bPiece' => '0',
|
|
|
+ 'bSrvItem' => '0',
|
|
|
+ 'bSrvFittings' => '0',
|
|
|
+ 'bSpecialOrder' => '0',
|
|
|
+ 'bTrackSaleBill' => '0',
|
|
|
+ 'bCheckBatch' => '0',
|
|
|
+ 'bMngOldpart' => '0',
|
|
|
+ ];
|
|
|
+
|
|
|
+ $inventorySubData = [
|
|
|
+ 'cInvSubCode' => $no,
|
|
|
+ 'iSurenessType' => '1',
|
|
|
+ 'bIsAttachFile' => '0',
|
|
|
+ 'bInByProCheck' => '1',
|
|
|
+ 'iRequireTrackStyle' => '0',
|
|
|
+ 'iExpiratDateCalcu' => '0',
|
|
|
+ 'iBOMExpandUnitType' => '1',
|
|
|
+ 'iDrawType' => $inventory['iDrawType'] ?? 0, // 领用方式
|
|
|
+ 'fInvCIQExch' => $inventory['customs_change_rate'] ?? 1, // 海关换算率
|
|
|
+ 'bInvKeyPart' => '1',
|
|
|
+ 'iAcceptEarlyDays' => '999',
|
|
|
+ 'dInvCreateDatetime' => date("Y-m-d H:i:s.000"),
|
|
|
+ 'bPUQuota' => '0',
|
|
|
+ 'bInvROHS' => '0',
|
|
|
+ 'bPrjMat' => '0',
|
|
|
+ 'bInvAsset' => '0',
|
|
|
+ 'bSrvProduct' => '0',
|
|
|
+ 'iAcceptDelayDays' => '0',
|
|
|
+ 'bSCkeyProjections' => '0',
|
|
|
+ 'iSupplyPeriodType' => '1',
|
|
|
+ 'iAvailabilityDate' => '1',
|
|
|
+ 'bImport' => '0',
|
|
|
+ 'bCheckSubitemCost' => '1',
|
|
|
+ 'fRoundFactor' => '0.0',
|
|
|
+ 'bConsiderFreeStock' => '1',
|
|
|
+ 'bSuitRetail' => '0',
|
|
|
+ 'bFeatureMatch' => '0',
|
|
|
+ 'bProduceByFeatureAllocate' => '0',
|
|
|
+ 'bMaintenance' => '0',
|
|
|
+ 'iMaintenanceCycleUnit' => '0',
|
|
|
+ 'bCoupon' => '0',
|
|
|
+ 'bStoreCard' => '0',
|
|
|
+ 'bProcessProduct' => '0',
|
|
|
+ 'bProcessMaterial' => '0',
|
|
|
+ // 所有的价格自由项默认设为 '0'
|
|
|
+ 'bPurPriceFree1' => '0', 'bPurPriceFree2' => '0', 'bPurPriceFree3' => '0', 'bPurPriceFree4' => '0', 'bPurPriceFree5' => '0',
|
|
|
+ 'bPurPriceFree6' => '0', 'bPurPriceFree7' => '0', 'bPurPriceFree8' => '0', 'bPurPriceFree9' => '0', 'bPurPriceFree10' => '0',
|
|
|
+ 'bOMPriceFree1' => '0', 'bOMPriceFree2' => '0', 'bOMPriceFree3' => '0', 'bOMPriceFree4' => '0', 'bOMPriceFree5' => '0',
|
|
|
+ 'bOMPriceFree6' => '0', 'bOMPriceFree7' => '0', 'bOMPriceFree8' => '0', 'bOMPriceFree9' => '0', 'bOMPriceFree10' => '0',
|
|
|
+ 'bSalePriceFree1' => '0', 'bSalePriceFree2' => '0', 'bSalePriceFree3' => '0', 'bSalePriceFree4' => '0', 'bSalePriceFree5' => '0',
|
|
|
+ 'bSalePriceFree6' => '0', 'bSalePriceFree7' => '0', 'bSalePriceFree8' => '0', 'bSalePriceFree9' => '0', 'bSalePriceFree10' => '0',
|
|
|
+ // 所有的控制自由项默认设为 '0'
|
|
|
+ 'bControlFreeRange1' => '0', 'bControlFreeRange2' => '0', 'bControlFreeRange3' => '0', 'bControlFreeRange4' => '0', 'bControlFreeRange5' => '0',
|
|
|
+ 'bControlFreeRange6' => '0', 'bControlFreeRange7' => '0', 'bControlFreeRange8' => '0', 'bControlFreeRange9' => '0', 'bControlFreeRange10' => '0',
|
|
|
+ // 所有的批次属性默认设为 '0'
|
|
|
+ 'bBatchProperty1' => '0', 'bBatchProperty2' => '0', 'bBatchProperty3' => '0', 'bBatchProperty4' => '0', 'bBatchProperty5' => '0',
|
|
|
+ 'bBatchProperty6' => '0', 'bBatchProperty7' => '0', 'bBatchProperty8' => '0', 'bBatchProperty9' => '0', 'bBatchProperty10' => '0',
|
|
|
+ 'bBondedInv' => '0',
|
|
|
+ 'bBatchCreate' => '0',
|
|
|
+ ];
|
|
|
+
|
|
|
+ try {
|
|
|
+ DB::connection('sqlsrv')->beginTransaction();
|
|
|
+
|
|
|
+ $exists = DB::connection('sqlsrv')
|
|
|
+ ->table('Inventory')
|
|
|
+ ->where('cInvCode', $inventoryData['cInvCode'])
|
|
|
+ ->lockForUpdate() // 锁定该行,防止并发冲突
|
|
|
+ ->exists();
|
|
|
+
|
|
|
+ if ($exists) return [false, '存货编码已存在,请' . $flag_title];
|
|
|
+
|
|
|
+ DB::connection('sqlsrv')->table('Inventory')->insert($inventoryData);
|
|
|
+ DB::connection('sqlsrv')->table('Inventory_sub')->insert($inventorySubData);
|
|
|
+
|
|
|
+ DB::connection('sqlsrv')->commit();
|
|
|
+ } catch (\Throwable $exception) {
|
|
|
+ DB::connection('sqlsrv')->rollBack();
|
|
|
+
|
|
|
+ return [false, "创建用友失败: " . $exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ //U8 供应商新增
|
|
|
+ public function vendorAdd1($data, $user){
|
|
|
+ $vendor = Vendor::where('del_time', 0)
|
|
|
+ ->where('id', $data['id'])
|
|
|
+ ->first();
|
|
|
+ if(empty($vendor)) return [false, '供应商记录不存在或已被删除'];
|
|
|
+ $vendor = $vendor->toArray();
|
|
|
+ if($vendor['status'] != Vendor::STATE_TWO) return [false, '供应商记录未审核通过'];
|
|
|
+
|
|
|
+ if(! empty($vendor['code'])){
|
|
|
+ //用户传入
|
|
|
+ $no = $vendor['code'];
|
|
|
+ $flag_title = "重填";
|
|
|
+ }else{
|
|
|
+ //生成编码
|
|
|
+ list($status, $msg) = $this->generate('vendor');
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+ $no = $msg;
|
|
|
+ $flag_title = "重试";
|
|
|
+ }
|
|
|
+
|
|
|
+ $vendorData = [
|
|
|
+ 'cVenCode' => $no,
|
|
|
+ 'cVenName' => $vendor['title'],
|
|
|
+ 'cVenAbbName' => $vendor['easy_title'],
|
|
|
+ 'cVCCode' => $vendor['category_code'],
|
|
|
+ 'dVenDevDate' => date("Y-m-d 00:00:00.000"),
|
|
|
+ 'iVenDisRate' => '0.0',
|
|
|
+ 'iVenCreLine' => '0.0',
|
|
|
+ 'iVenCreDate' => '0',
|
|
|
+ 'cVenHeadCode' => $no,
|
|
|
+ 'iAPMoney' => '0.0',
|
|
|
+ 'iLastMoney' => '0.0',
|
|
|
+ 'iLRMoney' => '0.0',
|
|
|
+ 'iFrequency' => '0',
|
|
|
+ 'bVenTax' => '1',
|
|
|
+ 'cCreatePerson' => 'demo',
|
|
|
+ 'cModifyPerson' => 'demo',
|
|
|
+ 'dModifyDate' => date("Y-m-d H:i:s.000"),
|
|
|
+ 'iGradeABC' => '-1',
|
|
|
+ 'bLicenceDate' => '0',
|
|
|
+ 'bBusinessDate' => '0',
|
|
|
+ 'bProxyDate' => '0',
|
|
|
+ 'bPassGMP' => '0',
|
|
|
+ 'bVenCargo' => '1', // 采购
|
|
|
+ 'bProxyForeign' => '0', // 委外
|
|
|
+ 'bVenService' => '0', // 服务
|
|
|
+ 'bVenOverseas' => '0', // 国外
|
|
|
+ 'cVenExch_name' => '人民币',
|
|
|
+ 'iVenGSPType' => '0',
|
|
|
+ 'iVenGSPAuth' => '-1',
|
|
|
+ 'bVenAccPeriodMng' => '0',
|
|
|
+ 'bVenHomeBranch' => '0',
|
|
|
+ 'dVenCreateDatetime' => date("Y-m-d H:i:s.000"),
|
|
|
+ 'bIsVenAttachFile' => '0',
|
|
|
+ 'bRetail' => '0',
|
|
|
+ ];
|
|
|
+
|
|
|
+ try {
|
|
|
+ DB::connection('sqlsrv')->beginTransaction();
|
|
|
+
|
|
|
+ $exists = DB::connection('sqlsrv')
|
|
|
+ ->table('Vendor')
|
|
|
+ ->where('cVenCode', $vendorData['cVenCode'])
|
|
|
+ ->lockForUpdate() // 锁定该行,防止并发冲突
|
|
|
+ ->exists();
|
|
|
+
|
|
|
+ if ($exists) return [false, '供应商编码已存在,请' . $flag_title];
|
|
|
+
|
|
|
+ DB::connection('sqlsrv')->table('Vendor')->insert($vendorData);
|
|
|
+
|
|
|
+ DB::connection('sqlsrv')->commit();
|
|
|
+
|
|
|
+ } catch (\Throwable $exception) {
|
|
|
+ DB::connection('sqlsrv')->rollBack();
|
|
|
+
|
|
|
+ return [false, "创建供应商失败: " . $exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成编码
|
|
|
+ public function generate($type, $classCode = "")
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ // 1. 确定对象映射
|
|
|
+ $cardNumber = ($type === 'inventory') ? 'inventory' : 'Vendor';
|
|
|
+ $cardNumber_name = ($type === 'inventory') ? '存货' : '供应商';
|
|
|
+ $table = ($type === 'inventory') ? 'Inventory' : 'Vendor';
|
|
|
+ $codeField = ($type === 'inventory') ? 'cInvCode' : 'cVenCode';
|
|
|
+
|
|
|
+ // 2. 获取 U8 规则定义
|
|
|
+ $rule = DB::connection('sqlsrv')->table('VoucherNumber')
|
|
|
+ ->where('CardNumber', $cardNumber)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ if (!$rule) return [false, "未找到 {$cardNumber_name} 的规则定义"];
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 3. 动态解析前缀 (Prefix1, Prefix2, Prefix3)
|
|
|
+ * U8 的规则通常存放在 PrefixRule 或 Prefix 字段中
|
|
|
+ */
|
|
|
+ $prefix = "";
|
|
|
+ for ($i = 1; $i <= 3; $i++) {
|
|
|
+ $ruleField = "Prefix{$i}Rule";
|
|
|
+ $valField = "Prefix{$i}";
|
|
|
+
|
|
|
+ // 检查规则描述
|
|
|
+ $ruleDesc = $rule->$ruleField ?? ''; // 例如 "存货分类编码" 或 "GYS"
|
|
|
+ $staticVal = $rule->$valField ?? '';
|
|
|
+
|
|
|
+ if (str_contains($ruleDesc, '分类') || str_contains($staticVal, '分类')) {
|
|
|
+ // 如果规则提到“分类”,则填入传入的分类编码
|
|
|
+ $prefix .= $classCode;
|
|
|
+ } elseif (!empty($ruleDesc)) {
|
|
|
+ // 如果规则是具体的字符(如 "GYS"),直接拼接
|
|
|
+ $prefix .= $ruleDesc;
|
|
|
+ } elseif (!empty($staticVal) && $staticVal !== '手工输入' && $staticVal !== '存货分类编码') {
|
|
|
+ // 如果静态值不是提示语,则作为前缀
|
|
|
+ $prefix .= $staticVal;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 获取流水号配置 (Glide)
|
|
|
+ $glideLen = $rule->GlideLen > 0 ? $rule->GlideLen : 4;
|
|
|
+ $startNum = $rule->iStartNumber ?? 1;
|
|
|
+
|
|
|
+ // 5. 查找当前最大编码
|
|
|
+ $expectedLen = strlen($prefix) + $glideLen;
|
|
|
+
|
|
|
+ $lastCode = DB::connection('sqlsrv')->table($table)
|
|
|
+ ->where($codeField, 'like', $prefix . '%')
|
|
|
+ ->whereRaw("LEN($codeField) = $expectedLen")
|
|
|
+ ->orderBy($codeField, 'desc')
|
|
|
+ ->value($codeField);
|
|
|
+
|
|
|
+ // 6. 生成编码
|
|
|
+ if (!$lastCode) {
|
|
|
+ // 初始:前缀 + 起始值补零
|
|
|
+ $finalCode = $prefix . str_pad($startNum, $glideLen, '0', STR_PAD_LEFT);
|
|
|
+ } else {
|
|
|
+ // 截取流水号自增
|
|
|
+ $lastSerial = substr($lastCode, -$glideLen);
|
|
|
+ $nextSerial = ++$lastSerial;
|
|
|
+
|
|
|
+ // 溢出检查
|
|
|
+ if (strlen($nextSerial) > $glideLen) {
|
|
|
+ return [false, "流水号已溢出"];
|
|
|
+ }
|
|
|
+ $finalCode = $prefix . str_pad($nextSerial, $glideLen, '0', STR_PAD_LEFT);
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, $finalCode];
|
|
|
+
|
|
|
+ } catch (\Throwable $e) {
|
|
|
+ return [false, "生成失败: " . $e->getMessage()];
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|