mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-11-30 22:20:45 +00:00
58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Shop;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Resources\ShopsResource;
|
|
use App\Models\Shop;
|
|
use App\Models\ShopSender;
|
|
use App\Models\ShopShip;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class ShipController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$shopShips = ShopShip::query()
|
|
->select(['id', 'type', 'shop_id', 'expires_at', 'owner_id', 'owner_name'])
|
|
->with('shop:id,name')
|
|
->get();
|
|
$time = date('Y-m-d H:i:s');
|
|
foreach ($shopShips as $shopShip) {
|
|
if ($shopShip->expires_at && $time >= $shopShip->expires_at) {
|
|
ShopShip::query()->where('shop_id', $shopShip->shop_id)->update(['status' => Shop::$STATUS_UNAUTHORIZED]);
|
|
}
|
|
}
|
|
|
|
return ShopsResource::collection($shopShips);
|
|
}
|
|
|
|
public function getSenders(Request $request)
|
|
{
|
|
$senders = ShopSender::query()
|
|
->where('shop_id', $request->get('shop_id'))
|
|
->where('shop_ship_id', $request->get('shop_ship_id'))
|
|
->orderBy('sort')
|
|
->get();
|
|
|
|
return JsonResource::collection($senders);
|
|
}
|
|
|
|
public function saveSenders(Request $request)
|
|
{
|
|
$senderList = $request->input('senderList');
|
|
foreach ($senderList as $item) {
|
|
$item = json_decode($item, true);
|
|
$sender = ShopSender::query()->findOrFail($item['id']);
|
|
$sender->name = $item['name'];
|
|
$sender->mobile = $item['mobile'];
|
|
$sender->sort = $item['sort'];
|
|
$sender->status = $item['status'];
|
|
$sender->save();
|
|
}
|
|
|
|
return response(['message' => '保存成功']);
|
|
}
|
|
}
|