cqpCow 1 rok temu
rodzic
commit
6747ae94eb

+ 9 - 2
.idea/workspace.xml

@@ -2,6 +2,7 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="b5852db3-28ab-419d-82cf-b6c0f6b99397" name="变更" comment="">
+      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/app/Service/MaterialService.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Service/MaterialService.php" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
@@ -121,12 +122,18 @@
     <property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
     <property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
     <property name="WebServerToolWindowFactoryState" value="false" />
-    <property name="last_opened_file_path" value="$PROJECT_DIR$" />
+    <property name="last_opened_file_path" value="$PROJECT_DIR$/app/Service" />
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
     <property name="nodejs_package_manager_path" value="npm" />
     <property name="vue.rearranger.settings.migration" value="true" />
   </component>
+  <component name="RecentsManager">
+    <key name="CopyFile.RECENT_KEYS">
+      <recent name="D:\phpstudy_pro\WWW\jf_admin2.0\app\Service" />
+      <recent name="D:\phpstudy_pro\WWW\jf_admin2.0\app\Model" />
+    </key>
+  </component>
   <component name="RunManager">
     <configuration name="phpunit.xml" type="PHPUnitRunConfigurationType" factoryName="PHPUnit">
       <TestRunner scope="XML" />
@@ -145,7 +152,7 @@
       <workItem from="1685595177391" duration="2533000" />
       <workItem from="1685669123669" duration="2439000" />
       <workItem from="1685952381761" duration="726000" />
-      <workItem from="1686021203384" duration="8712000" />
+      <workItem from="1686021203384" duration="13363000" />
     </task>
     <servers />
   </component>

+ 13 - 0
app/Model/InOutRecord.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class InOutRecord extends Model
+{
+    protected $table = "in_out_record"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+}

+ 15 - 0
app/Model/Inventory.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+//库存
+class Inventory extends Model
+{
+    protected $table = "inventory"; //指定表
+    const CREATED_AT = null;
+    const UPDATED_AT = null;
+    protected $dateFormat = 'U';
+
+}

+ 19 - 0
app/Model/Storehouse.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * 仓库
+ * Class Unit
+ * @package App\Models
+ */
+class Storehouse extends Model
+{
+    protected $table = "storehouse"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+
+}

+ 232 - 0
app/Service/CheckService.php

@@ -0,0 +1,232 @@
+<?php
+
+namespace App\Service;
+
+use App\Model\Construction;
+use App\Model\ConstructionOrderSub;
+use App\Model\InOutRecord;
+use App\Model\Inventory;
+use App\Model\InventoryInSub;
+use App\Model\InventoryOutSub;
+use App\Model\MaterialCharge;
+use App\Model\MaterialOrder;
+use App\Model\MaterialOrderInSub;
+use App\Model\MaterialReturn;
+use App\Model\RollFilmInventory;
+use App\Model\Setting;
+use App\Model\Transfer;
+use App\Model\TransferInSub;
+use App\Model\TransferOutSub;
+use App\Model\Warranty;
+use App\Service\Oa\OaService;
+use Illuminate\Support\Facades\DB;
+
+/**
+ * 所有审批相关与流水
+ * @package App\Models
+ */
+class CheckService extends Service
+{
+    //审批操作对应的数值
+    const one = 1; //领料单申领区域审批
+    const two = 2; //领料单发货区域审批
+    const three = 3; //领料单收货区域审批
+    const four = 4; //领料单入库区域审批
+    const five = 5; //施工单审核
+    const six = 6; //退料单审核
+    const seven = 7; //调拨单详情审核
+    const eight = 8; //调拨单入库审核
+    const nine = 9; //调拨单出库审核
+    const ten = 10; //盘点单详情审核
+    const eleven = 11; //盘点单入库审核
+    const twl = 12; //盘点单出库审核
+    const thirteen = 13; //计费领料单审核
+
+    //中文对照
+    public $map = [
+        self::one => '领料单申领区域审批',
+        self::two => '领料单发货区域审批',
+        self::three => '领料单收货区域审批',
+        self::four => '领料单入库区域审批',
+        self::five => '施工单审核',
+        self::six => '退料单审核',
+        self::seven => '调拨单详情审核',
+        self::eight => '调拨单入库审核',
+        self::nine => '调拨单出库审核',
+        self::ten => '盘点单详情审核',
+        self::eleven => '盘点单入库审核',
+        self::twl => '盘点单出库审核',
+        self::thirteen => '计费领料单审核',
+    ];
+
+    const TYPE_ONE = 1;//通过
+    const TYPE_TWO = 2;//不通过
+
+    //对应具体单子的具体操作数值(将待审批改为通过或者未审批)
+    public static $opt_case = [
+        self::one => 'check_material_order_apply', //领料单申领区域审批
+        self::two => 'check_material_order_send', //领料单发货区域审批
+        self::three => 'check_material_order_take', //领料单收货区域审批
+        self::four => 'check_material_order_In', //领料单入库区域审批 审批通过后有入库流水
+        self::five => 'check_construction', //施工单审核  审批通过后有出库流水
+        self::six => 'check_material_return', //退料单审核  审批通过后有出库流水
+        self::seven => 'check_transfer_sub', //调拨单详情审核
+        self::eight => 'check_transfer_in_sub', //调拨单入库审核  审批通过后有入库流水
+        self::nine => 'check_transfer_out_sub', //调拨单出库审核  审批通过后有出库流水
+        self::ten => 'check_inventory_sub', //盘点单详情审核
+        self::eleven => 'check_inventory_in_sub', //盘点单入库审核   审批通过后有入库流水
+        self::twl => 'check_inventory_out_sub', //盘点单出库审核  审批通过后有出库流水
+        self::thirteen => 'check_material_charge', //计费领料单审核
+    ];
+
+    //单子审批通过后产生流水
+    public static $record = [
+        self::four => 'record_material_order_In', //领料单入库区域审批 审批通过后有入库流水
+        self::five => 'record_construction', //施工单审核  审批通过后有出库流水
+        self::six => 'record_material_return', //退料单审核  审批通过后有出库流水
+        self::eight => 'record_transfer_in_sub', //调拨单入库审核  审批通过后有入库流水
+        self::nine => 'record_transfer_out_sub', //调拨单出库审核  审批通过后有出库流水
+        self::eleven => 'record_inventory_in_sub', //盘点单入库审核   审批通过后有入库流水
+        self::twl => 'record_inventory_out_sub', //盘点单出库审核  审批通过后有出库流水
+    ];
+
+    //将状态改为待审核
+    public static $opt_case2 = [
+        self::one => 'set_check_material_order_apply', //领料单申领区域审批
+        self::two => 'set_check_material_order_send', //领料单发货区域审批
+        self::three => 'set_check_material_order_take', //领料单收货区域审批
+        self::four => 'set_check_material_order_In', //领料单入库区域审批 审批通过后有入库流水
+        self::five => 'set_check_construction', //施工单审核  审批通过后有出库流水
+        self::six => 'set_check_material_return', //退料单审核  审批通过后有出库流水
+        self::seven => 'set_check_transfer_sub', //调拨单详情审核
+        self::eight => 'set_check_transfer_in_sub', //调拨单入库审核  审批通过后有入库流水
+        self::nine => 'set_check_transfer_out_sub', //调拨单出库审核  审批通过后有出库流水
+        self::ten => 'set_check_inventory_sub', //盘点单详情审核
+        self::eleven => 'set_check_inventory_in_sub', //盘点单入库审核   审批通过后有入库流水
+        self::twl => 'set_check_inventory_out_sub', //盘点单出库审核  审批通过后有出库流水
+        self::thirteen => 'set_check_material_charge', //计费领料单审核
+    ];
+
+    public static $opt_case3 = [
+        self::five => 'create_warranty', //施工单审核 审批产生质保单
+    ];
+
+    //将状态改为待审核
+    public function set_status_to_one($data){
+        $modelOne = MaterialOrder::where('order_number',$data['order_number'])->where('del_time',0)->first();
+
+        //待审
+        if($modelOne->apply_status >= MaterialOrder::STATE_ONE) return [false,'已待审或审核通过,操作失败!'];
+
+        $modelOne->apply_status = MaterialOrder::STATE_ONE;
+        $modelOne->save();
+
+        return [true,''];
+    }
+
+    /**
+     * order_number 单据名称
+     * opt_case 审核单据的区域 有已经定义的方法
+     */
+    public function checkAll($data,$user){
+        if(empty($data['order_number']) || empty($data['opt_case']) || ! isset(self::$opt_case2[$data['opt_case']])) return [false,'必传参数不能为空或者参数值错误!'];
+
+        //具体方法
+        $function = self::$opt_case2[$data['opt_case']];
+
+        $function2 = self::$opt_case3[$data['opt_case']] ?? '';
+        try{
+            DB::beginTransaction();
+
+            //更新单据的状态 从待审变成已审核
+            list($bool,$msg) = $this->$function($data);
+
+            if(! $bool){
+                DB::rollBack();
+                return [false, $msg];
+            }
+
+            if($function2){
+                $this->$function2($data,$user);
+            }
+
+            //创建审批流
+            $args = [
+                'order_no' => $data['order_number'],
+                'menu_id' => $data['menu_id'] ?? 0,
+                'type' => $data['opt_case']
+            ];
+            $oa = new OaService();
+            $bool = $oa->createOaOrder($args);
+
+            DB::commit();
+            return [true, ''];
+        }catch (\Throwable $exception){
+            DB::rollBack();
+            return [false, $exception->getMessage()];
+        }
+
+    }
+    //创建审批流 将状态改为待审核  结束
+
+    //将待审核状态改为审批通过或者驳回
+    public function check_status($data){
+        return true;
+    }
+
+    //产生流水
+    public function record_create($data){
+        $result = [];
+
+        //写入流水
+        InOutRecord::insert($result);
+
+        return true;
+    }
+
+    /**
+     * 业务单据审核统一入库
+     * order_number 订单编号
+     * type 1 =》 通过  2  =》 驳回
+     * opt_case 具体审核类型 已定义同名静态变量
+     */
+    public function createRecordAndInventory($data = []){
+        if(empty($data['order_number']) || empty($data['type']) || empty($data['opt_case']) || ! isset(self::$opt_case[$data['opt_case']])) return [false,config('response.FAILED')];
+
+        //具体方法
+        $function = self::$opt_case[$data['opt_case']];
+
+        try{
+            DB::beginTransaction();
+
+            //更新单据的状态
+            $bool = $this->$function($data);
+
+            if($bool && $data['type'] == self::TYPE_ONE && isset(self::$record[$data['opt_case']])){
+                //审批通过 创建流水
+                $function_record = self::$record[$data['opt_case']];
+
+                $boolean = $this->$function_record($data);
+
+                if(! $boolean) { //创建流水失败 数据库回滚
+                    DB::rollBack();
+                    return [false, config('response.FAILED')];
+                }
+
+                //更新库存
+                $inventy = new InventoryService();
+                $boole = $inventy->changeInventory($data);
+                if(! $boole){
+                    DB::rollBack();
+                    return [false, config('response.FAILED')];
+                }
+            }
+
+            DB::commit();
+            return [true, config('response.SUCCESS')];
+        }catch (\Throwable $exception){
+            DB::rollBack();
+            return [false, config('response.FAILED')];
+        }
+    }
+}

+ 73 - 0
app/Service/InventoryService.php

@@ -0,0 +1,73 @@
+<?php
+
+namespace App\Service;
+
+use App\Model\InOutRecord;
+use App\Model\Inventory;
+use Illuminate\Support\Facades\DB;
+
+class InventoryService extends Service
+{
+    public function getList($data){
+        $model = Inventory::where('')
+            ->select('*');
+
+        $list = $this->limit($model,'',$data);
+
+        return [200, $list];
+    }
+
+    //获取卷膜真实库存
+    public static function getGoodsRealInventy($goods_id, $storehouse_id){
+        if(empty($roll_film_id) || empty($storehouse_id))  return [];
+
+        $array = Inventory::where('storehouse_id',$storehouse_id)
+            ->whereIn('goods_id',$goods_id)
+            ->select('goods_id','storehouse_id','number','lock_number')
+            ->get()->toArray();
+        if(empty($array)) return [];
+
+        $return = [];
+        foreach ($array as $v){
+            $return[$v['goods_id'].$v['storehouse_id']] = $v['number'] - $v['lock_number'];
+        }
+
+        return $return;
+    }
+
+    /**
+     * 业务单据审核后 更新库存
+     * order_number 订单编号
+     * opt_case 有些订单一次创建会同时有出入库单据
+     */
+    public function changeInventory($data){
+        $model = InOutRecord::where('del_time',0)
+            ->where('from_order_number',$data['order_number'])
+            ->select('storehouse_id',DB::raw("sum(number) as number"),'goods_id')
+            ->groupby('goods_id','storehouse_id');
+
+        $result = $model->get()->toArray();
+        if (empty($result)) return false;
+
+        foreach ($result as $key => $value){
+            $m = Inventory::where('goods_id',$value['goods_id'])
+                ->where('storehouse_id',$value['storehouse_id'])
+                ->select('goods_id','number','storehouse_id')
+                ->first();
+
+            if(empty($m)){
+                Inventory::insert($result[$key]);
+            }else{
+                $array['number'] = $value['number'] + $m->number;
+                $array['lock_number'] = $value['lock_number'] - $m->number;
+
+                Inventory::where('goods_id',$m->roll_film_id)
+                    ->where('storehouse_id',$m->storehouse_id)
+                    ->lockForUpdate()
+                    ->update($array);
+            }
+        }
+
+        return true;
+    }
+}

+ 5 - 2
app/Service/MaterialService.php

@@ -43,7 +43,11 @@ class MaterialService extends Service
             ->select('title','crt_time','upd_time','id','parent_id')
             ->orderBy('id','desc');
 
-        $list = $this->limit($list,'',$data);
+        $list = $list->get()->toArray();
+        if(! empty($list)) {
+            $list = $this->makeTree(0,$list);
+            $list = $this->set_sort_circle($list);
+        }
 
         return [200,$list];
     }
@@ -218,7 +222,6 @@ class MaterialService extends Service
         if($this->isEmpty($data,'title')) return [false,'物料名称不存在!'];
         if($this->isEmpty($data,'abbreviation_title')) return [false,'物料简称不存在!'];
         if($this->isEmpty($data,'unit')) return [false,'物料单位不存在!'];
-        if($this->isEmpty($data,'id')) return [false,'ID必传'];
 
         $model = Material::whereRaw("title = '{$data['title']}' OR abbreviation_title = '{$data['abbreviation_title']}'")
             ->where('del_time',0);