海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

77 lines
2.0 KiB

<?php
namespace App\AdminSupplier\Extensions\Grid;
use App\Common\OrderStatus;
use App\Models\IndustryOrder;
use App\Models\IndustryProduct;
use App\Models\Supplier;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid\RowAction;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
/**
* 供应商审核
* Class AuditSupplier
* @package App\Admin\Extensions\Grid
*/
class IndustryOrderStatus extends RowAction
{
protected $title = '设为已付款';
protected function html()
{
$class = 'btn btn-sm btn-success';
$this->appendHtmlAttribute('class', $class);
$this->defaultHtmlAttribute('href', 'javascript:;');
return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>";
}
public function handle(Request $request)
{
$id = $this->getKey();
DB::beginTransaction();
try {
$order = IndustryOrder::where(['id' => $id, 'status' => OrderStatus::OFFLINE_UNPAID])->find($id);
if (!$order) {
throw new \Exception('订单不存在或者已审核过了');
}
//操作订单表
$order->status = OrderStatus::OFFLINE_PAID;
$order->paid_at = now();
$order->verify_code = uniqid();
$order->save();
//减库存
$affect_row = IndustryProduct::where([
['id', '=', $order->industry_product_id],
['stock', '>=', $order->num],
])->decrement('stock', $order->num);
if (!$affect_row) {
throw new \Exception('库存不足,请先增加库存');
}
//扣除交易金
$supplier = Supplier::find(Admin::user()->id); //不能使用Admin::user()修改,必须使用Supplier模型才能正确记录资金变动日志
$supplier->deposit_used = $supplier->deposit_used + $order->deposit;
$supplier->deposit_frozen = $supplier->deposit_frozen - $order->deposit;
$supplier->save();
DB::commit();
return $this->response()->success('操作成功');
} catch (\Exception $e) {
DB::rollBack();
return $this->response()->error($e->getMessage());
}
}
public function confirm()
{
return ['确定要设置为已付款吗?', ''];
}
}