generated from liutk/owl-admin-base
补充后台发货,以及接口调整bug
parent
54faeb2ca7
commit
831af90170
|
|
@ -6,9 +6,13 @@ use Slowlyo\OwlAdmin\Admin;
|
|||
use Slowlyo\OwlAdmin\Renderers\Page;
|
||||
use Slowlyo\OwlAdmin\Renderers\Form;
|
||||
use Slowlyo\OwlAdmin\Renderers\Operation;
|
||||
use Slowlyo\OwlAdmin\Renderers\Dialog;
|
||||
use Slowlyo\OwlAdmin\Renderers\DialogAction;
|
||||
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||
use App\Services\Admin\UserGiftService;
|
||||
use App\Admin\Components;
|
||||
use App\Models\UserGift;
|
||||
use App\Models\Activity;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UserGiftController extends AdminController
|
||||
{
|
||||
|
|
@ -22,13 +26,23 @@ class UserGiftController extends AdminController
|
|||
amis('filter-toggler')->align('right'),
|
||||
])
|
||||
->filter($this->baseFilter()->labelWidth('80px')->body([
|
||||
|
||||
amis()->GroupControl()->mode('horizontal')->body([
|
||||
amis()->SelectControl('activity', __('admin.activities.name'))->options(Activity::sort()->pluck('name', 'id')->toArray()),
|
||||
amis()->TextControl('user_name', __('admin.users.nick_name'))
|
||||
->placeholder(__('admin.users.nick_name')),
|
||||
amis()->TextControl('user_phone', __('admin.users.phone'))
|
||||
->placeholder(__('admin.users.phone')),
|
||||
amis()->SelectControl('state', __('admin.user_gifts.state'))
|
||||
->options([
|
||||
1=>'未发货',2=>'已发货',0=>'未领取'
|
||||
]),
|
||||
])
|
||||
]))
|
||||
->columns([
|
||||
amis()->TableColumn('activity.name', __('admin.activities.name')),
|
||||
amis()->TableColumn('gift.name', __('admin.activity_gifts.name')),
|
||||
amis()->TableColumn('user.nick_name', __('admin.users.nick_name')),
|
||||
amis()->TableColumn('user.phone', __('admin.users.phone')),
|
||||
amis()->TableColumn('user.phone', __('admin.users.phone'))->copyable(),
|
||||
amis()->TableColumn('state', __('admin.user_gifts.state'))->type('mapping')->map([
|
||||
"0"=>"<span class='label label-default'>未领取</span>",
|
||||
"1"=>"<span class='label label-danger'>未发货</span>",
|
||||
|
|
@ -39,7 +53,19 @@ class UserGiftController extends AdminController
|
|||
amis()->TableColumn('address', __('admin.user_gifts.address')),
|
||||
amis()->TableColumn('phone', __('admin.user_gifts.phone')),
|
||||
amis()->TableColumn('shipping_company', __('admin.user_gifts.shipping_company')),
|
||||
amis()->TableColumn('shipping_number', __('admin.user_gifts.shipping_number')),
|
||||
amis()->TableColumn('shipping_number', __('admin.user_gifts.shipping_number'))->copyable(),
|
||||
Operation::make()->label(__('admin.actions'))->buttons([
|
||||
amisMake()->DialogAction()->label('发货')
|
||||
->level('link')
|
||||
->dialog(Dialog::make()->title('填写发货信息')->body([
|
||||
amisMake()->form()->title('')
|
||||
->api('post:' .admin_url('user_gifts/${id}/shipping'))
|
||||
->body([
|
||||
amis()->TextControl('shipping_company', __('admin.user_gifts.shipping_company'))->required(),
|
||||
amis()->TextControl('shipping_number', __('admin.user_gifts.shipping_number'))->required(),
|
||||
])
|
||||
]))->visibleOn('${state == 1}'),
|
||||
])
|
||||
]);
|
||||
|
||||
return $this->baseList($crud);
|
||||
|
|
@ -74,4 +100,14 @@ class UserGiftController extends AdminController
|
|||
amis()->Button()->actionType('cancel')->label(__('admin.back'))->primary()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 发货
|
||||
*/
|
||||
public function shipping(UserGift $userGift, Request $request)
|
||||
{
|
||||
$res = $this->service->shippingGift($userGift, $request->input());
|
||||
|
||||
return $this->autoResponse($res, '发货');
|
||||
}
|
||||
}
|
||||
|
|
@ -42,6 +42,7 @@ Route::group([
|
|||
|
||||
$router->resource('activity_gifts', \App\Admin\Controllers\ActivityGiftController::class);
|
||||
|
||||
$router->post('user_gifts/{user_gift}/shipping', [\App\Admin\Controllers\UserGiftController::class, 'shipping']);
|
||||
$router->resource('user_gifts', \App\Admin\Controllers\UserGiftController::class);
|
||||
|
||||
//修改上传
|
||||
|
|
|
|||
|
|
@ -57,9 +57,9 @@ class ActivityGameController extends ApiController
|
|||
return $this->success();
|
||||
}
|
||||
|
||||
public function joinGame(ActivityGame $activityGame, JoinGameRequest $request)
|
||||
public function joinGame(ActivityGame $game, JoinGameRequest $request)
|
||||
{
|
||||
$res = $this->service->join($activityGame, $request->user(), $request->input('score'));
|
||||
$res = $this->service->join($game, $request->user(), $request->input('score'));
|
||||
|
||||
if($res['status']){
|
||||
return $this->success(null, '竞猜成功');
|
||||
|
|
|
|||
|
|
@ -71,14 +71,15 @@ class UserController extends ApiController
|
|||
|
||||
public function giftList(Request $request)
|
||||
{
|
||||
$userGifts = $request->user()->gifts()->with(['gift', 'gift.activity'])->sort()
|
||||
$userGifts = $request->user()->gifts()->with(['gift', 'activity'])->sort()
|
||||
->simplePaginate($request->query('per_page', 20));
|
||||
|
||||
return $this->success(['activities' => UserGiftResource::collection($userGifts)->resolve()]);
|
||||
return $this->success(['gifts' => UserGiftResource::collection($userGifts)->resolve()]);
|
||||
}
|
||||
|
||||
public function userGift(UserGift $userGift, Request $request)
|
||||
{
|
||||
$userGift->load(['gift', 'activity']);
|
||||
return UserGiftResource::make($userGift);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ class UserGiftResource extends JsonResource
|
|||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'gift_name'=>$this->whenLoaded('gift', function () {
|
||||
return $this->gift->name;
|
||||
}, ''),
|
||||
|
|
@ -28,8 +29,8 @@ class UserGiftResource extends JsonResource
|
|||
'gift_explain'=> $this->whenLoaded('gift', function () {
|
||||
return $this->gift->explain;
|
||||
}, ''),
|
||||
'activity_name' => $this->whenLoaded('gift.activity', function () {
|
||||
return $this->gift->activity->name;
|
||||
'activity_name' => $this->whenLoaded('activity', function () {
|
||||
return $this->activity->name;
|
||||
}, ''),
|
||||
|
||||
'consignee' => $this->consignee ?? '',
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@ class Activity extends Model
|
|||
{
|
||||
use HasFactory,Filterable;
|
||||
|
||||
protected $fillable = [
|
||||
'state'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'start_at' => 'datetime',
|
||||
'end_at' => 'datetime'
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ class AdFilter extends ModelFilter
|
|||
{
|
||||
return $this->where('address', $address);
|
||||
}
|
||||
|
||||
public function publishedAt($publishedAt){
|
||||
$publishedAt = explode(',',$publishedAt);
|
||||
return $this->where(function($q) use ($publishedAt) {
|
||||
|
|
|
|||
|
|
@ -7,5 +7,22 @@ use EloquentFilter\ModelFilter;
|
|||
|
||||
class UserGiftFilter extends ModelFilter
|
||||
{
|
||||
public function activityId($activity)
|
||||
{
|
||||
return $this->where('activity_id', $activityId);
|
||||
}
|
||||
|
||||
public function userName($userName)
|
||||
{
|
||||
return $this->whereHas('user', function($q) use ($userName) {
|
||||
return $q->where('nick_name', 'like', '%'.$userName.'%');
|
||||
});
|
||||
}
|
||||
|
||||
public function userPhone($userPhone)
|
||||
{
|
||||
return $this->whereHas('user', function($q) use ($userPhone) {
|
||||
return $q->where('phone', 'like', $userPhone.'%');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,15 @@ class UserGift extends Model
|
|||
{
|
||||
use HasFactory,Filterable;
|
||||
|
||||
protected $fillable = [
|
||||
'consignee',
|
||||
'address',
|
||||
'phone',
|
||||
'shipping_company',
|
||||
'shipping_number',
|
||||
'state',
|
||||
];
|
||||
|
||||
public function scopeSort($q)
|
||||
{
|
||||
$q->orderBy('created_at', 'desc');
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Services\Admin;
|
||||
|
||||
use DB;
|
||||
use App\Models\Activity;
|
||||
use App\Models\Filters\ActivityFilter;
|
||||
use Illuminate\Support\Arr;
|
||||
|
|
|
|||
|
|
@ -21,4 +21,16 @@ class UserGiftService extends BaseService
|
|||
protected string $modelFilterName = UserGiftFilter::class;
|
||||
|
||||
protected array $withRelationships = ['user', 'gift', 'activity'];
|
||||
|
||||
public function shippingGift(UserGift $userGift, $params)
|
||||
{
|
||||
//更新状态,结果
|
||||
$userGift->update([
|
||||
'shipping_company' => $params['shipping_company'],
|
||||
'shipping_number' => $params['shipping_number'],
|
||||
'state' => 2,
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -65,40 +65,40 @@ class UserService
|
|||
return $res;
|
||||
}
|
||||
|
||||
// public function receiveGift(UserGift $userGift, $params)
|
||||
// {
|
||||
// $userGift->update([
|
||||
// 'consignee' => $params['consignee'],
|
||||
// 'phone' => $params['phone'],
|
||||
// 'address' => $params['address'],
|
||||
// 'state' => 1
|
||||
// ]);
|
||||
// }
|
||||
public function receiveGift(UserGift $userGift, $params)
|
||||
{
|
||||
$userGift->update([
|
||||
'consignee' => $params['consignee'],
|
||||
'phone' => $params['phone'],
|
||||
'address' => $params['address'],
|
||||
'state' => 1
|
||||
]);
|
||||
}
|
||||
|
||||
// protected function saveFile($path, $file = null)
|
||||
// {
|
||||
// if (gettype($file) == 'object') {
|
||||
// //获取文件大小
|
||||
// if($size = $file->getSize() > 2*1024*1024){//大于2M
|
||||
// return false;
|
||||
// }
|
||||
// $type = $file->getClientOriginalExtension();
|
||||
// if (in_array($type, array('jpeg', 'jpg', 'bmp', 'png'))) {
|
||||
// $file = Storage::disk(Admin::config('admin.upload.disk'))->putFile($path, $file);
|
||||
// }else{
|
||||
// return false;
|
||||
// }
|
||||
// } else if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $file, $result)) {
|
||||
// $type = $result[2];
|
||||
// if (in_array($type, array('jpeg', 'jpg', 'bmp', 'png'))) {
|
||||
// $savePath = $path . '/' . uniqid() . '.' . $type;
|
||||
// Storage::disk(Admin::config('admin.upload.disk'))->put($savePath, base64_decode(str_replace($result[1], '', $file)));
|
||||
// $file = $savePath;
|
||||
// }else{
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// return $file;
|
||||
// }
|
||||
protected function saveFile($path, $file = null)
|
||||
{
|
||||
if (gettype($file) == 'object') {
|
||||
//获取文件大小
|
||||
if($size = $file->getSize() > 2*1024*1024){//大于2M
|
||||
return false;
|
||||
}
|
||||
$type = $file->getClientOriginalExtension();
|
||||
if (in_array($type, array('jpeg', 'jpg', 'bmp', 'png'))) {
|
||||
$file = Storage::disk(Admin::config('admin.upload.disk'))->putFile($path, $file);
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
} else if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $file, $result)) {
|
||||
$type = $result[2];
|
||||
if (in_array($type, array('jpeg', 'jpg', 'bmp', 'png'))) {
|
||||
$savePath = $path . '/' . uniqid() . '.' . $type;
|
||||
Storage::disk(Admin::config('admin.upload.disk'))->put($savePath, base64_decode(str_replace($result[1], '', $file)));
|
||||
$file = $savePath;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return $file;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue