123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- <?php
- namespace App\Http\Controllers\Withdraw;
- use App\Http\Controllers\AdminBaseController;
- use App\Http\Requests\WithdrawCreateRequest;
- use App\Http\Requests\WithdrawUpdateRequest;
- use App\Models\MemberOpenId;
- use App\Models\Withdraw;
- use App\Repositories\Eloquent\WithdrawRepositoryEloquent;
- use App\Servers\MoneyDetailServer;
- use App\Servers\WeixinServer;
- use App\Servers\WithdrawServer;
- use App\Validators\WithdrawValidator;
- use function Couchbase\defaultDecoder;
- /**
- * Class WithdrawsController.
- *
- * @package namespace App\Http\Controllers;
- */
- class WithdrawsController extends AdminBaseController
- {
- /**
- * @var WithdrawRepositoryEloquent
- */
- protected $repository;
- /**
- * @var WithdrawValidator
- */
- protected $validator;
- /**
- * WithdrawsController constructor.
- *
- * @param WithdrawRepositoryEloquent $repository
- * @param WithdrawValidator $validator
- */
- public function __construct(WithdrawRepositoryEloquent $repository, WithdrawValidator $validator)
- {
- parent::__construct($repository, $validator);
- }
- /**
- * 数据检索
- */
- public function _indexScopeQuery()
- {
- $where = [];
- $search = explode(";", request()->input('search', ""));
- $start = $end = null;
- $fieldSearchable = $this->repository->getFieldsSearchable();
- foreach ($search as $value) {
- if (!empty($value)) {
- list($one, $tow) = explode(":", $value);
- if (!empty($fieldSearchable[$one])) {
- if ($fieldSearchable[$one] == 'like') $tow = "%{$tow}%";
- $where[] = [$one, $fieldSearchable[$one], $tow];
- } elseif ($one == 'start') {
- $start = $tow . " 00:00:00";
- } elseif ($one == 'end') {
- $end = $tow . " 23:59:59";
- } else {
- continue;
- }
- }
- }
- return function ($query) use ($where, $start, $end) {
- if ($start) $where[] = ['created_at', '>=', $start];
- if ($end) $where[] = ['created_at', '<=', $end];
- if ($where) {
- $query->where($where);
- }
- };
- }
- /**
- * 数据更新
- */
- protected function _indexPost($datum)
- {
- foreach ($datum as $value){
- if ($value->status ==1) {
- $value->skip = '';
- } else {
- $value->skip = 'skip';
- }
- $value->{'withdraw_type_str'}=WithdrawServer::creatServer()->getType($value->{'withdraw_type'});
- $value->{'status_str'}=WithdrawServer::creatServer()->getStatusArr($value->{'status'});
- }
- return $datum;
- }
- /**
- * 查询组合
- * @return \Illuminate\Database\Query\Builder
- */
- function _indexJoin()
- {
- return Withdraw::from('withdraws as w')
- ->leftJoin('members as m', 'm.id', '=', 'w.m_id');
- }
- function _indexSelect(){
- return ['w.*','m.phone', 'm.nickname'];
- }
- function _updatePost(){
- $status=request()->input('status');
- $id=request()->input('id');
- $withdraw_type=request()->input('withdraw_type');
- $info=Withdraw::where('id',$id)->first();
- if(empty($withdraw_type) && !in_array($withdraw_type,[1,2])){
- $this->errorMsg='审核类型错误';
- return false;
- }
- if(empty($info)){
- $this->errorMsg='审核信息不存在';
- return false;
- }
- if($info->{'status'}!=1){
- $this->errorMsg='状态异常';
- return false;
- }
- if($status==2){
- $wx_data='';
- if($withdraw_type==1){
- $openid=MemberOpenId::where('m_id',$info->{'m_id'})->where('type',1)->value('openid');
- if(empty($openid)){
- $this->errorMsg='当前用户未绑定微信';
- return false;
- }
- //转账到微信零钱
- $request=WeixinServer::creatServer()->setVerified('TX'.$info->{'id'}.date('YmdHis'),$info->{'withdraw_money'},$openid,'');
- if(empty($request['code'])){
- $this->errorMsg=empty($request['msg'])?'微信零钱划转失败':$request['msg'];
- return false;
- }else{
- $wx_data=json_encode($request);
- }
- }
- $ret=$info->update(['status'=>2,'withdraw_type'=>$withdraw_type,'wx_data'=>$wx_data]);
- }else{
- MoneyDetailServer::creatServer()->write(1, 14, $info->{'money'}, 1, $info->{'m_id'}, '余额提现驳回', $info->{'id'});
- $ret=$info->update(['status'=>3]);
- }
- if($ret){
- $this->successMsg='操作成功';
- return true;
- }else{
- $this->errorMsg='操作失败';
- return false;
- }
- }
- /**
- * 提现审核
- */
- function audit(){
- $status=request()->input('status');
- $id=request()->input('id');
- $withdraw_type=request()->input('withdraw_type');
- $info=Withdraw::where('id',$id)->first();
- if(empty($info)){
- return $this->error('审核信息不存在');
- }
- if($info->{'status'}!=1){
- return $this->response('状态异常', 'error', '', '');
- }
- if($status==2){
- if($withdraw_type==1){
- $openid=MemberOpenId::where('m_id',$info->{'m_id'})->where('type',1)->value('openid');
- if(empty($openid)){
- return $this->error('当前用户未绑定微信');
- }
- }
- $ret=$info->update(['status'=>2,'withdraw_type'=>$withdraw_type]);
- //转账到微信零钱
- }else{
- MoneyDetailServer::creatServer()->write(1, 14, $info->{'money'}, 1, $info->{'m_id'}, '余额提现驳回', $info->{'id'});
- $ret=$info->update(['status'=>3]);
- }
- if($ret){
- return $this->success('操作成功');
- }else{
- return $this->error('操作失败');
- }
- }
- }
|