Commit 06f2dc65 by lizhilin

更新

parent 7713df48
<?php
namespace App\Admin\Forms;
use App\Command\Log;
use App\Models\Company;
use App\Models\Employee;
use App\Models\Income;
use App\Models\Pay;
use Dcat\Admin\Widgets\Form;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Illuminate\Support\Facades\DB;
class CheckIncome extends Form implements LazyRenderable
{
use LazyWidget;
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
DB::beginTransaction();
$income = Income::find($this->payload['id']);
if ($income->batch_id) {
return $this->response()->error('提现已受理,请等待。。。')->refresh();
}
try {
$status = (int)$input['status']; //审核状态 0:审核中 1:通过 2:拒绝
$income->remark = $input['remark'] ?? '';
if ($status == 1) {
$pay_res = Pay::toBalance($income->openid, $income->amount, '用户提现');
if (!empty($pay_res)) {
$income->partner_trade_no = $pay_res[0];
$income->out_batch_no = $pay_res[1];
$income->batch_id = $pay_res[2];
$income->batch_status = $pay_res[3];
}
} elseif ($status == 2) {
$income->status = 2;
//恢复陪诊员余额
if ($income->user_type == 1) {
$em = Employee::find($income->ec_id);
$em->balance += $income->amount;
$em->freeze_balance -= $income->amount;
$em->save();
} else if ($income->user_type == 2) {
$cm = Company::find($income->ec_id);
$cm->balance += $income->amount;
$cm->freeze_balance -= $income->amount;
$cm->save();
}
}
$income->save();
DB::commit();
Log::add('提现已受理', $income->toArray());
} catch (\Exception $exception) {
DB::rollBack();
Log::add('用户提现失败', $exception->getMessage());
return $this->response()->error('用户提现失败')->refresh();
}
return $this->response()->success('用户提现已受理')->refresh();
}
public function handle_202312(array $input)
{
DB::beginTransaction();
try {
$income = Income::find($this->payload['id']);
$income->status = $input['status'];
$income->remark = $input['remark'] ?? '';
if ($income->status == 1) {
// $income->partner_trade_no = Pay::toBalance($income->openid,$income->amount,'用户提现');
$pay_res = Pay::toBalance($income->openid, $income->amount, '用户提现');
Log::add('用户提现-微信结果', $pay_res);
if (!empty($pay_res)) {
$income->partner_trade_no = $pay_res[0];
$income->out_batch_no = $pay_res[1];
$income->batch_id = $pay_res[2];
} else { //提现失败
$income->status = 2;
}
}
$income->save();
if ($income->user_type == 1) {
$em = Employee::find($income->ec_id);
if ($income->status == 2) {
$em->balance += $income->amount;
}
$em->freeze_balance -= $income->amount;;
$em->save();
} else if ($income->user_type == 2) {
$cm = Company::find($income->ec_id);
if ($income->status == 2) {
$cm->balance += $income->amount;
}
$cm->freeze_balance -= $income->amount;
$cm->save();
}
DB::commit();
Log::add('用户提现成功', $income->toArray());
} catch (\Exception $exception) {
DB::rollBack();
Log::add('用户提现失败', $exception);
return $this->response()->error('用户提现失败')->refresh();
}
return $this->response()->success('用户提现成功')->refresh();
}
/**
* Build a form here.
*/
public function form()
{
$this->radio('status', '提现审核')->options([1 => '同意提现', 2 => '拒绝提现'])
->when(2, function (Form $form) {
$form->textarea('remark', '拒绝理由');
})
->required();
}
/**
* The data of the form.
*
* @return array
*/
public function default()
{
// 获取外部传递参数
return [];
}
}
<?php
namespace App\Http\Controllers\Api;
use App\Command\Log;
use App\Models\Carousel;
use App\Models\User;
use App\Models\Income;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class IncomeController extends BaseController
{
public function getList(Request $request)
{
$type = $request->type ?? 0;
$page = $request->page ?? 1;
$limit = $request->limit ?? 10;
$txtArr = ['提现中', '提现成功', '提现失败'];
if (!in_array($type, [1, 2,])) {
return $this->JsonResponse('', '参数错误', 201);
}
$sql = Income::where(['um_id' => $request->user()->id, 'user_type' => $type, 'deleted_at' => null]);
$total = $sql->count();
$data = [
'total' => $total,
'total_page' => ceil($total / $limit),
'list' => []
];
$listData = $sql->offset(($page - 1) * $limit)->limit($limit)->orderBy('created_at', 'DESC')->get();
if ($listData->toArray()) {
foreach ($listData as $kk => $vv) {
$data['list'][] = [
'title' => $txtArr[$vv->status],
'status' => $vv->status,
'created_at' => date("Y-m-d H:i:s", strtotime($vv->created_at)),
'amount' => $vv->amount
];
}
}
return $this->JsonResponse($data);
}
public function add(Request $request)
{
$useObj = $request->user();
$type = $request->type ?? 0;
$money = $request->money ? (float)$request->money : 0;
if (!in_array($type, [1, 2,])) {
return $this->JsonResponse('', '参数错误', 201);
}
if ($money < 1) {
return $this->JsonResponse('', '提现金额1元起', 500);
}
if ($useObj->balance < $money) {
return $this->JsonResponse('', '余额不足', 500);
}
DB::beginTransaction();
try {
$comObj = new Income();
$comObj->user_type = $type;
$comObj->um_id = $useObj->id;
$comObj->amount = $money;
$comObj->status = 0;
$comObj->save();
DB::commit();
return $this->JsonResponse('');
} catch (\Exception $exception) {
Log::add('添加提现失败', $exception->getMessage());
DB::rollBack();
return $this->JsonResponse('', '添加提现失败', 201);
}
}
}
<?php
namespace App\Http\Controllers\Api;
use App\Command\Log;
use App\Models\Carousel;
use App\Models\User;
use App\Models\OrderDivideRecord;
use Illuminate\Http\Request;
class OrderDivideRecordController extends BaseController
{
public function getList(Request $request)
{
$type = $request->type ?? 0;
$page = $request->page ?? 1;
$limit = $request->limit ?? 10;
if (!in_array($type, [1, 2, 3])) {
return $this->JsonResponse('', '参数错误', 201);
}
$sql = OrderDivideRecord::where(['um_id' => $request->user()->id, 'sh_type' => $type, 'deleted_at' => null]);
$total = $sql->count();
$data = [
'total' => $total,
'total_page' => ceil($total / $limit),
'list' => []
];
$listData = $sql->offset(($page - 1) * $limit)->limit($limit)->orderBy('created_at', 'DESC')->get();
if ($listData->toArray()) {
foreach ($listData as $kk => $vv) {
$data['list'][] = [
'title' => $vv->title,
'created_at' => date("Y-m-d H:i:s", strtotime($vv->created_at)),
'divide_price' => $vv->divide_price
];
}
}
return $this->JsonResponse($data);
}
}
<?php
namespace App\Http\Controllers\Api;
use App\Command\Log;
use App\Handlers\FileUploadHandler;
use App\Models\Merchant;
use App\Models\StoreAdminUsers;
use App\Models\UserPermission;
use App\Models\PersonalAccessToken;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
class StoreAdminUsersController extends BaseController
{
public function login(Request $request)
{
// $user = User::find(1);
// $accessToken = 'Bearer '.$user->createToken('Access-token')->plainTextToken;
// return $this->JsonResponse([ 'Authorization'=>$accessToken,]);
// $encryptedData = $request->encryptedData ?? '';
// $iv = $request->iv ?? '';
// $session_key = $request->session_key ?? '';
// $openId = $request->openid ??'';
// $res = $this->decryptData($session_key,$encryptedData,$iv,$data);
// if($res != 0 ){
// return $this->JsonResponse('','参数异常',201);
// }
$username = $request->username ?? '';
$password = $request->password ?? '';
$user = StoreAdminUsers::where(['username' => $username])->first();
if (!$user) {
return $this->JsonResponse('', '用户不存在', 201);
}
if (!Hash::check($password, $user->password)) {
return $this->JsonResponse('', '账号或密码错误', 500);
}
//生成token
$accessToken = 'Bearer ' . $user->createToken('Access-token')->plainTextToken;
Log::add('商家端用户--' . $user->id . '登录', ['token' => $accessToken]);
return $this->JsonResponse([
'Authorization' => $accessToken,
]);
}
public function logout(Request $request)
{
$request->user()->tokens()->delete();
PersonalAccessToken::where(['tokenable_id' => $request->user()->id])->delete();
return $this->JsonResponse('');
}
public function info(Request $request)
{
$muser = $request->user();
$buycode = '';
$merchant_id = $muser->merchant_id;
$total_revenue = $balance = $cashout = 0;
if ($merchant_id) {
$merObj = Merchant::where('id', $merchant_id)->first();
$buycode = $merObj->buycode;
$total_revenue = $merObj->total_revenue ?? 0;
$balance = $merObj->balance ?? 0;
$cashout = $total_revenue - $balance;
}
return $this->JsonResponse([
'user_id' => $muser->id,
'username' => $muser->username,
'avatar' => $muser->avatar ? env('IMAGE_URL') . $muser->avatar : '',
'merchant_id' => $muser->merchant_id,
'buycode' => $buycode,
'total_revenue' => $total_revenue,
'balance' => $balance,
'cashout' => $cashout,
'role_id' => $muser->role_id,
]);
}
}
<?php
namespace App\Models;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;
class OrderDivideRecord extends Model
{
use HasDateTimeFormatter;
use SoftDeletes;
protected $table = 'order_divide_record';
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment