阶段更新
This commit is contained in:
40
app/Admin/Actions/Area/AddStock.php
Normal file
40
app/Admin/Actions/Area/AddStock.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Area;
|
||||
|
||||
use App\Models\Area;
|
||||
use Encore\Admin\Actions\RowAction;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AddStock extends RowAction
|
||||
{
|
||||
|
||||
public $name = '增加库存';
|
||||
|
||||
public function handle(Area $area, Request $request)
|
||||
{
|
||||
try {
|
||||
$number = $request->number;
|
||||
|
||||
$res = Area::addStock($area, $number, false);
|
||||
|
||||
if ($res === true) {
|
||||
return $this->response()->success('增加库存成功')->refresh();
|
||||
} else {
|
||||
return $this->response()->error('增加库存成功失败,'.$res)->refresh();
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
return $this->response()->error('增加库存成功失败,'.$exception->getMessage())->refresh();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function form(Area $area)
|
||||
{
|
||||
$this->integer('number', '增加库存数')
|
||||
->default(0)
|
||||
->help('1份=2箱')
|
||||
->required();
|
||||
}
|
||||
|
||||
}
|
||||
40
app/Admin/Actions/Area/SubStock.php
Normal file
40
app/Admin/Actions/Area/SubStock.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Area;
|
||||
|
||||
use App\Models\Area;
|
||||
use Encore\Admin\Actions\RowAction;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SubStock extends RowAction
|
||||
{
|
||||
|
||||
public $name = '减少库存';
|
||||
|
||||
public function handle(Area $area, Request $request)
|
||||
{
|
||||
try {
|
||||
$number = $request->number;
|
||||
|
||||
$res = Area::addStock($area, -$number, false);
|
||||
|
||||
if ($res === true) {
|
||||
return $this->response()->success('增加库存成功')->refresh();
|
||||
} else {
|
||||
return $this->response()->error('增加库存成功失败,'.$res)->refresh();
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
return $this->response()->error('增加库存成功失败,'.$exception->getMessage())->refresh();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function form(Area $area)
|
||||
{
|
||||
$this->integer('number', '减少库存数')
|
||||
->default(0)
|
||||
->help('1份=2箱')
|
||||
->required();
|
||||
}
|
||||
|
||||
}
|
||||
129
app/Admin/Controllers/Area/IndexController.php
Normal file
129
app/Admin/Controllers/Area/IndexController.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers\Area;
|
||||
|
||||
use App\Admin\Actions\Area\AddStock;
|
||||
use App\Admin\Actions\Area\SubStock;
|
||||
use App\Admin\Selectable\AreaStockAble;
|
||||
use App\Admin\Selectable\ClerksSelectAble;
|
||||
use App\Models\Area;
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
use Exception;
|
||||
use Modules\Mall\Models\Region;
|
||||
|
||||
class IndexController extends AdminController
|
||||
{
|
||||
|
||||
protected $title = '地区管理';
|
||||
|
||||
/**
|
||||
* Notes:
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/11 13:44
|
||||
* @return Grid
|
||||
*/
|
||||
public function grid(): Grid
|
||||
{
|
||||
$grid = new Grid(new Area());
|
||||
|
||||
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
||||
$actions->disableDelete();
|
||||
$actions->disableView();
|
||||
$actions->add(new AddStock());
|
||||
$actions->add(new SubStock());
|
||||
|
||||
});
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->column(1 / 3, function (Grid\Filter $filter) {
|
||||
$filter->like('title', '地区名称');
|
||||
});
|
||||
|
||||
$filter->column(1 / 3, function (Grid\Filter $filter) {
|
||||
$filter->equal('user_id', '管理员')->select()->ajax(route('admin.user.users.ajax'));
|
||||
});
|
||||
});
|
||||
|
||||
$grid->model()->with(['user.info']);
|
||||
|
||||
$grid->column('id', '序号');
|
||||
$grid->column('title', '地区名称');
|
||||
$grid->column('stock', '库存')
|
||||
->modal('变动记录', AreaStockAble::class);
|
||||
// $grid->column('user.username', '管理员')
|
||||
// ->display(function () {
|
||||
// return $this->user->username."({$this->user->info->nickname})";
|
||||
// });
|
||||
$grid->column('all_address', '地址')
|
||||
->display(function () {
|
||||
return $this->getFullAddress();
|
||||
});
|
||||
|
||||
$grid->column('clerks', '操作员')
|
||||
->belongsToMany(ClerksSelectAble::class);
|
||||
$grid->column('created_at', '创建时间');
|
||||
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 编辑表单
|
||||
*
|
||||
* @Date : 2021/7/15 5:09 下午
|
||||
* @Author : <Jason.C>
|
||||
* @return Form
|
||||
* @throws Exception
|
||||
*/
|
||||
public function form(): Form
|
||||
{
|
||||
|
||||
$form = new Form(new Area());
|
||||
|
||||
$form->text('title', '地区名称')->required();
|
||||
|
||||
// $form->select('user_id', '管理员')
|
||||
// ->options(function ($userId) {
|
||||
// $user = User::find($userId);
|
||||
// if ($user) {
|
||||
// return [$user->id => $user->username.' ['.$user->info->nickname.']'];
|
||||
// }
|
||||
// })
|
||||
// ->value(request()->user_id ?? '')
|
||||
// ->ajax(route('admin.user.users.ajax'))
|
||||
// ->required();
|
||||
|
||||
$form->belongsToMany('clerks', ClerksSelectAble::class, '关联操作员');
|
||||
|
||||
if ($form->isCreating()) {
|
||||
$form->number('stock', '库存(份)')->default(100)->help('1份2箱');
|
||||
}
|
||||
$form->select('province_id', '省份')
|
||||
->options(Region::where('parent_id', 1)->pluck('name', 'id'))
|
||||
->load('city_id', route('admin.mall.regions.region'))
|
||||
->required();
|
||||
$form->select('city_id', '城市')
|
||||
->options(function ($option) {
|
||||
$parent = Region::where('id', $option)->value('parent_id');
|
||||
|
||||
return Region::where(['parent_id' => $parent])->pluck('name', 'id');
|
||||
})
|
||||
->load('district_id', route('admin.mall.regions.region'))
|
||||
->required();
|
||||
$form->select('district_id', '区/县')
|
||||
->options(function ($option) {
|
||||
$parent = Region::where('id', $option)->value('parent_id');
|
||||
|
||||
return Region::where(['parent_id' => $parent])->pluck('name', 'id');
|
||||
})
|
||||
->required();
|
||||
$form->text('address', '详细地址')
|
||||
->required();
|
||||
$form->switch('status', '状态')
|
||||
->default(1);
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
@@ -2,33 +2,20 @@
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Bonus\IdentityBonus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Liuhelong\LaravelAdmin\Wechat\Models\WechatOffiaccountUser;
|
||||
use Modules\Coupon\Models\Coupon;
|
||||
use Modules\Coupon\Traits\WithCoupon;
|
||||
use Modules\User\Models\Identity;
|
||||
use Modules\User\Models\Order;
|
||||
use Modules\User\Models\UserInvite;
|
||||
use Modules\User\Models\UserStockLog;
|
||||
use Modules\User\Models\UserWechat;
|
||||
use Modules\User\Models\UserWechatOfficial;
|
||||
use Modules\User\Traits\RankDataTrait;
|
||||
use Modules\User\Traits\WechatTrait;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class TestController extends Controller
|
||||
{
|
||||
use WithCoupon, WechatTrait, RankDataTrait;
|
||||
use WechatTrait, RankDataTrait;
|
||||
|
||||
public function index()
|
||||
{
|
||||
$identities= Identity::all();
|
||||
$identities = Identity::all();
|
||||
dd($identities->toArray());
|
||||
}
|
||||
|
||||
@@ -55,20 +42,9 @@ class TestController extends Controller
|
||||
|
||||
$tables = [
|
||||
'admin_operation_log',
|
||||
'bouns',
|
||||
'bouns_orders',
|
||||
'bouns_user_perves',
|
||||
'coupon_grants',
|
||||
'coupon_item_use_logs',
|
||||
'coupon_use_logs',
|
||||
'favorites',
|
||||
'cms_logs',
|
||||
'failed_jobs',
|
||||
'gout_case_log_symptoms',
|
||||
'gout_case_logs',
|
||||
'gout_case_timelines',
|
||||
'gout_case_symptom',
|
||||
'gout_cases',
|
||||
'gout_surveys',
|
||||
'gout_votes',
|
||||
'jobs',
|
||||
'linker_relations',
|
||||
'linkers',
|
||||
@@ -81,7 +57,6 @@ class TestController extends Controller
|
||||
'mall_refund_logs',
|
||||
'mall_refunds',
|
||||
'mall_refund_expresses',
|
||||
'notifications',
|
||||
'payment_refunds',
|
||||
'payments',
|
||||
'user_account_logs',
|
||||
@@ -100,17 +75,18 @@ class TestController extends Controller
|
||||
'user_sms',
|
||||
'user_stock_logs',
|
||||
'user_stocks',
|
||||
'user_subscribes',
|
||||
'user_wechat_apps',
|
||||
'user_wechat_minis',
|
||||
'user_wechat_officials',
|
||||
'user_wechats',
|
||||
'users',
|
||||
'personal_access_tokens',
|
||||
'subscriptions',
|
||||
'task_logs',
|
||||
'task_users',
|
||||
'versions',
|
||||
'wechat_offiaccount_event_logs',
|
||||
'withdraw_alipay_accounts',
|
||||
'withdraw_bank_accounts',
|
||||
'withdraw_logs',
|
||||
'withdraws',
|
||||
'personal_access_tokens',
|
||||
];
|
||||
foreach ($tables as $table) {
|
||||
|
||||
10
app/Admin/Routes/area.php
Normal file
10
app/Admin/Routes/area.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Routing\Router;
|
||||
|
||||
Route::group([
|
||||
'namespace' => 'Area',
|
||||
], function (Router $router) {
|
||||
$router->resource('areas', 'IndexController');
|
||||
$router->resource('areas/codes', 'IndexController');
|
||||
});
|
||||
25
app/Admin/Selectable/AreaStockAble.php
Normal file
25
app/Admin/Selectable/AreaStockAble.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Selectable;
|
||||
|
||||
use App\Models\Area;
|
||||
use Encore\Admin\Widgets\Table;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
|
||||
class AreaStockAble implements Renderable
|
||||
{
|
||||
|
||||
public function render($key = null): string
|
||||
{
|
||||
$area = Area::find($key);
|
||||
$stocks = $area->stocks()->exists();
|
||||
$data = [];
|
||||
if ($stocks) {
|
||||
$data = $area->stocks()->select('amount', 'stock', 'created_at')->get()->toArray();
|
||||
}
|
||||
|
||||
$table = new Table(['变动值', '当前库存', '操作时间'], $data);
|
||||
return $table->render();
|
||||
}
|
||||
|
||||
}
|
||||
40
app/Admin/Selectable/ClerksSelectAble.php
Normal file
40
app/Admin/Selectable/ClerksSelectAble.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Selectable;
|
||||
|
||||
use Encore\Admin\Grid\Filter;
|
||||
use Encore\Admin\Grid\Selectable;
|
||||
use Modules\User\Models\User;
|
||||
|
||||
class ClerksSelectAble extends Selectable
|
||||
{
|
||||
|
||||
public $model = User::class;
|
||||
|
||||
public $perPage = 25;
|
||||
|
||||
public static function display(): \Closure
|
||||
{
|
||||
return function ($value) {
|
||||
|
||||
// 如果`$value`是数组,表示在`collaborators`列中使用,显示用分号`;`分隔的用户`name`字段
|
||||
if (is_array($value)) {
|
||||
return implode(';', array_column($value, 'show_name'));
|
||||
}
|
||||
// 否则为`author_id`列使用,直接显示用户的`name`字段
|
||||
return optional($this->clerks)->username;
|
||||
};
|
||||
}
|
||||
|
||||
public function make()
|
||||
{
|
||||
$this->column('id', 'ID');
|
||||
$this->column('username', '手机号');
|
||||
$this->column('info.nickname', '昵称');
|
||||
|
||||
$this->filter(function (Filter $filter) {
|
||||
$filter->like('username', '手机号');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
73
app/Api/Controllers/Area/IndexController.php
Normal file
73
app/Api/Controllers/Area/IndexController.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers\Area;
|
||||
|
||||
use App\Api\Controllers\Controller;
|
||||
use App\Api\Resources\Area\AreaCodeCollection;
|
||||
use App\Api\Resources\Area\AreaResource;
|
||||
use App\Models\Area;
|
||||
use App\Models\AreaCode;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Jason\Api\Api;
|
||||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 我管理的地区
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/11 15:37
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$user = Api::user();
|
||||
$areas = Area::query()
|
||||
->whereHas('areaClerks', function ($q) {
|
||||
$q->where('user_id', Api::userId());
|
||||
})
|
||||
->get();
|
||||
|
||||
return $this->success(AreaResource::collection($areas));
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 查看管理的提货码
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/11 15:42
|
||||
* @param Area $area
|
||||
*/
|
||||
public function codes(Area $area, Request $request)
|
||||
{
|
||||
$status = $request->status ?? '';
|
||||
|
||||
$codes = $area->areaCodes()
|
||||
->when($status, function ($q) use ($status) {
|
||||
$q->where('status', $status);
|
||||
})
|
||||
->paginate();
|
||||
return $this->success(new AreaCodeCollection($codes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 生成提货码
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/11 15:52
|
||||
* @param Area $area
|
||||
* @param Request $request
|
||||
* @return JsonResponse|mixed
|
||||
*/
|
||||
public function generate(Area $area, Request $request)
|
||||
{
|
||||
$res = $area->generate(Api::userId(), $request->num);
|
||||
if ($res === true) {
|
||||
return $this->success('生成成功');
|
||||
} else {
|
||||
return $this->failed($res);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
28
app/Api/Resources/Area/AreaCodeCollection.php
Normal file
28
app/Api/Resources/Area/AreaCodeCollection.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Resources\Area;
|
||||
|
||||
use App\Api\Resources\BaseCollection;
|
||||
use App\Api\Resources\User\UserBaseResource;
|
||||
|
||||
class AreaCodeCollection extends BaseCollection
|
||||
{
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'data' => $this->collection->map(function ($info) {
|
||||
return [
|
||||
'area_code' => $info->id,
|
||||
'user' => new UserBaseResource($info->user),
|
||||
'status' => [
|
||||
'status' => $info->status,
|
||||
'text' => $info->status_text,
|
||||
],
|
||||
];
|
||||
}),
|
||||
'page' => $this->page(),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
19
app/Api/Resources/Area/AreaResource.php
Normal file
19
app/Api/Resources/Area/AreaResource.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Resources\Area;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class AreaResource extends JsonResource
|
||||
{
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'area_id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'stock' => $this->stock,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
14
app/Api/Routes/area.php
Normal file
14
app/Api/Routes/area.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Routing\Router;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::group([
|
||||
'namespace' => 'Area',
|
||||
'middleware' => config('api.route.middleware_auth'),
|
||||
], function (Router $router) {
|
||||
$router->get('areas', 'IndexController@index');
|
||||
$router->get('areas/{area}/codes', 'IndexController@codes');
|
||||
$router->get('areas/{area}/generate', 'IndexController@generate');
|
||||
});
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Jobs\Bonus\BuyIdentityJob;
|
||||
use App\Models\Bouns;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Modules\Task\Facades\TaskFacade;
|
||||
use Modules\User\Events\UserOrderPaid;
|
||||
|
||||
class UserOrderPaidListener implements ShouldQueue
|
||||
@@ -21,21 +18,6 @@ class UserOrderPaidListener implements ShouldQueue
|
||||
'order_id' => $event->order->id,
|
||||
'type' => $event->order->type,
|
||||
];
|
||||
|
||||
// BuyIdentityJob::dispatch($user, $order, $source);//个人赠送水滴
|
||||
// Bouns::addBouns($order, $order->price);
|
||||
|
||||
#TODO 开通会员赠送水滴
|
||||
// TaskFacade::do('open_vip', $user->id, [
|
||||
// 'identity_id' => $event->order->identity_id
|
||||
// ]);
|
||||
|
||||
#TODO 邀请一名健康体验馆 赠送水滴
|
||||
// if ($user->parent) {
|
||||
// TaskFacade::do('recommend_ty', $user->parent->id, [
|
||||
// 'user_id' => $user->id
|
||||
// ]);
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
147
app/Models/Area.php
Normal file
147
app/Models/Area.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\Mall\Models\Traits\HasRegion;
|
||||
use Modules\User\Models\User;
|
||||
use Modules\User\Models\UserInvite;
|
||||
use Modules\User\Traits\BelongsToUser;
|
||||
|
||||
class Area extends Model
|
||||
{
|
||||
use BelongsToUser,
|
||||
HasRegion;
|
||||
|
||||
const STATUS_DOWN = 0;
|
||||
const STATUS_UP = 1;
|
||||
|
||||
const STATUS = [
|
||||
self::STATUS_DOWN => '下架',
|
||||
self::STATUS_UP => '上架',
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
self::created(function ($model) {
|
||||
self::addStock($model, $model->stock, true);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 操作员
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/11 13:57
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function clerks(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(
|
||||
User::class,
|
||||
(new AreaClerk())->getTable())->using(AreaClerk::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 操作员
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/11 15:53
|
||||
* @return HasMany
|
||||
*/
|
||||
public function areaClerks(): HasMany
|
||||
{
|
||||
return $this->hasMany(AreaClerk::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 关联库存变动表
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/11 14:54
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function stocks(): HasMany
|
||||
{
|
||||
return $this->hasMany(AreaStock::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 关联提货券
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/11 15:43
|
||||
* @return HasMany
|
||||
*/
|
||||
public function areaCodes(): HasMany
|
||||
{
|
||||
return $this->hasMany(AreaCode::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 增加库存
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/11 14:50
|
||||
* @param $number
|
||||
*/
|
||||
public static function addStock($area, $number, $isCreate = false)
|
||||
{
|
||||
$stock = $area->stock;
|
||||
|
||||
if ($isCreate) {
|
||||
$all = $number;
|
||||
} else {
|
||||
$area->increment('stock', $number);
|
||||
$all = bcadd($number, $stock);
|
||||
}
|
||||
$area->stocks()->create([
|
||||
'amount' => $number,
|
||||
'stock' => $all,
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 生成提货码
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/11 16:00
|
||||
* @param $num
|
||||
*/
|
||||
public function generate($user_id, $num)
|
||||
{
|
||||
try {
|
||||
if (! $num) {
|
||||
throw new \Exception('缺少数量');
|
||||
}
|
||||
if ($this->stock < $num) {
|
||||
throw new \Exception('可生成数量不足,您还可以释放'.$this->stock);
|
||||
}
|
||||
|
||||
while ($num > 0) {
|
||||
$data[] = [
|
||||
'area_id' => $this->id,
|
||||
'manage_id' => $user_id,
|
||||
'code' => Str::random(14),
|
||||
'status' => AreaCode::STATUS_INIT,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
--$num;
|
||||
}
|
||||
|
||||
AreaCode::insert($data);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $exception) {
|
||||
return $exception->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
15
app/Models/AreaClerk.php
Normal file
15
app/Models/AreaClerk.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\BelongsToArea;
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
use Modules\User\Traits\BelongsToUser;
|
||||
|
||||
class AreaClerk extends Pivot
|
||||
{
|
||||
use BelongsToArea, BelongsToUser;
|
||||
|
||||
protected $table = 'area_clerks';
|
||||
|
||||
}
|
||||
36
app/Models/AreaCode.php
Normal file
36
app/Models/AreaCode.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\BelongsToArea;
|
||||
use App\Traits\HasStatus;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Modules\User\Models\User;
|
||||
use Modules\User\Traits\BelongsToUser;
|
||||
|
||||
class AreaCode extends Model
|
||||
{
|
||||
use BelongsToArea, BelongsToUser, HasStatus;
|
||||
|
||||
const STATUS_INIT = 0;
|
||||
const STATUS_USED = 1;
|
||||
|
||||
const STATUS = [
|
||||
self::STATUS_INIT => '未使用',
|
||||
self::STATUS_USED => '已使用',
|
||||
];
|
||||
|
||||
/**
|
||||
* Notes: 生成人-管理人
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/11 13:41
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function manage(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
11
app/Models/AreaStock.php
Normal file
11
app/Models/AreaStock.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
use App\Models\Traits\BelongsToArea;
|
||||
|
||||
class AreaStock extends Model
|
||||
{
|
||||
use BelongsToArea;
|
||||
}
|
||||
23
app/Models/Traits/BelongsToArea.php
Normal file
23
app/Models/Traits/BelongsToArea.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Traits;
|
||||
|
||||
use App\Models\Area;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
trait BelongsToArea
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 关联地区
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/11 13:40
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function area(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Area::class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,7 +35,7 @@ return [
|
||||
| login page.
|
||||
|
|
||||
*/
|
||||
'name' => '修缮庙宇',
|
||||
'name' => '备水疫战',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -45,7 +45,7 @@ return [
|
||||
| Html title for all pages.
|
||||
|
|
||||
*/
|
||||
'title' => '修缮庙宇',
|
||||
'title' => '备水疫战',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -56,7 +56,7 @@ return [
|
||||
| `img` tag, eg '<img src="http://logo-url" alt="Admin logo">'.
|
||||
|
|
||||
*/
|
||||
'logo' => '修缮庙宇 功德无量',
|
||||
'logo' => '备水疫战 功德无量',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
41
database/migrations/2023_01_11_132844_create_areas_table.php
Normal file
41
database/migrations/2023_01_11_132844_create_areas_table.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateAreasTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('areas', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('user_id')->nullable()->index();
|
||||
$table->string('title');
|
||||
$table->string('mobile', 32);
|
||||
$table->unsignedInteger('province_id');
|
||||
$table->unsignedInteger('city_id');
|
||||
$table->unsignedInteger('district_id');
|
||||
$table->string('address');
|
||||
$table->integer('stock')->default(0)->comment('库存');
|
||||
$table->integer('sold')->default(0)->comment('领取数');
|
||||
$table->boolean('status')->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('areas');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateAreaCodesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('area_codes', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('user_id')->nullable()->index();
|
||||
$table->unsignedBigInteger('manage_id')->index();
|
||||
$table->unsignedBigInteger('area_id')->index();
|
||||
$table->string('code');
|
||||
$table->boolean('status')->default(0);
|
||||
$table->timestamp('pick_at')->nullable()->comment('提货时间');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('area_codes');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateAreaClerksTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('area_clerks', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedInteger('area_id')->comment('订单')->index();
|
||||
$table->unsignedInteger('user_id')->comment('操作员')->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('area_clerks');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateAreaStocksTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('area_stocks', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('area_id');
|
||||
$table->integer('amount')->comment('增加值');
|
||||
$table->integer('stock')->comment('库存量');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('area_stocks');
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,5 @@
|
||||
"Mall": true,
|
||||
"Cms": true,
|
||||
"Payment": true,
|
||||
"Gout": true,
|
||||
"Linker": false,
|
||||
"Notification": true,
|
||||
"Coupon": true,
|
||||
"Configuration": true,
|
||||
"Withdraw": true
|
||||
"Configuration": true
|
||||
}
|
||||
4
modules/Configuration/.gitignore
vendored
4
modules/Configuration/.gitignore
vendored
@@ -1,4 +0,0 @@
|
||||
.idea
|
||||
vendor
|
||||
.DS_Store
|
||||
composer.lock
|
||||
@@ -1,6 +0,0 @@
|
||||
# laravel-configuration-module
|
||||
|
||||
# 参数配置模块
|
||||
|
||||
## 需要config的模块配置
|
||||
|
||||
4
modules/Coupon/.gitignore
vendored
4
modules/Coupon/.gitignore
vendored
@@ -1,4 +0,0 @@
|
||||
.idea
|
||||
vendor
|
||||
.DS_Store
|
||||
composer.lock
|
||||
@@ -1,10 +0,0 @@
|
||||
# 优惠券模块
|
||||
|
||||
> 1、发布config并配置相关模型
|
||||
|
||||
> 2、关联traits
|
||||
|
||||
```php
|
||||
Shop Model
|
||||
use HasStores,HasCoupons;
|
||||
```
|
||||
@@ -1,154 +0,0 @@
|
||||
# Notification
|
||||
|
||||
通知模块
|
||||
|
||||
## 1. 安装
|
||||
|
||||
```shell
|
||||
composer require getuilaboratory/getui-pushapi-php-client-v2
|
||||
```
|
||||
|
||||
## 2. 接口文档
|
||||
|
||||
### 1. 获取未读消息数量(不登陆返回0)
|
||||
|
||||
> GET: /api/notifications/counts
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "SUCCESS",
|
||||
"status_code": 200,
|
||||
"data": 16
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 消息主页
|
||||
|
||||
> GET: /api/notifications
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "SUCCESS",
|
||||
"status_code": 200,
|
||||
"data": [
|
||||
{
|
||||
"type": "SystemNotification",
|
||||
"icon": "",
|
||||
"name": "系统通知",
|
||||
"count": 16,
|
||||
"title": "登录成功"
|
||||
},
|
||||
{
|
||||
"type": "OrderNotification",
|
||||
"icon": "",
|
||||
"name": "订单通知",
|
||||
"count": 0,
|
||||
"title": ""
|
||||
},
|
||||
{
|
||||
"type": "ActivityNotification",
|
||||
"icon": "",
|
||||
"name": "活动通知",
|
||||
"count": 0,
|
||||
"title": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 分类消息的列表
|
||||
|
||||
> GET: /api/notifications/{type}/list
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "SUCCESS",
|
||||
"status_code": 200,
|
||||
"data": {
|
||||
"data": [
|
||||
{
|
||||
"notification_id": "91e31d1e-95e1-40ff-88d8-8049df974860",
|
||||
"type": "SystemNotification",
|
||||
"title": "登录成功",
|
||||
"content": "您于北京时间:2021-07-02 15:31:03,通过【账号密码】渠道,在IP:1.190.203.218成功登录系统。请注意保管好您的账号密码。",
|
||||
"read_at": "",
|
||||
"created_at": "2021-07-02 15:31:03"
|
||||
}
|
||||
],
|
||||
"page": {
|
||||
"current": 1,
|
||||
"total_page": 2,
|
||||
"per_page": 15,
|
||||
"has_more": true,
|
||||
"total": 16
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 4. 消息详情
|
||||
|
||||
> GET: /api/notifications/{notification_id}
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "SUCCESS",
|
||||
"status_code": 200,
|
||||
"data": {
|
||||
"notification_id": "91e31d1e-95e1-40ff-88d8-8049df974860",
|
||||
"type": "SystemNotification",
|
||||
"title": "登录成功",
|
||||
"content": "您于北京时间:2021-07-02 15:31:03,通过【账号密码】渠道,在IP:1.190.203.218成功登录系统。请注意保管好您的账号密码。",
|
||||
"read_at": "2021-07-02 16:27:07",
|
||||
"created_at": "2021-07-02 15:31:03"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 5. 全部标记已读
|
||||
|
||||
> PUT: /api/notifications
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "SUCCESS",
|
||||
"status_code": 200,
|
||||
"data": ""
|
||||
}
|
||||
```
|
||||
|
||||
### 6. 全部标记已读(分类)
|
||||
|
||||
> PUT: /api/notifications/{type}
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "SUCCESS",
|
||||
"status_code": 200,
|
||||
"data": ""
|
||||
}
|
||||
```
|
||||
|
||||
### 7. 清空全部消息
|
||||
|
||||
> DELETE: /api/notifications
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "SUCCESS",
|
||||
"status_code": 200,
|
||||
"data": ""
|
||||
}
|
||||
```
|
||||
|
||||
### 8. 清空分类消息
|
||||
|
||||
> DELETE: /api/notifications/{type}
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "SUCCESS",
|
||||
"status_code": 200,
|
||||
"data": ""
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user