Selaa lähdekoodia

【Add】余额记录

liuxiangxin 4 kuukautta sitten
vanhempi
sitoutus
68ac8413ea

+ 75 - 0
app/Http/Controllers/Admin/AmountRecord.php

@@ -0,0 +1,75 @@
+<?php namespace App\Http\Controllers\Admin;
+
+use App\Models\Custom as Custom;
+use Illuminate\Support\Carbon;
+use App\Models\Amount\Record as Model;
+
+/**
+ * 余额记录
+ *
+ * @author    jun
+ *
+ */
+class AmountRecord extends Auth{
+
+	protected function _initialize(){
+		parent::_initialize();
+		$this->assign('breadcrumb1','余额管理');
+		$this->assign('breadcrumb2','余额记录');
+	}
+
+	/**
+	 * 列表页
+	 * 
+	 * */
+    public function index(Model $Model,Custom $Custom){
+ 		// 接受参数
+		$code					= request('custom_code','');
+		$phone					= request('phone','');
+		$username				= request('username','');
+		$status					= request('status');
+		$startTime				= request('start_time','');
+		$endTime				= request('end_time','');
+		// 编码转ID
+		$uid					= $Custom->codeToId($code);
+		// 查询条件
+		$map 					= [];
+		// 编码ID
+		if( $uid )				$map[] = ['custom.uid','=',$uid];
+		if( $phone )			$map[] = ['custom.phone','=',$phone];
+		if( $username )			$map[] = ['custom.username','=',$username];
+		if( $startTime )		$map[] = ['amount_record.insert_time','>=',Carbon::createFromFormat('Y-m-d',$startTime)->startOfDay()->getTimestamp()];
+		if( $endTime )		    $map[] = ['amount_record.insert_time','<=',Carbon::createFromFormat('Y-m-d',$endTime)->endOfDay()->getTimestamp()];
+		if( !is_null($status) )	$map[] = ['amount_record.status','=',$status];
+		// 查询数据
+		$list					= $Model->query()
+                                    ->leftJoin('custom','custom.uid','=','amount_record.custom_uid')
+                                    ->where($map)
+                                    ->select(['amount_record.*','custom.username'])
+                                    ->orderByDesc('amount_record.id')
+                                    ->paginate(config('page_num',10))
+                                    ->appends(request()->all());
+		// 循环处理数据
+		foreach ($list as $key => $value) {
+			// id转编号
+			$value['custom_code'] 	= $Custom->idToCode($value['custom_uid']);
+            $value['buy_type']      = $Model->getBuyType($value['buy_type'],'name');
+			// 重组
+			$list[$key]				= $value;
+		}
+		// 分配数据
+		$this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
+		$this->assign('list',$list);
+		// 加载模板
+		return 						$this->fetch();
+    }
+
+    /**
+     * 导出表格
+     *
+     * */
+    public function down_excel(Model $Model,Custom $Custom){
+        
+
+    }
+}

+ 46 - 0
app/Http/Requests/Admin/Amount/Record.php

@@ -0,0 +1,46 @@
+<?php namespace App\Http\Requests\Admin\Amount;
+
+use App\Http\Requests\BaseRequest;
+
+/**
+ * 发放规则验证器
+ * 
+ */
+class Record extends BaseRequest
+{
+    /**
+     * 获取应用于请求的规则
+     *
+     * @return array
+     */
+    public function rules()
+    {
+        // 返回结果
+        return      [
+            // 有时候我们希望某个字段在第一次验证失败后就停止运行验证规则,只需要将 bail 添加到规则中:
+            // 验证字段,验证规则,提示信息
+	        'id'                => 'required|integer|gt:0',
+        ];
+    }
+
+    
+    // 场景列表
+    protected   $scenes         = [
+        'set_status'  		    => ['id'],
+	];
+
+    /**
+     * 获取已定义验证规则的错误消息
+     *
+     * @return array
+     */
+    public function messages()
+    {
+        return [
+            'id.required'       => 'ID未知',
+            'id.integer'        => 'ID格式错误',
+            'id.gt'   		    => 'ID格式错误',
+        ];
+    }
+    
+}

+ 55 - 0
app/Models/Amount/Record.php

@@ -0,0 +1,55 @@
+<?php namespace App\Models\Amount;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+use App\Models\Traits\Amount\BuyType;
+/**
+ * 发放规则模型
+ * 
+ */
+class Record extends Model
+{
+    use HasFactory,BuyType;
+
+    // 与模型关联的表名
+    protected   $table = 'amount_record';
+    // 是否主动维护时间戳
+    public      $timestamps = false;
+    // 定义时间戳字段名
+    // const CREATED_AT = 'insert_time';
+    // const UPDATED_AT = 'update_time';
+
+    /**
+     * 添加数据
+     * 
+     */
+    public function add($data)
+    {
+        // 时间
+        $data['insert_time']				= time();
+        $data['update_time']				= time();
+        // 写入数据表
+        $id						            = $this->query()->insertGetId($data);
+        // 如果操作失败
+        if( !$id )                          return $id;
+        // 返回结果
+        return                              $id;
+    }
+
+    /**
+     * 添加数据
+     * 
+     */
+    public function edit($id,$data)
+    {
+        // 更新时间
+        $data['update_time']                = time();
+        // 写入数据表
+        $result						        = $this->query()->where(['id'=>$id])->update($data);
+        // 如果操作失败
+        if( !$result )                      return $result;
+        // 返回结果
+        return                              $result;
+    }
+
+}

+ 81 - 0
app/Models/Traits/Amount/BuyType.php

@@ -0,0 +1,81 @@
+<?php
+
+namespace App\Models\Traits\Amount;
+
+/**
+ * 交易类型
+ * 交易类型 与 支付方式  用于余额记录 (需与订单的buy_type购买类型严格区分,即与订单信息中的的buy_type购买类型无关)
+ * 
+ */
+trait BuyType
+{
+
+    // 交易类型  与 支付方式
+    private     $buyType        =   ['1'=>[
+                                        'id'            =>1,
+                                        // 类型名称
+                                        'name'          =>'系统操作',
+                                        // 支付方式  方式名称
+                                        'pay_type'      =>['1'=>['id'=>1,'name'=>'系统操作']],
+                                    ],'2'=>[
+                                        'id'            =>2,
+                                        // 类型名称
+                                        'name'          =>'红包奖励',
+                                        // 支付方式  方式名称
+                                        'pay_type'  =>['1'=>['id'=>1,'name'=>'红包奖励']],
+                                    ],'3'=>[
+                                        'id'            =>3,
+                                        // 类型名称
+                                        'name'          =>'余额提现',
+                                        // 支付方式  方式名称
+                                        'pay_type'  =>['1'=>['id'=>1,'name'=>'余额提现']],
+                                    ]];
+
+    /**
+     * 交易类型列表
+     * 
+     */
+    public function getBuyTypeList(){
+        // 返回数据
+        return                  $this->buyType;
+    }
+
+    /**
+     * 获取支付方式
+     * 
+     * @param Int       $buyTid     交易类型 ID
+     * @param Int       $payTid     支付方式 ID
+     * @param String    $field      字段
+     * 
+     */
+    public function getPayType($buyTid,$payTid,$field=''){
+        // 获取数据
+        $payList            = (array) $this->getBuyType($buyTid,'pay_type');
+        // 循环数据
+        $payType            = isset($payList[$payTid]) ? $payList[$payTid] : [];
+        // 如果支付类型未传
+        if( $field )        return isset($payType[$field]) ? $payType[$field] : null;
+        // 名称
+        return              $payType;
+    }
+
+    /**
+     * 获取交易类型
+     * 
+     * @param Int       $buyTid     交易类型 ID
+     * @param String    $field      字段
+     * 
+     */
+    public function getBuyType($buyTid,$field=''){
+        // 获取数据
+        $buyType            = [];
+        // 获取交易类型
+        $buyType            = isset($this->buyType[$buyTid]) ? $this->buyType[$buyTid] : [];
+        // 如果存在需要的字段
+        if( $field )        return isset($buyType[$field]) ? $buyType[$field] : null;
+        // 返回结果
+        return              $buyType;
+    }
+
+
+}

+ 71 - 0
resources/views/admin/amount_record/index.blade.php

@@ -0,0 +1,71 @@
+@extends('admin.public.base')
+@section('body_class')
+style="margin: 0 auto;width: 96%;padding: 30px 0px;"
+@endsection
+@section('content')
+
+<form action="" method="get" class="form-horizontal form-line" name="thisform">
+	<div class="form-group col col-lg-2 col-md-4 col-sm-6 col-xs-12" style="margin-right: 2px;">
+		<input type="text" class="form-control" name="custom_code" value="{{request('custom_code','')}}" placeholder="请输入客户编码" />
+	</div>
+	<div class="form-group col col-lg-2 col-md-4 col-sm-6 col-xs-12" style="margin-right: 2px;">
+		<input type="text" class="form-control" name="custom_name" value="{{request('custom_name','')}}" placeholder="请输入客户名称查询" />
+	</div>
+	<div class="form-group col col-lg-2 col-md-4 col-sm-6 col-xs-12" style="margin-right: 2px;">
+		<input type="date" class="form-control" name="start_time" value="{{request('start_time','')}}" placeholder="请输入开始时间查询" />
+	</div>
+	<div class="form-group col col-lg-2 col-md-4 col-sm-6 col-xs-12" style="margin-right: 2px;">
+		<input type="date" class="form-control" name="end_time" value="{{request('end_time','')}}" placeholder="请输入结束查询" />
+	</div>
+	<input type="submit" class="btn btn-sm btn-primary" value="查询"/>
+	<a href="{{url('admin/amount_record/index')}}" class="btn btn-sm btn-default" >重置</a>
+	@if( check_auth('admin/amount_record/down_excel') )
+		<button type="button" onclick="alter_from_attr({'method':'get','action':`{{url('admin/amount_record/down_excel')}}`})" class="btn btn-sm btn-primary"> 下载</button>
+	@endif
+</form>
+
+<div class="row">
+	<div class="col-xs-12">	
+		<div class="table-responsive">
+			<table class="table table-striped table-bordered table-hover">
+				<thead>
+					<tr>
+						<th>记录ID</th>
+						<th>客户编码</th>
+						<th>客户名称</th>
+						<th>变动金额</th>
+						<th>剩余金额</th>
+						<th>交易类型</th>
+						<th>交易状态</th>
+						<th>修改时间</th>
+						<th>操作</th>
+					</tr>
+				</thead>
+				
+				<tbody>
+						@foreach ($list as $a)
+						<tr>
+							<th>{{$a['id']}}</th>
+							<th>{{$a['custom_code']}}</th>
+							<th>{{$a['custom_name']}}</th>
+							<th>{{$a['amount']}}</th>
+							<td>{{$a['balance']}}</td>
+							<td>{{$a['status']}}</td>
+							<td>{{$a['buy_type']}}</td>
+							<td> {{date('Y/m/d H:i:s',$a['update_time'])}}</td>
+							<td></td>
+						</tr>  
+						@endforeach
+						<tr>
+							<td colspan="20" class="page">{{$list->render()}}</td>
+						</tr>
+						<tr>
+							<td colspan="20">总计 {{$list->total()}} 个记录</td>
+						</tr>
+				</tbody>
+				
+			</table>
+		</div>
+	</div>
+</div>
+@endsection

+ 5 - 0
routes/web.php

@@ -561,4 +561,9 @@ Route::middleware('admin')->prefix('admin')->group(function(){
     // 状态
     Route::any('custom_redpacket/set_status',[App\Http\Controllers\Admin\CustomRedpacket::class,'set_status']);
 
+
+    /* 余额记录 */
+    // 余额
+    Route::any('amount_record/index',[App\Http\Controllers\Admin\AmountRecord::class,'index']);
+
 });