cqp 3 周之前
父節點
當前提交
19ca01fc35
共有 5 個文件被更改,包括 273 次插入31 次删除
  1. 76 0
      app/Http/Controllers/Api/GiveOutController.php
  2. 13 0
      app/Model/GiveOut.php
  3. 177 0
      app/Service/GiveOutService.php
  4. 0 31
      app/Service/Service.php
  5. 7 0
      routes/api.php

+ 76 - 0
app/Http/Controllers/Api/GiveOutController.php

@@ -0,0 +1,76 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use App\Service\GiveOutService;
+use Illuminate\Http\Request;
+
+class GiveOutController extends BaseController
+{
+    public function giveOutEdit(Request $request)
+    {
+        $service = new GiveOutService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->giveOutEdit($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function giveOutAdd(Request $request)
+    {
+        $service = new GiveOutService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->giveOutAdd($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+
+    }
+
+    public function giveOutDel(Request $request)
+    {
+        $service = new GiveOutService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->giveOutDel($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+
+    }
+
+    public function giveOutList(Request $request)
+    {
+        $service = new GiveOutService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->giveOutList($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function giveOutDetail(Request $request)
+    {
+        $service = new GiveOutService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->giveOutDetail($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+}

+ 13 - 0
app/Model/GiveOut.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Model;
+
+class GiveOut extends UseScopeBaseModel
+{
+    protected $table = "give_out"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+
+    public static $field = ['give_out_amount','id','mark','employee_id_1','employee_id_1_title','send_time','start_time','end_time'];
+}

+ 177 - 0
app/Service/GiveOutService.php

@@ -0,0 +1,177 @@
+<?php
+
+namespace App\Service;
+
+use App\Model\Employee;
+use App\Model\GiveOut;
+use Illuminate\Support\Facades\DB;
+
+/**
+ * 发放
+ */
+class GiveOutService extends Service
+{
+    public function giveOutEdit($data,$user){
+        list($status,$msg) = $this->giveOutRule($data, $user, false);
+        if(!$status) return [$status,$msg];
+
+        try {
+            DB::beginTransaction();
+
+            $model = GiveOut::where('id',$data['id'])->first();
+            $model->give_out_amount = $data['give_out_amount'] ?? 0;
+            $model->employee_id_1 = $data['employee_id_1'] ?? 0;
+            $model->employee_id_1_title = $data['employee_id_1_title'] ?? "";
+            $model->send_time = $data['send_time'] ?? 0;
+            $model->start_time = $data['start_time'] ?? 0;
+            $model->end_time = $data['end_time'] ?? 0;
+            $model->save();
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true, ''];
+    }
+
+    public function giveOutAdd($data,$user){
+        list($status,$msg) = $this->giveOutRule($data, $user);
+        if(!$status) return [$status,$msg];
+
+        try {
+            DB::beginTransaction();
+
+            $model = new GiveOut();
+            $model->give_out_amount = $data['give_out_amount'] ?? 0;
+            $model->employee_id_1 = $data['employee_id_1'] ?? 0;
+            $model->employee_id_1_title = $data['employee_id_1_title'] ?? "";
+            $model->send_time = $data['send_time'] ?? 0;
+            $model->start_time = $data['start_time'] ?? 0;
+            $model->end_time = $data['end_time'] ?? 0;
+            $model->crt_id = $user['id'];
+            $model->save();
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true, ''];
+    }
+
+    public function giveOutDel($data){
+        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
+
+        try {
+            DB::beginTransaction();
+            $time = time();
+
+            GiveOut::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 giveOutDetail($data,$user){
+        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
+        $customer = GiveOut::where('del_time',0)
+            ->where('id',$data['id'])
+            ->first();
+        if(empty($customer)) return [false,'发放记录不存在或已被删除'];
+        $customer = $customer->toArray();
+
+        $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('emp_name');
+        $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
+
+        return [true, $customer];
+    }
+
+    public function giveOutCommon($data,$user, $field = []){
+        if(empty($field)) $field = GiveOut::$field;
+
+        $model = GiveOut::where('del_time',0)
+            ->select($field)
+            ->orderby('id', 'desc');
+
+        if(! empty($data['employee_id_1_title'])) $model->where('employee_id_1_title', 'LIKE', '%'.$data['employee_id_1_title'].'%');
+        if(! empty($data['send_time'][0]) && ! empty($data['send_time'][1])) {
+            $return = $this->changeDateToTimeStampAboutRange($data['send_time']);
+            $model->where('send_time','>=',$return[0]);
+            $model->where('send_time','<=',$return[1]);
+        }
+        if(! empty($data['belong_time'][0]) && ! empty($data['belong_time'][1])) {
+            $return = $this->changeDateToTimeStampAboutRange($data['belong_time']);
+            $model->where('start_time','>=',$return[0]);
+            $model->where('end_time','<=',$return[1]);
+        }
+
+        return $model;
+    }
+
+    public function giveOutList($data,$user){
+        $model = $this->giveOutCommon($data, $user);
+        $list = $this->limit($model,'',$data);
+        $list = $this->fillData($list,$user,$data);
+
+        return [true, $list];
+    }
+
+    public function giveOutRule(&$data, $user, $is_add = true){
+        if(empty($data['give_out_amount'])) return [false, '分红已发金额不能为空'];
+        $res = $this->checkNumber($data['give_out_amount'],2,'positive');
+        if(! $res['valid']) return [false,'分红已发金额:' . $res['error']];
+        if(empty($data['employee_id_1'])) return [false, '业务员不能为空'];
+        $employee = Employee::where('del_time',0)
+            ->where('id',$data['employee_id_1'])
+            ->first();
+        if(empty($employee)) return [false, '业务员不存在或已被删除'];
+        $data['employee_id_1_title'] = $employee->emp_name;
+
+        if(empty($data['send_time'])) return [false, '发放日期不能为空'];
+        $data['send_time'] = $this->changeDateToDate($data['send_time']);
+        if($data['send_time'] == null) return [false, '发放日期错误'];
+
+        if(empty($data['belong_time'])) return [false, '归属日期不能为空'];
+        list($start_time,$end_time) = $this->changeDateToTimeStampAboutRange($data['belong_time'], false);
+        if ($start_time === null || $end_time === null || $start_time > $end_time) return [false, "归属日期的区间无效"];
+        $data['start_time'] = $start_time;
+        $data['end_time'] = $start_time;
+
+        if($is_add){
+
+        }else{
+            if(empty($data['id'])) return [false,'ID不能为空'];
+            $bool = GiveOut::where('id',$data['id'])
+                ->where('del_time',0)
+                ->exists();
+            if(! $bool) return [false,'发放记录不存在或已被删除'];
+        }
+
+        return [true, $data];
+    }
+
+    public function fillData($data, $user, $search){
+        if(empty($data['data'])) return $data;
+
+        foreach ($data['data'] as $key => $value){
+            $data['data'][$key]['send_time'] = $value['send_time'] ? date('Y-m-d',$value['send_time']) : '';
+            $start = $value['start_time'] ? date('Y-m-d',$value['start_time']) : '';
+            $end = $value['end_time'] ? date('Y-m-d',$value['end_time']) : '';
+            $string = "";
+            if(! empty($start) && ! empty($end)) $string = $start . "-" . $end;
+            $data['data'][$key]['belong_time'] = $string;
+        }
+
+        return $data;
+    }
+}

+ 0 - 31
app/Service/Service.php

@@ -495,37 +495,6 @@ class Service
         return $result;
     }
 
-    public function getDepart($user){
-        if(empty($user)) return 0;
-        return $user['depart_select']['depart_id'];
-    }
-
-    public function getMyTopDepart($user, $get_title = false){
-        if(empty($user)) return 0;
-        //当前门店
-        $current_top_depart_id = $user['depart_top'][0] ?? [];
-        if($get_title){
-            $current_top_depart_title = $current_top_depart_id['title'] ?? "";
-            return $current_top_depart_title;
-        }else{
-            $current_top_depart_id = $current_top_depart_id['depart_id'] ?? 0;
-            return $current_top_depart_id;
-        }
-    }
-
-    public function returnOrderEditErrorCommon($current_top_depart_id, $order_top_depart_id){
-        if($current_top_depart_id != $order_top_depart_id){
-            $depart_map = Depart::whereIn('id', [$current_top_depart_id, $order_top_depart_id])
-                ->pluck('title', 'id')
-                ->toArray();
-            $current_top_depart_title = $depart_map[$current_top_depart_id] ?? "";
-            $order_top_depart_title = $depart_map[$order_top_depart_id] ?? "";
-            return [false, "单据所属门店:" . $order_top_depart_title . ",当前所在门店:" . $current_top_depart_title . ",操作失败"];
-        }
-
-        return [true, ''];
-    }
-
     public function getTopId($id, $data) {
         foreach ($data as $item) {
             if ($item['id'] == $id) {

+ 7 - 0
routes/api.php

@@ -102,6 +102,13 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('freightDel', 'Api\FreightController@freightDel');
     $route->any('freightDetail', 'Api\FreightController@freightDetail');
 
+    //发放
+    $route->any('giveOutList', 'Api\GiveOutController@giveOutList');
+    $route->any('giveOutEdit', 'Api\GiveOutController@giveOutEdit');
+    $route->any('giveOutAdd', 'Api\GiveOutController@giveOutAdd');
+    $route->any('giveOutDel', 'Api\GiveOutController@giveOutDel');
+    $route->any('giveOutDetail', 'Api\GiveOutController@giveOutDetail');
+
     //获取默认表头
     $route->any('getTableHead','Api\TableHeadController@tableHeadGet');
     //设置表头