|
|
|
@ -13,6 +13,7 @@ use Dcat\Admin\Form\NestedForm; |
|
|
|
use Dcat\Admin\Grid; |
|
|
|
use Dcat\Admin\Show; |
|
|
|
use Dcat\Admin\Http\Controllers\AdminController; |
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
|
|
|
|
class IndustryProductController extends AdminController |
|
|
|
{ |
|
|
|
@ -202,12 +203,6 @@ class IndustryProductController extends AdminController |
|
|
|
$form->deleteInput('type'); |
|
|
|
} |
|
|
|
|
|
|
|
//判断交易金是否充足
|
|
|
|
$single = SystemSetting::val('single', 'price'); //单人头交易费
|
|
|
|
if (!$single || Admin::user()->deposit_normal < $single * $form->service_persons * $form->stock) { |
|
|
|
return $form->response()->error('交易金不足,请先联系管理员充值'); |
|
|
|
} |
|
|
|
|
|
|
|
//忽略字段
|
|
|
|
$form->ignore(['id', 'sale', 'created_at', 'updated_at', 'deleted_at']); |
|
|
|
|
|
|
|
@ -218,24 +213,42 @@ class IndustryProductController extends AdminController |
|
|
|
} else if ($form->isEditing() && in_array($form->model()->status, [ProductStatus::SOLD_OUT, ProductStatus::ON_SALE])) { //如果原来是下架或上架状态才允许修改
|
|
|
|
$form->status = $form->status == ProductStatus::ON_SALE ? ProductStatus::ON_SALE : ProductStatus::SOLD_OUT; |
|
|
|
} |
|
|
|
})->saved(function (Form $form, $result) { |
|
|
|
if ($form->isEditing() && $form->model()->wasChanged(['title', 'price', 'original_price', 'pictures', 'know', 'content'])) { //有extends判断不准
|
|
|
|
$form->model()->update(['status' => ProductStatus::UNAUDITED]); |
|
|
|
|
|
|
|
//处理交易金
|
|
|
|
//判断交易金是否充足
|
|
|
|
$single = SystemSetting::val('single', 'price'); //单人头交易费
|
|
|
|
if (!$single) { |
|
|
|
return $form->response()->error('没有可用交易金,请先联系管理员充值'); |
|
|
|
} |
|
|
|
|
|
|
|
//目前逻辑不考虑单人头交易费变动的情况
|
|
|
|
if ($result) { //新增处理
|
|
|
|
if ($form->isCreating()) { |
|
|
|
$single = SystemSetting::val('single', 'price'); //单人头交易费
|
|
|
|
$change = $single * $form->service_persons * $form->stock; //变动的交易金
|
|
|
|
if ($form->isCreating() || $form->isEditing() && $form->model()->stock != $form->stock) { |
|
|
|
DB::beginTransaction(); |
|
|
|
|
|
|
|
$supplier = Supplier::query()->find(Admin::user()->id); //不能使用Admin::user()修改,必须使用Supplier模型才能正确记录资金变动日志
|
|
|
|
$supplier->deposit_normal = $supplier->deposit_normal - $change; //正常交易金
|
|
|
|
$supplier->deposit_frozen = $supplier->deposit_frozen + $change; //冻结交易金
|
|
|
|
$supplier->save(); |
|
|
|
} else if ($form->isEditing()) { |
|
|
|
$supplier = Supplier::query()->find(Admin::user()->id); //不能使用Admin::user()修改,必须使用Supplier模型才能正确记录资金变动日志
|
|
|
|
|
|
|
|
if ($form->isCreating()) { //新增处理
|
|
|
|
$change_deposit = $single * $form->service_persons * $form->stock; |
|
|
|
} else if ($form->isEditing() && $form->model()->stock != $form->stock) { //库存变动时冻结或解冻相应的保证金
|
|
|
|
$change_deposit = $single * $form->service_persons * ($form->stock - $form->model()->stock); |
|
|
|
} |
|
|
|
|
|
|
|
if (Admin::user()->deposit_normal < $change_deposit) { |
|
|
|
DB::rollBack(); |
|
|
|
return $form->response()->error('交易金不足,请先联系管理员充值'); |
|
|
|
} |
|
|
|
|
|
|
|
$supplier->deposit_normal = $supplier->deposit_normal - $change_deposit; //正常交易金
|
|
|
|
$supplier->deposit_frozen = $supplier->deposit_frozen + $change_deposit; //冻结交易金
|
|
|
|
$supplier->save(); |
|
|
|
} |
|
|
|
})->saved(function (Form $form, $result) { |
|
|
|
if ($form->isEditing() && $form->model()->wasChanged(['title', 'price', 'original_price', 'pictures', 'know', 'content'])) { //有extends判断不准
|
|
|
|
$form->model()->update(['status' => ProductStatus::UNAUDITED]); |
|
|
|
} |
|
|
|
|
|
|
|
if ($result) { |
|
|
|
DB::commit(); |
|
|
|
} |
|
|
|
})->deleting(function (Form $form) { |
|
|
|
//不允许删除非自己的数据
|
|
|
|
|