diff --git a/app/admin/controller/SupplyAccount.php b/app/admin/controller/SupplyAccount.php index 15f9b05..19fccc0 100644 --- a/app/admin/controller/SupplyAccount.php +++ b/app/admin/controller/SupplyAccount.php @@ -35,11 +35,15 @@ class SupplyAccount extends BaseController if (request()->isAjax()) { $param = get_params(); $where = []; - - $list = $this->model->getSupplyAccountList($where,$param); + $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit']; + + $list = SupplyAccountModel::with('team')->where($where) + ->paginate($rows, false, ['query' => $param]); + foreach ($list as $k =>$v){ $list[$k]['fa_supply_team_id'] = Db::table('fa_supply_team')->where('id',$v['fa_supply_team_id'])->value('name'); } + return table_assign(0, '', $list); } else{ @@ -62,11 +66,25 @@ class SupplyAccount extends BaseController // 验证失败 输出错误信息 return to_assign(1, $e->getError()); } - - $this->model->addSupplyAccount($param); + + // 如果存在,则更新 + if(SupplyAccountModel::where('fa_supply_team_id', $this->uid)->find()) + { + $param['fa_supply_team_id'] = $this->uid; // 供应链服务小组ID + $this->model->updateSupplyAccount($param); + + }else{ // 不存在,则创建新的提现账户 + + $param['fa_supply_team_id'] = $this->uid; // 供应链服务小组ID + $this->model->addSupplyAccount($param); + } + }else{ - $team = Db::table('fa_supply_team')->select(); - View::assign('team', $team); + + // 获取当前账号提现信息 + $account = SupplyAccountModel::where('fa_supply_team_id', $this->uid)->find(); + View::assign('account', $account); + return view(); } } diff --git a/app/admin/controller/supplychain/Extract.php b/app/admin/controller/supplychain/Extract.php index d9ecd2e..75c8ee5 100644 --- a/app/admin/controller/supplychain/Extract.php +++ b/app/admin/controller/supplychain/Extract.php @@ -187,7 +187,43 @@ class Extract extends BaseController */ public function cancel() { + $params = get_params(); + // 启动事务 + Db::startTrans(); + try { + + // 撤销提现,更新状态 + $status = SupplyExtract::where('id', $params['id'])->update(['status' => 3]); + + // 返回提现金额 + if($status) + { + // 申请提现的金额 + $extractInfo = SupplyExtract::where('id', $params['id'])->find(); + $extract_price = $extractInfo['extract_price']; + $fa_supply_team_id = $extractInfo['fa_supply_team_id']; + + if($extract_price) + { + // 返还提现余额 + SupplyTeam::where('id', $fa_supply_team_id) + ->inc('brokerage', $extract_price) + ->update(); + } + } + + // 提交事务 + Db::commit(); + } catch (\Exception $e) { + + // 回滚事务 + Db::rollback(); + + return to_assign(1, '操作失败,原因:' . $e->getMessage()); + } + + return to_assign(0, '操作成功'); } /** diff --git a/app/admin/model/SupplyAccount.php b/app/admin/model/SupplyAccount.php index f0dc3cc..1ba61e2 100644 --- a/app/admin/model/SupplyAccount.php +++ b/app/admin/model/SupplyAccount.php @@ -11,6 +11,16 @@ class SupplyAccount extends Model // 设置当前模型对应的完整数据表名称 protected $table = 'fa_supply_account'; + /** + * + * 获取关联小组 + * + */ + public function team() + { + return $this->hasOne(SupplyTeam::class, 'id', 'fa_supply_team_id'); + } + /** * 获取分页列表 * @param $where @@ -45,16 +55,17 @@ class SupplyAccount extends Model * 编辑信息 * @param $param */ - public function editSupplyAccount($param) + public function updateSupplyAccount($param) { try { - $param['update_time'] = time(); - self::where('id', $param['id'])->strict(false)->field(true)->update($param); - add_log('edit', $param['id'], $param); + $param['update_time'] = time(); + self::where('fa_supply_team_id', $param['fa_supply_team_id'])->strict(false)->field(true)->update($param); + add_log('edit', $param['fa_supply_team_id'], $param); } catch(\Exception $e) { - return to_assign(1, '操作失败,原因:'.$e->getMessage()); + return to_assign(1, '操作失败,原因:'.$e->getMessage()); } - return to_assign(); + + return to_assign(); } diff --git a/app/admin/validate/SupplyAccountValidate.php b/app/admin/validate/SupplyAccountValidate.php index 4dcbbb7..5fb167c 100644 --- a/app/admin/validate/SupplyAccountValidate.php +++ b/app/admin/validate/SupplyAccountValidate.php @@ -11,22 +11,16 @@ use think\Validate; class SupplyAccountValidate extends Validate { protected $rule = [ - 'account' => 'require', - 'name' => 'require', - 'bank' => 'require', - 'amount' => 'require', - 'balance' => 'require', - 'free_balance' => 'require', - 'fa_supply_team_id' => 'require', -]; + 'account' => 'require', + 'name' => 'require', + 'bank' => 'require', + 'bank_address' => 'require', + ]; protected $message = [ - 'account.require' => '账号不能为空', - 'name.require' => '用户名不能为空', - 'bank.require' => '开户行不能为空', - 'amount.require' => '已提现金额不能为空', - 'balance.require' => '账户余额不能为空', - 'free_balance.require' => '冻结余额不能为空', - 'fa_supply_team_id.require' => '所属后台供应链团队ID不能为空', + 'account.require' => '账号不能为空', + 'name.require' => '用户名不能为空', + 'bank.require' => '开户银行不能为空', + 'bank_address.require' => '开户地址不能为空', ]; } \ No newline at end of file diff --git a/app/admin/view/supply_account/add.html b/app/admin/view/supply_account/add.html index 4e4196e..6041e3d 100644 --- a/app/admin/view/supply_account/add.html +++ b/app/admin/view/supply_account/add.html @@ -1,36 +1,64 @@ {extend name="common/base"/} {block name="body"} -
+{if condition="$account"} + +{else/} + +{/if} {/block} diff --git a/app/admin/view/supply_account/datalist.html b/app/admin/view/supply_account/datalist.html index 2c70e61..4fc0153 100644 --- a/app/admin/view/supply_account/datalist.html +++ b/app/admin/view/supply_account/datalist.html @@ -9,12 +9,14 @@ +