Browse Source

发货记录

afa 5 months ago
parent
commit
a9bef9e81f

+ 104 - 0
app/admin/controller/shop/Customer.php

@@ -7,6 +7,7 @@ use app\common\controller\Backend;
 use think\annotation\route\Group;
 use think\annotation\route\Route;
 use app\admin\traits\Actions;
+use think\facade\Db;
 use app\common\model\Customer as CustomerModel;
 
 #[Group("shop/customer")]
@@ -20,6 +21,109 @@ class Customer extends Backend
         $this->model = new CustomerModel();
     }
 
+    /**
+     * 添加
+     */
+    #[Route('GET,POST','add')]
+    public function add()
+    {
+        if (false === $this->request->isPost()) {
+            return $this->fetch();
+        }
+        $params = array_merge($this->request->post("row/a"),$this->postParams);
+        if (empty($params)) {
+            $this->error(__('提交的参数不能为空'));
+        }
+        if(!$this->request->checkToken('__token__',['__token__'=>$this->request->post('__token__')])){
+            $this->error(__('token错误,请刷新页面重试'));
+        }
+        foreach ($params as &$value){
+            if(is_array($value)){
+                $value=implode(',',$value);
+            }
+            if($value===''){
+                $value=null;
+            }
+        }
+        if($params['account_term'] == 2 && empty($params['cycle'])) $this->error(__('请选择周结日期'));
+        $result = false;
+        Db::startTrans();
+        try {
+            $result = $this->model->save($params);
+            if($this->callback){
+                $callback=$this->callback;
+                $callback($this->model);
+            }
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if ($result === false) {
+            $this->error(__('没有新增任何数据'));
+        }
+        $this->success();
+    }
+
+    /**
+     * 编辑
+     */
+    #[Route('GET,POST','edit')]
+    public function edit(mixed $row=null)
+    {
+        $ids = $this->request->get('ids');
+        if(!$row || is_array($row)){
+            $row = $this->model->find($ids);
+        }
+        if (!$row) {
+            $this->error(__('没有找到记录'));
+        }
+        if(count($this->volidateFields)>0){
+            foreach ($this->volidateFields as $field=>$value){
+                if($row[$field]!=$value){
+                    $this->error(__('没有操作权限'));
+                }
+            }
+        }
+        if (false === $this->request->isPost()) {
+            $this->assign('row', $row);
+            return $this->fetch();
+        }
+        $params = array_merge($this->request->post("row/a"),$this->postParams);
+        if (empty($params)) {
+            $this->error(__('提交的参数不能为空'));
+        }
+        if(!$this->request->checkToken('__token__',['__token__'=>$this->request->post('__token__')])){
+            $this->error(__('token错误,请刷新页面重试'));
+        }
+        foreach ($params as &$value){
+            if(is_array($value)){
+                $value=implode(',',$value);
+            }
+            if($value===''){
+                $value=null;
+            }
+        }
+        if($params['account_term'] == 2 && empty($params['cycle'])) $this->error(__('请选择周结日期'));
+        $result = false;
+        Db::startTrans();
+        try {
+            $result = $row->save($params);
+            if($this->callback){
+                $callback=$this->callback;
+                $callback($row);
+            }
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if (false === $result) {
+            $this->error(__('没有数据被更新'));
+        }
+        $this->success();
+    }
+
 
   
     

+ 32 - 1
app/admin/controller/shop/ShopDelivery.php

@@ -7,6 +7,7 @@ use app\common\controller\Backend;
 use think\annotation\route\Group;
 use app\admin\traits\Actions;
 use think\annotation\route\Route;
+use think\facade\Db;
 use app\common\model\ShopDelivery as ShopDeliveryModel;
 
 #[Group("shop/shop_delivery")]
@@ -45,7 +46,7 @@ class ShopDelivery extends Backend
             ->paginate($limit);
 
         //表格底部要有汇总:发货数量汇总  重量汇总 总价汇总
-        $count = $this->model->field('sum(num) total_num, sum(weigh) total_weigh, sum(total_price) total_price')->select()->toArray();
+        $count = $this->model->withJoin($with,'left')->where($where)->field('sum(num) total_num, sum(weigh) total_weigh, sum(total_price) total_price')->select()->toArray();
 
         $result = ['total' => $list->total(), 'rows' => $list->items(), 
         'total_num'    => $count[0]['total_num']??0, 
@@ -53,4 +54,34 @@ class ShopDelivery extends Backend
         'total_price'  => $count[0]['total_price']??0];
         return json($result);
     }
+
+
+
+    /**
+     * 结算
+     */
+    #[Route('GET,POST','settlement')]
+    public function settlement()
+    {
+       
+        $ids =$this->request->post('ids/a', []);
+        if(empty($ids)) return resp_json(0, '请选着要结算记录');
+        $result = false;
+        Db::startTrans();
+        try {
+            $result = $this->model->whereIn('id', $ids)->save(['status'=>$this->model::StatusSettlement]);
+            if($this->callback){
+                $callback=$this->callback;
+                $callback($this->model);
+            }
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if ($result === false) {
+            $this->error(__('没有新增任何数据'));
+        }
+        return resp_json(200,'操作成功');
+    }
 }

+ 14 - 0
app/admin/service/curd/controller-normal.txt

@@ -43,6 +43,9 @@ class <#controllerName#> extends Backend
         <#if isset(actionList['recyclebin'])#>
         recyclebin as private _recyclebin;
         <#endif#>
+        <#if isset(actionList['settlement'])#>
+        settlement as private _settlement;
+        <#endif#>
     }
     <#endif#>
 
@@ -207,6 +210,17 @@ class <#controllerName#> extends Backend
     }
     <#endif#>
     <#if methods#>
+
+    <#if table && isset(actionList['settlement'])#>
+    //结算
+    #[Route("GET,POST","settlement")]
+    public function settlement()
+    {
+        //通过定义callback回调函数来执行删除后的操作
+        $this->callback=function ($ids){};
+        return $this->_settlement();
+    }
+    <#endif#>
 <#methods#>
     <#endif#>
 }

+ 3 - 0
app/admin/service/curd/view-index.txt

@@ -51,6 +51,9 @@
                     <#if in_array('recyclebin',toolbar)#>
                     recyclebin:{:$auth->check('<#controller#>','recyclebin')},
                     <#endif#>
+                     <#if in_array('settlement',toolbar)#>
+                    settlement:{:$auth->check('<#controller#>','settlement')},
+                    <#endif#>
                 }"
                 :extend="extend">
                 <#if expand#>

+ 19 - 5
app/admin/view/shop/customer/add.html

@@ -1,6 +1,13 @@
 <template>
     <el-card shadow="never" style="border: 0;">
-        <yun-form :data="row" :columns="columns">
+        <yun-form 
+           ref="yunform"
+            @render="onFormRender"
+            @submit="onSubmit"
+            @success="onSuccess"
+            @fail="onFail"
+            :data="row"
+            :columns="columns">
             {:token_field()}
         </yun-form>
     </el-card>
@@ -16,15 +23,22 @@
                 {field: 'name',title: __('姓名'),edit:'text',rules:'required'},
                 {field: 'phone',title: __('手机'),edit:'text',rules:'mobile'},
                 {field: 'password',title: __('密码'),edit:'text',rules:'required;length(6, 20)'},
-                {field: 'account_term', title: __('账期'), edit: 'radio',rules:"required",searchList: {1: __('日结'), 2: __('周结'), 3: __('半月结')}},
+                {field: 'account_term', title: __('账期'), edit: {form:'radio',change:'changeType'},rules:"required",searchList: {1: __('日结'), 2: __('周结'), 3: __('半月结')}},
+                {field: 'cycle', title: __('周结日期'), visible: false, edit: 'radio',searchList: {1: __('周一'), 2: __('周二'), 3: __('周三'),4: __('周四'), 5: __('周五'), 6: __('周六'), 7: __('周日')}},
                 {field: 'remark',title: __('备注'),edit:'textarea'},
                 {field: 'status', title: __('状态'), edit:'switch',searchList: {1: __('正常'),2: __('隐藏')}},
             ]
         },
         methods: {
-
-        
-        }
+            changeType:function(data,row){
+                if(data == 2){
+                    this.$refs.yunform.showField("cycle")//为表单项设置值
+                }else{
+                    this.$refs.yunform.hideField('cycle');//为表单项设置值
+                }
+            },
+        },
+       
     }
 </script>
 <style>

+ 51 - 1
app/admin/view/shop/customer/edit.html

@@ -1 +1,51 @@
-{include vue="shop/customer/add" /}
+<template>
+    <el-card shadow="never" style="border: 0;">
+        <yun-form 
+           ref="yunform"
+            @render="onFormRender"
+            @submit="onSubmit"
+            @success="onSuccess"
+            @fail="onFail"
+            :data="row"
+            :columns="columns">
+        >
+            {:token_field()}
+        </yun-form>
+    </el-card>
+</template>
+<script>
+    import form from "@components/Form.js";
+    export default{
+        components:{'YunForm':form},
+        data:{
+            row:Yunqi.data.row,
+            columns:[
+                {field: 'id',title: __('ID'),edit:'hidden'},
+                {field: 'name',title: __('姓名'),edit:'text',rules:'required'},
+                {field: 'phone',title: __('手机'),edit:'text',rules:'mobile'},
+                {field: 'password',title: __('密码'),edit:'text',rules:'required;length(6, 20)'},
+                {field: 'account_term', title: __('账期'), edit: {form:'radio',change:'changeType'},rules:"required",searchList: {1: __('日结'), 2: __('周结'), 3: __('半月结')}},
+                {field: 'cycle', title: __('周结日期'), visible: false, edit: 'radio',
+                    visible:function(row){
+                        return row.account_term=='2';
+                    },
+                searchList: {1: __('周一'), 2: __('周二'), 3: __('周三'),4: __('周四'), 5: __('周五'), 6: __('周六'), 7: __('周日')}},
+                {field: 'remark',title: __('备注'),edit:'textarea'},
+                {field: 'status', title: __('状态'), edit:'switch',searchList: {1: __('正常'),2: __('隐藏')}},
+            ]
+        },
+        methods: {
+            changeType:function(data,row){
+                if(data == 2){
+                    this.$refs.yunform.showField("cycle")//为表单项设置值
+                }else{
+                    this.$refs.yunform.hideField('cycle');//为表单项设置值
+                }
+            },
+        },
+     
+    }
+</script>
+<style>
+
+</style>

+ 60 - 11
app/admin/view/shop/shop_delivery/index.html

@@ -4,7 +4,7 @@
         <yun-table
                 :columns="columns"
                 search="name,phone"
-                toolbar="refresh,add,edit,del,more"
+                toolbar="refresh,settlement"
                 ref="yuntable"
                 :auth="auth"
                 :extend="extend"
@@ -13,7 +13,16 @@
                 :is-showtotal="true"
                 @data-loaded="handleData"
                 >
+                <template #toolbar="{tool}">
+                    <template v-if="tool=='settlement'">
+                            <el-button type="primary" @click="createAddon">
+                                结算
+                            </el-button>
+
+                        </template>
+                </template>
         </yun-table>
+         
     </el-card>
 </template>
 <script>
@@ -21,6 +30,7 @@
     export default{
         components:{'YunTable':table},
         data:{
+            checkedKey:[],
             auth:{
                 recyclebin:Yunqi.auth.check('app\\admin\\controller\\shop\\ShopList','recyclebin'),
             },
@@ -29,22 +39,30 @@
                 recyclebin_url: 'shop/shop_delivery/recyclebin',
             },
             columns:[
-                {checkbox: true},
-                {field: 'id',title: __('ID'),width:80,sortable: true},
+                {checkbox: true,selectable:function (row,index){
+                    if(row.status != 1){
+                        return false;
+                    }
+                    return true;
+                }},
+                {field: 'id',title: __('ID'),width:80,sortable: true, operate: false},
                 {field: 'customer.name',title: __('客户'),operate:'LIKE'},
-                {field: 'plat_id',title: __('平台'),operate: false, searchList: Yunqi.data.platformList},
+                {field: 'plat_id',title: __('平台'), operate: 'select', searchList: Yunqi.data.platformList},
                 {field: 'shops.name',title: __('店铺'),operate:'LIKE'},
-                {field: 'variety.title', title: __('品种'),operate: false},
-                {field: 'specs.title', title: __('规格'),operate: false},
-                {field: 'num', title: __('数量'),operate: false},
+                {field: 'variety.title', title: __('品种'),operate: 'LIKE'},
+                {field: 'specs.title', title: __('规格'),operate: 'LIKE'},
+                {field: 'num', title: __('数量'),operate: '='},
                 {field: 'weigh', title: __('重量'),operate: false},
                 {field: 'price', title: __('发货价'),operate: false},
                 {field: 'total_price', title: __('总价'),operate: false},
-                {field: 'settlement_data', title: __('结算时间'), width:160,formatter: Yunqi.formatter.datetime,operate:false,sortable: true},
-                {field: 'status', title: __('结算状态'),width:120,searchList: {1: __('待结算'),2: __('已结算'), 3: __('驳回')},formatter:Yunqi.formatter.switch},
+                {field: 'ship_date', title: __('录入时间'), width:120, operate:"date" },
+                {field: 'settlement_data', title: __('结算时间'),width: 120,operate:'date', formatter(value, row, index) {
+                    if(value ==0)  return "-";
+                    return value;
+                }},
+                {field: 'status', title: __('结算状态'), operate: 'select', width:120,searchList: {1: __('待结算'),2: __('已结算')},formatter:Yunqi.formatter.tag},
                 {field: 'createtime', title: __('创建时间'), width:160,formatter: Yunqi.formatter.datetime,operate:false,sortable: true},
-                {field: 'user.nickname', title: __('录入人'),operate: 'LIKE'},
-           
+                {field: 'user.nickname', title: __('录入人'),operate: false},
             ],
             totalArr: [
                 
@@ -64,6 +82,37 @@
                         value: data.total_price
                     },
                 ]
+            },
+            createAddon() {
+               
+                let ids=[];
+                let checks = this.$refs.yuntable.selections;
+                for (var key in Object(checks)) {
+                    ids.push(checks[key]['id'])
+                }
+                if(ids.length == 0){
+                    this.$message({type: 'error', message: '请选择要结算的记录'});
+                    return
+                }
+                this.$confirm('一旦结算将不可撤回', '提示', {
+                    confirmButtonText: '确定',
+                    cancelButtonText: '取消',
+                    type: 'warning'
+                    }).then((res) => {
+                        Yunqi.ajax.post('shop/shop_delivery/settlement', {ids: ids }, false, false, true).then(res => {
+                            if (res.code == 200) {
+                                this.$message.success(__('结算成功'));
+                                this.$refs.yuntable.reload();
+                            } else {
+                                this.$message.error(res.msg);
+                                return false;
+                            }
+                        });
+                       
+                    }).catch(() => {
+                        this.$message({ type: 'info', message: '已取消结算'});          
+                });
+              
             }
         },
     

+ 1 - 3
app/admin/view/shop/shop_list/specs.html

@@ -77,9 +77,7 @@
             },
             onSubmit() {
                 //获取规格
-                console.log(this.tableData, "==========111")
-                console.log(boxList, "==========22")
-
+              
                 if (this.tableData == "" || boxList.length == 0) return
                 Yunqi.ajax.post('shop/shop_list/specs', { ids: Yunqi.data.row.id,  variety: boxList, type_box: this.tableData }, false, false, true).then(res => {
                     if (res.code == 200) {

+ 8 - 0
app/api/common.php

@@ -26,4 +26,12 @@ function getDaysOfYear($year)
 }
 
 
+function getNextWeekDates($date,$day) {
+	// 定义日期
+    $formats = [7 => 'sunday', 1 => 'monday', 2 => 'tuesday', 3 => 'wednesday', 4 => 'thursday', 5 => 'friday', 6 => 'saturday'];
+	$nextWeekDate = date('Y-m-d', strtotime("next $formats[$day]", strtotime($date)));
+    return $nextWeekDate;
+}
+
+
 

+ 1 - 1
app/api/controller/Shops.php

@@ -44,7 +44,7 @@ class Shops extends Base
                 ->leftjoin('stock_config c', 'a.variety_id = c.id') //品种
                 ->leftjoin('product_config d', 'a.spec_id = d.id') //规格
                 ->leftjoin('customer u', 'a.customer_id = u.id') //客户
-                ->field('a.id,a.plat_id,a.shop_id,a.createtime,a.num, b.name shop_name,c.title variety_name,d.title spec_name,u.name customer_name')
+                ->field('a.id,a.plat_id,a.shop_id,a.ship_date,a.settlement_data,a.createtime,a.num, b.name shop_name,c.title variety_name,d.title spec_name,u.name customer_name')
                 ->where($where)
                 ->order('a.id desc')
                 ->paginate($limit);

+ 24 - 2
app/api/service/SpecService.php

@@ -44,7 +44,11 @@ class SpecService{
       {     
             $result = [];
             $stockData = [];
-            $customer_id = ShopList::where('id', $data['shop_id'])->value('customer_id');
+            //获取店铺客户信息
+            $customer = ShopList::getCustomerByShopId((int)$data['shop_id']);
+            if(!$customer) throw new \Exception('店铺客户信息不存在!');
+            //结算周期
+            $settlement_data = SpecService::getDeliverySettlement($customer, $data['ship_date']);
             foreach ($data['variety'] as $item) {
                   if(count($item) != 6 || empty(floatval($item['num'])))  throw new \Exception('参数有误!');
                   $specs = ProductConfig::where('id', $item['spec_id'])->field('weight,box_id')->find();
@@ -52,7 +56,7 @@ class SpecService{
                   $weight = bcmul((string)$specs->weight, $item['num'], 2);
                   $result[] = [
                         'user_id'         => $uid, 
-                        'customer_id'     => $customer_id,
+                        'customer_id'     => $customer->id,
                         'shop_id'         => $data['shop_id'],
                         'plat_id'         => $data['plat_id'],
                         'variety_id'      => $item['variety_id'],
@@ -60,6 +64,8 @@ class SpecService{
                         'num'             => $item['num'],
                         'weigh'           => $weight,
                         'price'           => $item['price'],
+                        'ship_date'       => $data['ship_date'],
+                        'settlement_data' => $settlement_data,
                         'total_price'     => bcmul($item['price'], $item['num'], 2)
                   ];
               
@@ -144,4 +150,20 @@ class SpecService{
             return $delivery->delete();
       }
    
+      //结算周期
+      public static function getDeliverySettlement(object $customer, string $ship_date)
+      {     
+            $result = $ship_date;
+            switch ($customer->account_term) {
+                  case 2:
+                        $result = getNextWeekDates($ship_date, $customer->cycle);
+                        break;
+                  case 3:
+                        $result = date('Y-m-d', strtotime($ship_date . ' +15 days'));
+                        break;
+            }
+            return  $result; 
+     
+      }
+      
 }

+ 4 - 2
app/api/validate/Shop.php

@@ -11,6 +11,7 @@ class Shop extends Validate
         'variety'  => 'require',
         'ids'      => 'require',
         'num'      => 'require|gt:0',
+        'ship_date' => 'require',
     ];
     
     protected $message  =   [
@@ -18,13 +19,14 @@ class Shop extends Validate
         'shop_id'     => '参数有误',
         'variety'     => '参数有误',  
         'ids'     => '参数有误', 
-        'num'     => '参数有误',   
+        'num'     => '参数有误',
+        'ship_date' => '参数有误',
     ];
 
 
  
     protected $scene = [
-        'add'  =>  ['plat_id','shop_id','variety'],
+        'add'  =>  ['plat_id','shop_id','variety', 'ship_date'],
         'edit' =>  ['ids','num'],
         'del'  =>  ['ids'],
     ]; 

+ 0 - 2
app/common/model/MoneyLog.php

@@ -92,8 +92,6 @@ class MoneyLog Extends Model
                 ->group('create_date')
                 ->field('create_date, sum(if(type=1,`change`,0)) as income, sum(if(type=2,`change`, 0)) as expenditure')
                 ->select();
-
-    
         return $list;
     }
 

+ 2 - 2
app/common/model/ShopDelivery.php

@@ -57,7 +57,7 @@ class ShopDelivery Extends Model
     
     public function variety()
     {
-        return $this->hasOne(StockConfig::class,'id','variety_id')->field('id,name');
+        return $this->hasOne(StockConfig::class,'id','variety_id')->field('id,title');
     }
 
 
@@ -65,7 +65,7 @@ class ShopDelivery Extends Model
     
     public function specs()
     {
-        return $this->hasOne(ProductConfig::class,'id','spec_id')->field('id,name');
+        return $this->hasOne(ProductConfig::class,'id','spec_id')->field('id,title');
     }
 
  

+ 13 - 0
app/common/model/ShopList.php

@@ -22,4 +22,17 @@ class ShopList Extends Model
             return $this->hasOne(User::class,'id','staff_id');
       }
 
+
+
+      //获取店铺客户信息
+      public static function getCustomerByShopId(int $shop_id): object
+      {
+            return self::alias('a')
+            ->where('a.id', $shop_id)
+            ->leftjoin('customer b', 'a.customer_id = b.id')
+            ->field('b.id, b.account_term,b.cycle')
+            ->find();
+      }
+
+   
 }

+ 1 - 1
runtime/admin/temp/40e652717b47d0a4376e9a58093820fb-js.php

@@ -1,4 +1,4 @@
-<?php /*a:2:{s:69:"D:\phpEnv\www\Gong-Ying-Lian-API\app\admin\view\auth\group\index.html";i:1750736984;s:63:"D:\phpEnv\www\Gong-Ying-Lian-API\app\admin\view\layout\vue.html";i:1750736984;}*/ ?>
+<?php /*a:2:{s:69:"D:\phpEnv\www\Gong-Ying-Lian-API\app\admin\view\auth\group\index.html";i:1751866917;s:63:"D:\phpEnv\www\Gong-Ying-Lian-API\app\admin\view\layout\vue.html";i:1751866917;}*/ ?>
 
 import table from "http://yun.cn/assets/js/components/Table.js";
 import {inArray} from "http://yun.cn/assets/js/util.js";

+ 1 - 1
runtime/admin/temp/40e652717b47d0a4376e9a58093820fb.php

@@ -1,4 +1,4 @@
-<?php /*a:2:{s:69:"D:\phpEnv\www\Gong-Ying-Lian-API\app\admin\view\auth\group\index.html";i:1750736984;s:63:"D:\phpEnv\www\Gong-Ying-Lian-API\app\admin\view\layout\vue.html";i:1750736984;}*/ ?>
+<?php /*a:2:{s:69:"D:\phpEnv\www\Gong-Ying-Lian-API\app\admin\view\auth\group\index.html";i:1751866917;s:63:"D:\phpEnv\www\Gong-Ying-Lian-API\app\admin\view\layout\vue.html";i:1751866917;}*/ ?>
 <!DOCTYPE html>
 <html <?php if($config['elementUi']['dark']): ?>class="dark"<?php endif; ?>>
 <head>

File diff suppressed because it is too large
+ 0 - 0
runtime/cache/7a/b2b683b6c3e8e0985917962d853b9c.php


Some files were not shown because too many files changed in this diff