Browse Source

社区站点健壮

master
lanzu_qsy 6 years ago
parent
commit
3d805ff85b
  1. 5
      app/Admin/Common/Auth.php
  2. 10
      app/Admin/Controllers/LanzuCsInfoController.php
  3. 66
      app/Admin/Controllers/LanzuCsWithdrawController.php
  4. 13
      app/Models/ImsCjdcMarket.php
  5. 11
      app/Models/LanzuCsInfo.php
  6. 13
      app/Models/LanzuCsWithdraw.php
  7. 93
      app/Models/LanzuUserBalance.php
  8. 2
      app/Models/MpBalance.php
  9. 22
      dcat_admin_ide_helper.php

5
app/Admin/Common/Auth.php

@ -4,6 +4,7 @@ namespace App\Admin\Common;
use App\Models\AdminRoles;
use App\Models\AdminRoleUsers;
use App\Models\AdminUsers;
use App\Models\LanzuUserBalance;
use Dcat\Admin\Controllers\AdminController;
use Illuminate\Support\Facades\Hash;
@ -46,12 +47,14 @@ class Auth extends AdminController
$row->admin_user_id = $adu->id;
$row->save();
//添加到admin roles中
//>>4.添加到admin roles中
$lanzu_role = AdminRoles::where('slug', $roles)->first();
$aru = new AdminRoleUsers();
$aru->role_id = $lanzu_role->id;
$aru->user_id = $adu->id;
$aru->save();
//>>5.生成可提现金额信息
LanzuUserBalance::create($cid,3);
}
}

10
app/Admin/Controllers/LanzuCsInfoController.php

@ -7,6 +7,8 @@ use App\Admin\Common\Images;
use App\Admin\Repositories\LanzuCsInfo;
use App\Models\AdminUsers;
use App\Models\ImsCjdcMarket;
use App\Models\LanzuUserBalance;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
@ -22,7 +24,7 @@ class LanzuCsInfoController extends AdminController
*/
protected function grid()
{
return Grid::make(new LanzuCsInfo(), function (Grid $grid) {
return Grid::make(new LanzuCsInfo('userBalance'), function (Grid $grid) {
$user = Admin::user();
if ($user->isRole('lanzu_cs')){//如何是社区站点角色登陆,则只能看到自己的信息
$grid->model()->where('admin_user_id', $user->id);
@ -32,8 +34,11 @@ class LanzuCsInfoController extends AdminController
$grid->id->sortable();
$grid->name;
$grid->phone;
$grid->amount('可提现金额');
$grid->column('userBalance.balance','可提现金额');
$grid->column('qrcode_path','二维码')->image('',50,50);
$grid->column('market_id','所属市场')->display(function (){
return ImsCjdcMarket::find($this->market_id)->name;
});
$grid->status('状态')->using(['禁用', '启用']);
$grid->address;
$grid->created_at->display(function ($time){
@ -79,6 +84,7 @@ class LanzuCsInfoController extends AdminController
$form->text('name','名称')->required();
$form->text('user_id','用户ID')->required();
$form->mobile('phone')->required();
$form->select('market_id','所属市场')->options(ImsCjdcMarket::getMarket())->required();
$form->text('address','社区地址')->required();
$form->radio('status', '状态')->options(['禁用', '启用'])->default(1);
$form->saved(function (Form $form,$cid){

66
app/Admin/Controllers/LanzuCsWithdrawController.php

@ -3,6 +3,9 @@
namespace App\Admin\Controllers;
use App\Admin\Repositories\LanzuCsWithdraw;
use App\Models\LanzuCsInfo;
use App\Models\LanzuUserBalance;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
@ -18,18 +21,26 @@ class LanzuCsWithdrawController extends AdminController
protected function grid()
{
return Grid::make(new LanzuCsWithdraw(), function (Grid $grid) {
$user = Admin::user();
if (!$user->isRole('lanzu_cs')){//如果不是社区站点的角色登陆,则隐藏提现入口
$grid->disableCreateButton();
}else{
$grid->disableEditButton();
}
$grid->disableViewButton();
$grid->disableDeleteButton();
$grid->id->sortable();
$grid->cs_id('提现用户');
$grid->cs_id('提现用户')->display(function (){
return LanzuCsInfo::where('id',$this->cs_id)->first()->name;
});
$grid->money;
$grid->status('状态');
$grid->is_pay('是否到账');
$grid->status('状态')->using([1=>'已同意',-1=>'已拒绝',0=>'待审核'])->label([1=>'success',-1=>'danger',0=>'default']);
$grid->is_pay('是否到账')->using(['否','是']);
$grid->created_at;
$grid->updated_at->sortable();
$grid->filter(function (Grid\Filter $filter) {
$filter->equal('id');
});
});
}
@ -60,14 +71,45 @@ class LanzuCsWithdrawController extends AdminController
*/
protected function form()
{
return Form::make(new LanzuCsWithdraw(), function (Form $form) {
return Form::make(new LanzuCsWithdraw('csInfo'), function (Form $form) {
$form->display('id');
$form->text('amount','可提现金额');
$form->text('cs_id','提现用户');
$form->text('money');
$user = Admin::user();
if ($form->isCreating()){//如果是添加操作
if ($user->isRole('lanzu_cs')){//如果是社区站点角色
$cs = LanzuCsInfo::where('admin_user_id',$user->id)->first();
if ($cs){
$form->text('amount', '可提现金额')->value(LanzuUserBalance::getBalance($cs->id,3))->disable();
$form->hidden('cs_id', '提现用户id')->value($cs->id);
$form->text('csInfo.name', '提现用户')->value($cs->name)->disable();
$form->text('money');
}
}
}else{//编辑操作
$form->display('amount', '可提现金额')->value(LanzuUserBalance::getBalance($form->model()->cs_id,3));
$form->display('cs_id', '提现用户')->value($form->model()->name);
$form->display('money');
$form->radio('status','状态')->options([1=>'同意',-1=>'拒绝'])->default(-1);
}
$form->display('created_at');
$form->display('updated_at');
});
}
/**
* 获取可提现金额
* @param $aduId
* @return float
*/
protected function getBalance($aduId)
{
$row = $this->getMmInfoByAduId($aduId);
if ($row) {
$res = MpBalance::where(['user_id' => $row->user_id])->first();
if ($res) {
return $res->balance;
}
}
return '0.00';
}
}

13
app/Models/ImsCjdcMarket.php

@ -29,5 +29,18 @@ class ImsCjdcMarket extends Model
return $this->hasOne('\App\Models\LanzuMpInfo','id','mp_id');
}
/**
* 获取市场信息
* @return \Illuminate\Http\JsonResponse
*/
public static function getMarket()
{
$markets = self::get();
$item = [];
foreach ($markets as $market) {
$item[$market->id] = $market->name;
}
return $item;
}
}

11
app/Models/LanzuCsInfo.php

@ -12,4 +12,15 @@ class LanzuCsInfo extends Model
protected $table = 'lanzu_cs_info';
protected $dateFormat = 'U';
public function userBalance()
{
return $this->hasOne("\App\Models\LanzuUserBalance",'source_id','id');
}
public function csWithdraw()
{
return $this->hasOne("\App\Models\LanzuCsWithdraw",'cs_id','id');
}
}

13
app/Models/LanzuCsWithdraw.php

@ -13,5 +13,18 @@ class LanzuCsWithdraw extends Model
protected $table = 'lanzu_cs_withdraw';
protected $dateFormat = 'U';
public function csInfo()
{
return $this->belongsTo("\App\Models\LanzuCsInfo",'cs_id','id');
}
public function getCreatedAtAttribute($value)
{
return date('Y-m-d H:i',$value);
}
public function getUpdatedAtAttribute($value)
{
return date('Y-m-d H:i',$value);
}
}

93
app/Models/LanzuUserBalance.php

@ -0,0 +1,93 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class LanzuUserBalance extends Model
{
protected $table = 'lanzu_user_balance';
protected $dateFormat = 'U';
/**
* 获取可提现金额
* @param $uid
* @param $uType 0/1 普通用户/服务商
*/
public static function getBalance($uid, $uType = 0)
{
$row = self::where(['source_id' => $uid, 'user_type' => $uType])->first();
if ($row) {
return $row->balance;
} else {
return '0.00';
}
}
/**
* 扣减可提现金额
*/
public static function reduceBalance($uid, $uType, $reduceMoney)
{
$row = self::where(['source_id' => $uid, 'user_type' => $uType])->first();
if ($row) {
$row->balance = $row->balance - $reduceMoney;
return $row->save();
} else {
return false;
}
}
/**
* 回退审核未通过时的提现金额
*/
public static function returnBalance($uid, $uType, $returnMoney)
{
$row = self::where(['source_id' => $uid, 'user_type' => $uType])->first();
if ($row) {
$row->balance = $row->balance + $returnMoney;
return $row->save();
} else {
return false;
}
}
/**
* 生成一条数据
*/
public static function create($sid,$type)
{
$self = new self();
$self->source_id = $sid;
$self->user_type = $type;
$self->balance = 0;
$self->save();
}
}

2
app/Models/MpBalance.php

@ -8,7 +8,7 @@ use Illuminate\Database\Eloquent\Model;
class MpBalance extends Model
{
protected $table = 'lanzu_mp_balance';
protected $table = 'lanzu_user_balance';
protected $dateFormat = 'U';
/**

22
dcat_admin_ide_helper.php

@ -602,7 +602,6 @@ namespace Dcat\Admin {
* @property Grid\Column|Collection print_mode
* @property Grid\Column|Collection is_yydc
* @property Grid\Column|Collection is_ps
* @property Grid\Column|Collection is_ps
* @property Grid\Column|Collection is_cj
* @property Grid\Column|Collection cj_name
* @property Grid\Column|Collection wmps_name
@ -667,7 +666,6 @@ namespace Dcat\Admin {
* @property Grid\Column|Collection distance
* @property Grid\Column|Collection is_jf
* @property Grid\Column|Collection fx_title
* @property Grid\Column|Collection fx_title
* @property Grid\Column|Collection hygn
* @property Grid\Column|Collection hy_discount
* @property Grid\Column|Collection hy_details
@ -1690,7 +1688,6 @@ namespace Dcat\Admin {
* @method Grid\Column|Collection is_dn(string $label = null)
* @method Grid\Column|Collection is_yy(string $label = null)
* @method Grid\Column|Collection is_tk(string $label = null)
* @method Grid\Column|Collection openId(string $label = null)
* @method Grid\Column|Collection wm_money(string $label = null)
* @method Grid\Column|Collection combination(string $label = null)
* @method Grid\Column|Collection spec_id(string $label = null)
@ -1766,7 +1763,7 @@ namespace Dcat\Admin {
* @method Grid\Column|Collection print_mode(string $label = null)
* @method Grid\Column|Collection is_yydc(string $label = null)
* @method Grid\Column|Collection is_ps(string $label = null)
* @method Grid\Column|Collection is_ps(string $label = null)
* @method Grid\Column|Collection is_cj(string $label = null)
* @method Grid\Column|Collection cj_name(string $label = null)
* @method Grid\Column|Collection wmps_name(string $label = null)
@ -1831,7 +1828,7 @@ namespace Dcat\Admin {
* @method Grid\Column|Collection distance(string $label = null)
* @method Grid\Column|Collection is_jf(string $label = null)
* @method Grid\Column|Collection fx_title(string $label = null)
* @method Grid\Column|Collection fx_title(string $label = null)
* @method Grid\Column|Collection hygn(string $label = null)
* @method Grid\Column|Collection hy_discount(string $label = null)
* @method Grid\Column|Collection hy_details(string $label = null)
@ -1899,8 +1896,6 @@ namespace Dcat\Admin {
* @method Grid\Column|Collection yh_money(string $label = null)
* @method Grid\Column|Collection origin_id(string $label = null)
* @method Grid\Column|Collection body(string $label = null)
* @method Grid\Column|Collection appId(string $label = null)
* @method Grid\Column|Collection appSecret(string $label = null)
* @method Grid\Column|Collection jdId(string $label = null)
* @method Grid\Column|Collection pdId(string $label = null)
* @method Grid\Column|Collection weChatId(string $label = null)
@ -2935,7 +2930,6 @@ namespace Dcat\Admin {
* @property Show\Field|Collection print_mode
* @property Show\Field|Collection is_yydc
* @property Show\Field|Collection is_ps
* @property Show\Field|Collection is_ps
* @property Show\Field|Collection is_cj
* @property Show\Field|Collection cj_name
* @property Show\Field|Collection wmps_name
@ -3000,7 +2994,6 @@ namespace Dcat\Admin {
* @property Show\Field|Collection distance
* @property Show\Field|Collection is_jf
* @property Show\Field|Collection fx_title
* @property Show\Field|Collection fx_title
* @property Show\Field|Collection hygn
* @property Show\Field|Collection hy_discount
* @property Show\Field|Collection hy_details
@ -4023,7 +4016,6 @@ namespace Dcat\Admin {
* @method Show\Field|Collection is_dn(string $label = null)
* @method Show\Field|Collection is_yy(string $label = null)
* @method Show\Field|Collection is_tk(string $label = null)
* @method Show\Field|Collection openId(string $label = null)
* @method Show\Field|Collection wm_money(string $label = null)
* @method Show\Field|Collection combination(string $label = null)
* @method Show\Field|Collection spec_id(string $label = null)
@ -4099,7 +4091,6 @@ namespace Dcat\Admin {
* @method Show\Field|Collection print_mode(string $label = null)
* @method Show\Field|Collection is_yydc(string $label = null)
* @method Show\Field|Collection is_ps(string $label = null)
* @method Show\Field|Collection is_ps(string $label = null)
* @method Show\Field|Collection is_cj(string $label = null)
* @method Show\Field|Collection cj_name(string $label = null)
* @method Show\Field|Collection wmps_name(string $label = null)
@ -4164,7 +4155,6 @@ namespace Dcat\Admin {
* @method Show\Field|Collection distance(string $label = null)
* @method Show\Field|Collection is_jf(string $label = null)
* @method Show\Field|Collection fx_title(string $label = null)
* @method Show\Field|Collection fx_title(string $label = null)
* @method Show\Field|Collection hygn(string $label = null)
* @method Show\Field|Collection hy_discount(string $label = null)
* @method Show\Field|Collection hy_details(string $label = null)
@ -4232,8 +4222,6 @@ namespace Dcat\Admin {
* @method Show\Field|Collection yh_money(string $label = null)
* @method Show\Field|Collection origin_id(string $label = null)
* @method Show\Field|Collection body(string $label = null)
* @method Show\Field|Collection appId(string $label = null)
* @method Show\Field|Collection appSecret(string $label = null)
* @method Show\Field|Collection jdId(string $label = null)
* @method Show\Field|Collection pdId(string $label = null)
* @method Show\Field|Collection weChatId(string $label = null)
@ -4683,19 +4671,19 @@ namespace Dcat\Admin {
namespace Dcat\Admin\Grid {
/**
*/
class Column {}
/**
*/
class Filter {}
}
namespace Dcat\Admin\Show {
/**
*/
class Field {}
}
Loading…
Cancel
Save