|
|
@ -6,7 +6,10 @@ use App\AdminAgent\Extensions\Grid\SupplierShowQrcode; |
|
|
use App\AdminAgent\Repositories\IndustryOrder; |
|
|
use App\AdminAgent\Repositories\IndustryOrder; |
|
|
use App\Common\OrderStatus; |
|
|
use App\Common\OrderStatus; |
|
|
use App\Common\PayType; |
|
|
use App\Common\PayType; |
|
|
|
|
|
use App\Common\ProductStatus; |
|
|
use App\Models\AdminSetting; |
|
|
use App\Models\AdminSetting; |
|
|
|
|
|
use App\Models\IndustryProduct; |
|
|
|
|
|
use App\Models\IndustryProductSpec; |
|
|
use Dcat\Admin\Admin; |
|
|
use Dcat\Admin\Admin; |
|
|
use Dcat\Admin\Form; |
|
|
use Dcat\Admin\Form; |
|
|
use Dcat\Admin\Grid; |
|
|
use Dcat\Admin\Grid; |
|
|
@ -17,6 +20,7 @@ use Dcat\Admin\Widgets\Modal; |
|
|
use Dcat\Admin\Widgets\Table; |
|
|
use Dcat\Admin\Widgets\Table; |
|
|
use EasyWeChat\Factory; |
|
|
use EasyWeChat\Factory; |
|
|
use EasyWeChat\Kernel\Http\StreamResponse; |
|
|
use EasyWeChat\Kernel\Http\StreamResponse; |
|
|
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
use Illuminate\Support\Facades\Storage; |
|
|
use Illuminate\Support\Facades\Storage; |
|
|
|
|
|
|
|
|
class IndustryOrderController extends AdminController |
|
|
class IndustryOrderController extends AdminController |
|
|
@ -261,11 +265,9 @@ JS |
|
|
return redirect(admin_url('industry_order/list'))->send(); |
|
|
return redirect(admin_url('industry_order/list'))->send(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$form->display('id'); |
|
|
|
|
|
|
|
|
|
|
|
$form->number('num'); |
|
|
|
|
|
$form->number('name'); |
|
|
|
|
|
$form->mobile('mobile'); |
|
|
|
|
|
|
|
|
$form->number('num')->required()->min(IndustryProduct::where('id', $form->model()->industry_product_id)->value('min_sale') ?? 1); |
|
|
|
|
|
$form->text('name', '您的姓名')->required(); |
|
|
|
|
|
$form->mobile('mobile', '您的手机号')->required(); |
|
|
|
|
|
|
|
|
//支付信息
|
|
|
//支付信息
|
|
|
$pay_type = [PayType::ONLINE, PayType::OFFLINE]; |
|
|
$pay_type = [PayType::ONLINE, PayType::OFFLINE]; |
|
|
@ -323,8 +325,50 @@ JS |
|
|
$form->info = $fields; |
|
|
$form->info = $fields; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$form->hidden(['audit_status']); |
|
|
|
|
|
|
|
|
$form->hidden(['audit_status', 'price', 'trade_deposit', 'single_price']); |
|
|
$form->audit_status = 0; |
|
|
$form->audit_status = 0; |
|
|
|
|
|
|
|
|
|
|
|
//产品规格
|
|
|
|
|
|
$spec = IndustryProductSpec::where([ |
|
|
|
|
|
['industry_product_id', '=', $form->model()->industry_product_id], |
|
|
|
|
|
['stock', '>=', $form->num], |
|
|
|
|
|
])->find($form->model()->industry_product_spec_id); |
|
|
|
|
|
if (!$spec) { |
|
|
|
|
|
return $form->response()->error('产品规格不存在或库存不足'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$industry_product = IndustryProduct::where([ |
|
|
|
|
|
['status', '=', ProductStatus::ON_SALE], |
|
|
|
|
|
['stock', '>=', $form->num] |
|
|
|
|
|
])->find($form->model()->industry_product_id); |
|
|
|
|
|
if (empty($industry_product)) { |
|
|
|
|
|
return $form->response()->error('产品不存在或库存不足'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$form->price = $form->num * $spec['price']; |
|
|
|
|
|
$form->trade_deposit = $industry_product->single_deposit * $form->num; |
|
|
|
|
|
$form->single_price = $industry_product->single_deposit; |
|
|
|
|
|
|
|
|
|
|
|
DB::beginTransaction(); |
|
|
|
|
|
try { |
|
|
|
|
|
# 产品表减库存
|
|
|
|
|
|
$industry_product->stock -= $form->num; |
|
|
|
|
|
$industry_product->save(); |
|
|
|
|
|
if ($industry_product->stock < 0) { |
|
|
|
|
|
throw new \Exception('产品库存足'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# 规格减库存
|
|
|
|
|
|
$spec->stock -= $form->num; |
|
|
|
|
|
$spec->save(); |
|
|
|
|
|
if ($spec->stock < 0) { |
|
|
|
|
|
throw new \Exception('产品规格库存足'); |
|
|
|
|
|
} |
|
|
|
|
|
DB::commit(); |
|
|
|
|
|
} catch (\Exception $exception) { |
|
|
|
|
|
DB::rollBack(); |
|
|
|
|
|
return $form->response()->error($exception->getMessage()); |
|
|
|
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |