阶段更新
This commit is contained in:
@@ -16,7 +16,7 @@ class AreaCodeController extends Controller
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/12 11:03
|
||||
* @param AreaCode $areaCode
|
||||
* @param AreaCode $code
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function show(AreaCode $code)
|
||||
@@ -24,10 +24,48 @@ class AreaCodeController extends Controller
|
||||
return $this->success(new AreaCodeResource($code));
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 根据提货码查询信息
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/16 9:48
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function info(Request $request)
|
||||
{
|
||||
$code = AreaCode::query()->where('code', $request->code)->first();
|
||||
return $this->success(new AreaCodeResource($code));
|
||||
if (! $code) {
|
||||
return $this->failed('未查询到此提货码信息');
|
||||
} else {
|
||||
return $this->success(new AreaCodeResource($code));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 核销提货码
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/16 10:56
|
||||
* @param Request $request
|
||||
* @return JsonResponse|mixed
|
||||
*/
|
||||
public function verify(Request $request)
|
||||
{
|
||||
$code = $request->code ?? '';
|
||||
if (! $code) {
|
||||
return $this->failed('缺少提货码');
|
||||
}
|
||||
$areaCode = AreaCode::query()->where('code', $code)->first();
|
||||
if ($areaCode->status != AreaCode::STATUS_INIT) {
|
||||
return $this->failed('此提货码已提货');
|
||||
}
|
||||
try {
|
||||
$areaCode->sign();
|
||||
return $this->success('提货成功');
|
||||
} catch (\Exception $exception) {
|
||||
return $this->failed($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,30 +33,28 @@ class IndexController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 查看管理的提货码
|
||||
* Notes: 查看库存量
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/11 15:42
|
||||
* @param Area $area
|
||||
* @Date: 2023/1/16 11:19
|
||||
* @return JsonResponse|mixed
|
||||
*/
|
||||
public function codes(Request $request)
|
||||
public function show()
|
||||
{
|
||||
$status = $request->status ?? '';
|
||||
|
||||
$area = Area::query()
|
||||
->whereHas('areaClerks', function ($q) {
|
||||
$q->where('user_id', Api::userId());
|
||||
})
|
||||
->first();
|
||||
|
||||
$codes = $area->areaCodes()
|
||||
->when($status, function ($q) use ($status) {
|
||||
$q->where('status', $status);
|
||||
})
|
||||
->paginate();
|
||||
if (! $area) {
|
||||
return $this->failed('您没有管理的区域无法查看');
|
||||
}
|
||||
|
||||
$codes = $area->areaCodes()->latest()->paginate();
|
||||
$release = $area->areaCodes()->count();
|
||||
$data = [
|
||||
|
||||
$data = [
|
||||
'count' => [
|
||||
'all' => $area->stocks()->sum('amount'),
|
||||
'stock' => $area->stock,
|
||||
@@ -69,6 +67,36 @@ class IndexController extends Controller
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 查看管理的提货码
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/11 15:42
|
||||
* @param Request $request
|
||||
* @return JsonResponse|mixed
|
||||
*/
|
||||
public function codes(Request $request)
|
||||
{
|
||||
$status = $request->status ?? '';
|
||||
|
||||
$area = Area::query()
|
||||
->whereHas('areaClerks', function ($q) {
|
||||
$q->where('user_id', Api::userId());
|
||||
})
|
||||
->first();
|
||||
if (! $area) {
|
||||
return $this->failed('您没有管理的区域无法查看');
|
||||
}
|
||||
|
||||
$codes = $area->areaCodes()
|
||||
->when($status, function ($q) use ($status) {
|
||||
$q->where('status', $status);
|
||||
})
|
||||
->paginate();
|
||||
|
||||
return $this->success(new AreaCodeCollection($codes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 生成提货码
|
||||
*
|
||||
|
||||
28
app/Api/Resources/Area/AreaCodeVerifyResource.php
Normal file
28
app/Api/Resources/Area/AreaCodeVerifyResource.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Resources\Area;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use SimpleSoftwareIO\QrCode\Facades\QrCode;
|
||||
use DNS1D;
|
||||
|
||||
|
||||
class AreaCodeVerifyResource extends JsonResource
|
||||
{
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'area_code_id' => $this->id,
|
||||
'code' => $this->code,
|
||||
// 'code_img' => 'data:image/jpg;base64,'.base64_encode(QrCode::format('png')
|
||||
// ->errorCorrection("L")
|
||||
// ->size(300)
|
||||
// ->margin(0)
|
||||
// ->generate($this->code)),
|
||||
'barcode' => 'data:image/png;base64,'.DNS1D::getBarcodePNG($this->code, 'C128', 2, 50),
|
||||
'area' => new AreaFullResource($this->area),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ Route::group([
|
||||
'middleware' => config('api.route.middleware_auth'),
|
||||
], function (Router $router) {
|
||||
$router->get('areas', 'IndexController@index');
|
||||
$router->get('areas/show', 'IndexController@show');
|
||||
$router->get('areas/codes', 'IndexController@codes');
|
||||
$router->get('areas/generate', 'IndexController@generate');
|
||||
});
|
||||
@@ -19,5 +20,6 @@ Route::group([
|
||||
], function (Router $router) {
|
||||
$router->get('areas/{code}/show', 'AreaCodeController@show');
|
||||
$router->get('areas/code/info', 'AreaCodeController@info');
|
||||
$router->post('areas/code/{code}/verify', 'AreaCodeController@verify');
|
||||
});
|
||||
|
||||
|
||||
@@ -15,10 +15,12 @@ class AreaCode extends Model
|
||||
|
||||
const STATUS_INIT = 0;
|
||||
const STATUS_USED = 1;
|
||||
const STATUS_SIGN = 2;
|
||||
|
||||
const STATUS = [
|
||||
self::STATUS_INIT => '未提取',
|
||||
self::STATUS_USED => '已提取',
|
||||
self::STATUS_SIGN => '已核销',
|
||||
];
|
||||
|
||||
|
||||
@@ -46,6 +48,21 @@ class AreaCode extends Model
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 核销
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/1/16 11:15
|
||||
*/
|
||||
public function sign()
|
||||
{
|
||||
$this->order->state = Order::STATUS_SIGNED;
|
||||
$this->order->save();
|
||||
$this->status = self::STATUS_SIGN;
|
||||
$this->save();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 关联订单
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user