123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- <?php
- namespace App\Http\Controllers\Admin;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Validator;
- class ChargeController extends Controller
- {
- public function __construct()
- {
- }
- /* 缴费记录 */
- public function chargeList(Request $request){
- $where=[];
- $adminInfo=Auth::guard('admin')->user();
- if($adminInfo){
- $atis=$adminInfo->is_team;
- if($atis==2){
- $where['charge.team_id']=$adminInfo->team_id;
- }
- }
- $search_name = $request->search_name;
- $page_size = $request->page_size;
- $page_index = $request->page_index;
- $num = ($page_index - 1) * $page_size;
- $where['charge.status']=1;
- if(!empty($request->month)){
- $where['charge.month'] = date("Y-m",strtotime($request->month));
- }
- if(!empty($request->team_id)){
- $where['charge.team_id'] = $request->team_id;
- }
- $count = DB::table('charge')
- ->join('users', 'users.id', '=', 'charge.uid')
- ->leftJoin('team','team.id','=','charge.team_id')
- ->where(function ($query) use ($search_name) {
- $query->where('users.name', 'like', '%' . $search_name . '%')
- ->orWhere('users.telphone', 'like', '%' . $search_name . '%')
- ->orWhere('users.cre_num', 'like', '%' . $search_name . '%');
- })
- ->where($where)
- ->count();
- if ($count > 0) {
- $data = DB::table('charge')
- ->join('users', 'users.id', '=', 'charge.uid')
- ->leftJoin('team','team.id','=','charge.team_id')
- ->where(function ($query) use ($search_name) {
- $query->where('users.name', 'like', '%' . $search_name . '%')
- ->orWhere('users.telphone', 'like', '%' . $search_name . '%')
- ->orWhere('users.cre_num', 'like', '%' . $search_name . '%');
- })
- ->where($where)
- ->select('charge.id','users.name','users.telphone','users.cre_num','team.name as tname','team.id as tid','charge.fee', 'charge.status', 'charge.month', 'charge.pays_at','charge.type')
- ->orderBy('charge.id','desc')
- ->skip($num)->take($page_size)->get();
- if ($data) {
- $data=json_decode($data,true);
- foreach ($data as $key => $val) {
- $data[$key]['month'] = substr($val['month'], 0, 7);
- }
- return response()->json([
- 'error_code' => 200,
- 'msg' => '成功',
- 'data' => $data,
- 'count' => $count
- ]);
- } else {
- return response()->json([
- 'error_code' => 0,
- 'msg' => '获取失败'
- ]);
- }
- }else{
- return response()->json([
- 'error_code' => 200,
- 'msg' => '没有缴费信息',
- 'list' => [],
- 'count' => $count
- ]);
- }
- }
- /* 缴费 */
- public function payFee(Request $request){
- $input=$request->all();
- $rules=[
- 'name'=>'required|max:16',
- 'cre_num'=>'required|min:8|max:8',
- 'month'=>'required',
- 'fee'=>'required',
- ];
- $messages=[
- 'name.required'=>'缴费人名称不能为空.',
- 'name.max'=>'缴费人名称不能超过16个字符.',
- 'cre_num.required'=>'档案号不能为空.',
- 'cre_num.min'=>'档案号长度为8个字符.',
- 'cre_num.max'=>'档案号长度为8个字符.',
- 'month.required'=>'请选择缴费月份.',
- 'fee.required'=>'缴费金额不能为空.',
- ];
- $validator = Validator::make($input, $rules ,$messages);
- if($validator->fails()){
- return response()->json([
- 'error_code'=>'41113',
- 'msg'=>$validator->errors()->first()
- ]);
- }
- $where['name']=$input['name'];
- $where['cre_num']=$input['cre_num'];
- $where['del_is']=0;
- $teamId=DB::table('users')->where($where)->value('team_id');
- if(empty($teamId) || $teamId==0){
- return response()->json([
- 'error_code' => 0,
- 'msg' => '该用户没有支部,不能缴费'
- ]);
- }
- $adminInfo=Auth::guard('admin')->user();
- if($adminInfo){
- $atid=$adminInfo->team_id;
- $atis=$adminInfo->is_team;
- if($atis==2){
- if($teamId!=$atid){
- return response()->json([
- 'error_code' => 0,
- 'msg' => '该用户不属于本支部,不能缴费'
- ]);
- }
- }
- }
- $userId=DB::table('users')
- ->where($where)->value('id');
- if($userId){
- $count=DB::table('upload_commit_log')->where('uid',$userId)->count();
- if($count==0){
- return response()->json([
- 'error_code'=>'0',
- 'msg'=>'该党员未上传承诺书'
- ]);
- }
- $da['uid']=$userId;
- $da['month']=date("Y-m",strtotime($input['month']));
- // $da['status']=1;
- $chargeStatus=DB::table('charge')
- ->where($da)
- ->where(function ($query) {
- $query->where('status', '=', '1')
- ->orWhere('status', '=', '2');
- })
- ->first();
- if(!$chargeStatus) { //未缴费
- $fee=ceil(floatval($input['fee'])*100)/100;
- if($fee<=0){
- return response()->json([
- 'error_code'=>'0',
- 'msg'=>'缴费金额不能小于等于0元'
- ]);
- }elseif($fee>=100000000){
- return response()->json([
- 'error_code'=>'0',
- 'msg'=>'缴费金额过大,请核对缴费信息'
- ]);
- }
- $out_trade_no=date("YmdHis").mt_rand(1000,9999).substr(md5(mt_rand(1000,9999)),10,12);
- $row = DB::table('charge')->insert([
- 'uid' => $userId,
- 'month' => date("Y-m",strtotime($input['month'])),
- 'fee' => $fee,
- 'f_fee' => $fee,
- 'aid' => Auth::guard('admin')->user()->id,
- 'out_trade_no'=>$out_trade_no,
- 'team_id' => $teamId,
- 'status' => 1,
- 'type' => 2,//后台缴费
- 'is_v' => 3,//无手续费
- 'v_fee' => 0,
- 'income'=>0,
- 'openid' => 0,
- 'added_on' => date("Y-m-d H:i:s"),
- 'pays_at' => date("Y-m-d H:i:s"),
- ]);
- if ($row) {
- return response()->json([
- 'error_code' => 200,
- 'msg' => '缴费成功'
- ]);
- } else {
- return response()->json([
- 'error_code' => 0,
- 'msg' => '缴费失败'
- ]);
- }
- }else{
- return response()->json([
- 'error_code' => 0,
- 'msg' => '该用户本月已缴费'
- ]);
- }
- }else{
- return response()->json([
- 'error_code'=> 10001,
- 'msg'=>'用户信息有误'
- ]);
- }
- }
- }
|