48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Endpoint\Api\Http\Controllers;
|
|
|
|
use App\Exceptions\BizException;
|
|
use App\Models\UserCid;
|
|
use App\Services\Push\MallUnipushService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Throwable;
|
|
|
|
class PushController extends Controller
|
|
{
|
|
/**
|
|
* 绑定cid
|
|
*
|
|
* @param Request $request
|
|
* @return void
|
|
*/
|
|
public function bindUniCid(Request $request, MallUnipushService $mallUnipushService)
|
|
{
|
|
if (!$request->user()) {
|
|
throw new BizException('绑定失败,请稍后再试');
|
|
}
|
|
|
|
$input = $request->validate([
|
|
'cid' => ['bail', 'required', 'string', 'max:64'],
|
|
]);
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
//查询目前有没有人已绑定这个cid, 有就解绑
|
|
UserCid::where('u_cid', $input['cid'])->where('user_id', '<>', $request->user()->id)->update([
|
|
'u_cid' => null,
|
|
]);
|
|
$request->user()->cid()->updateOrCreate([
|
|
'u_cid'=>$input['cid'],
|
|
]);
|
|
DB::commit();
|
|
} catch (Throwable $th) {
|
|
DB::rollBack();
|
|
report($th);
|
|
throw new BizException('绑定失败,请稍后再试');
|
|
}
|
|
return response()->noContent();
|
|
}
|
|
}
|