|
|
|
@ -2,19 +2,15 @@ |
|
|
|
|
|
|
|
namespace App\AdminAgent\Controllers; |
|
|
|
|
|
|
|
use App\AdminAgent\Renderable\SelectIndustryProductSpec; |
|
|
|
use App\AdminAgent\Repositories\IndustryOrder; |
|
|
|
use App\Common\OrderStatus; |
|
|
|
use App\Common\PayType; |
|
|
|
use App\Common\ProductStatus; |
|
|
|
use App\Models\AdminSetting; |
|
|
|
use App\Models\IndustryProduct; |
|
|
|
use App\Models\IndustryProductSpec; |
|
|
|
use Dcat\Admin\Admin; |
|
|
|
use Dcat\Admin\Form; |
|
|
|
use Dcat\Admin\Grid; |
|
|
|
use Dcat\Admin\Show; |
|
|
|
use Dcat\Admin\Http\Controllers\AdminController; |
|
|
|
use Dcat\Admin\Widgets\Table; |
|
|
|
use EasyWeChat\Factory; |
|
|
|
use EasyWeChat\Kernel\Http\StreamResponse; |
|
|
|
use Illuminate\Support\Facades\Storage; |
|
|
|
@ -43,6 +39,26 @@ class IndustryOrderController extends AdminController |
|
|
|
$grid->column('price'); |
|
|
|
$grid->column('name', '预留姓名'); |
|
|
|
$grid->column('mobile', '预留手机'); |
|
|
|
$grid->column('info', '客户信息') |
|
|
|
->display('查看') |
|
|
|
->modal('客户信息', function ($modal) { |
|
|
|
$info = $this->info ?? []; |
|
|
|
$info = array_map(function($v) { |
|
|
|
if (isset($v['value'], $v['type'])) { |
|
|
|
if ($v['type'] == 'image') { |
|
|
|
if (is_array($v['value'])) { |
|
|
|
return array_reduce($v['value'], fn($v2, $v3) => $v2 . '<img data-action="preview-img" src="' . $v3 . '" style="max-width:120px;max-height:200px;cursor:pointer" class="img img-thumbnail"> '); |
|
|
|
} else { |
|
|
|
return '<img data-action="preview-img" src="' . $v['value'] . '" style="max-width:120px;max-height:200px;cursor:pointer" class="img img-thumbnail">'; |
|
|
|
} |
|
|
|
} else { |
|
|
|
return is_string($v['value']) ? $v['value'] : join(',', $v['value']); |
|
|
|
} |
|
|
|
} |
|
|
|
return is_string($v) ? $v : json_encode($v); |
|
|
|
}, $info); |
|
|
|
return Table::make([], $info); |
|
|
|
})->xl(); |
|
|
|
$grid->column('title')->limit(15); |
|
|
|
$grid->column('picture')->image('', 80, 80); |
|
|
|
$grid->column('status') |
|
|
|
@ -209,134 +225,4 @@ JS |
|
|
|
'trade_type' => 'NATIVE', // 请对应换成你的支付方式对应的值类型
|
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Make a form builder. |
|
|
|
* |
|
|
|
* @return Form |
|
|
|
*/ |
|
|
|
/*protected function form() |
|
|
|
{ |
|
|
|
$pid = request()->input('pid'); |
|
|
|
$industry = IndustryProduct::with('diyForm.fields') |
|
|
|
->where([ |
|
|
|
['status', '=', ProductStatus::ON_SALE], |
|
|
|
['stock', '>', 0], |
|
|
|
])->find($pid); |
|
|
|
|
|
|
|
return Form::make(new IndustryOrder(), function (Form $form) use ($industry) { |
|
|
|
if (!$industry) { |
|
|
|
Admin::exit('订单不允许编辑'); |
|
|
|
} |
|
|
|
|
|
|
|
$form->selectTable('industry_product_spec_id', '选择产品规格') |
|
|
|
->required() |
|
|
|
->title('选择产品规格') |
|
|
|
->dialogWidth('80%;min-width:825px;') |
|
|
|
->from(SelectIndustryProductSpec::make(['industry_product_id' => request()->input('pid')])) |
|
|
|
->model(IndustryProductSpec::class); |
|
|
|
|
|
|
|
$form->hidden('pid')->value($industry->id); //pid要跟上面的request中的一样,否则提交出错
|
|
|
|
$form->number('num') |
|
|
|
->min($industry->min_sale)->required() |
|
|
|
->default($industry->min_sale); |
|
|
|
$form->text('name')->default(Admin::user()->director)->required(); |
|
|
|
$form->mobile('mobile')->default(Admin::user()->contact_phone)->required(); |
|
|
|
|
|
|
|
$pay_type = [PayType::ONLINE, PayType::OFFLINE]; |
|
|
|
if ($industry->deposit) { //订金支付
|
|
|
|
$pay_type = [...$pay_type, PayType::DEPOSIT_PAY]; |
|
|
|
} |
|
|
|
if ($industry->earnest) { //定金支付
|
|
|
|
$pay_type = [...$pay_type, PayType::EARNEST_PAY]; |
|
|
|
} |
|
|
|
$options = array_filter(PayType::array(), fn($k) => in_array($k, $pay_type), ARRAY_FILTER_USE_KEY); |
|
|
|
$form->select('pay_type')->options($options)->default(PayType::ONLINE)->required(); |
|
|
|
|
|
|
|
//信息收集表单 TODO 信息收集表单文件上传不了,不能用事务
|
|
|
|
if (!empty($industry->diyForm->fields)) { |
|
|
|
$form->divider(); |
|
|
|
$fields = $industry->diyForm->fields->toArray(); |
|
|
|
foreach ($fields as $v) { |
|
|
|
if ($v['type'] == 'radio' || $v['type'] == 'checkbox') { |
|
|
|
$form->{$v['type']}('info.' . $v['field'])->options($v['options'])->required((bool)$v['required']); |
|
|
|
} else { |
|
|
|
$form->{$v['type']}('info.' . $v['field'])->required((bool)$v['required']); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$form->divider(); |
|
|
|
$form->text('', '购买产品')->default($industry->title)->disable(); |
|
|
|
$form->text('', '单价')->default($industry->price)->disable(); |
|
|
|
$form->text('', '库存')->default($industry->stock)->disable(); |
|
|
|
$form->text('', '起购数量')->default($industry->min_sale)->disable(); |
|
|
|
$form->image('picture', '产品图')->default($industry->pictures)->disable(); |
|
|
|
$form->display('', '旅游须知')->default(fn() => preg_replace('/<script.*?>.*?<\/script>/is', '', $industry->know))->disable(); |
|
|
|
$form->display('', '产品详情')->default(fn() => preg_replace('/<script.*?>.*?<\/script>/is', '', $industry->content))->disable(); |
|
|
|
})->saving(function (Form $form) use ($industry) { |
|
|
|
//禁止编辑
|
|
|
|
if ($form->isEditing()) { |
|
|
|
return $form->response()->error('操作禁止'); |
|
|
|
} |
|
|
|
|
|
|
|
//判断最小起购数
|
|
|
|
if ($form->num < $industry->min_sale) { |
|
|
|
return $form->response()->error('购买数量不能小于最低起购数:' . $industry->min_sale); |
|
|
|
} |
|
|
|
|
|
|
|
//判断产品状态和库存
|
|
|
|
if (!$industry || $industry->status != ProductStatus::ON_SALE || $industry->stock < $form->num) { |
|
|
|
return $form->response()->error('产品已下架或库存不足'); |
|
|
|
} |
|
|
|
|
|
|
|
//生成订单号
|
|
|
|
list($micro, $sec) = explode(' ', microtime()); |
|
|
|
$micro = str_pad(floor($micro * 1000000), 6, 0, STR_PAD_LEFT); |
|
|
|
$order_no = date('ymdHis', $sec) . $micro . mt_rand(1000, 9999); |
|
|
|
|
|
|
|
//产品规格处理
|
|
|
|
$spec = IndustryProductSpec::where('industry_product_id', $form->pid)->find($form->industry_product_spec_id); |
|
|
|
if (!$spec) { |
|
|
|
return $form->response()->error('您选择的产品规格不存在'); |
|
|
|
} |
|
|
|
|
|
|
|
$form->deleteInput(['pid', 'picture']); |
|
|
|
|
|
|
|
$form->hidden(['industry_product_id', 'supplier_id', 'agent_id', 'order_no', 'price', 'title', 'picture', 'status', 'pay_type', 'paid_at', 'verify_code', 'trade_deposit', 'timeout']); |
|
|
|
|
|
|
|
$form->name = $form->name ?? Admin::user()->director; |
|
|
|
$form->mobile = $form->mobile ?? Admin::user()->contact_phone; |
|
|
|
|
|
|
|
$form->industry_product_id = $industry->id; |
|
|
|
$form->supplier_id = $industry->supplier_id; |
|
|
|
$form->agent_id = Admin::user()->id; |
|
|
|
$form->order_no = $order_no; |
|
|
|
$form->price = $form->num * $spec->price; |
|
|
|
$form->title = $industry->title; |
|
|
|
$form->picture = $industry->pictures[0] ?? '' ; |
|
|
|
$form->status = $form->pay_type == PayType::OFFLINE ? OrderStatus::OFFLINE_UNPAID : OrderStatus::UNPAID; |
|
|
|
$form->paid_at = null; |
|
|
|
$form->verify_code = ''; |
|
|
|
$form->trade_deposit = $form->num * $industry->single_deposit; |
|
|
|
$form->single_price = $industry->single_deposit; |
|
|
|
$form->timeout = null; |
|
|
|
|
|
|
|
if ($form->pay_type == PayType::DEPOSIT_PAY) { |
|
|
|
$form->prepay_price = $industry->deposit * $form->num; |
|
|
|
} else if ($form->pay_type == PayType::EARNEST_PAY) { |
|
|
|
$form->prepay_price = $industry->earnest * $form->num; |
|
|
|
} else { |
|
|
|
$form->prepay_price = 0; |
|
|
|
} |
|
|
|
|
|
|
|
//产品规格表减库存
|
|
|
|
$spec->stock = $spec->stock - $form->num; |
|
|
|
$spec->save(); |
|
|
|
})->saved(function (Form $form) { |
|
|
|
return $form->response()->success('下单成功,请等待供应商审核订单')->redirect(admin_url('industry_order/list')); |
|
|
|
})->deleting(function (Form $form) { |
|
|
|
return $form->response()->error('操作禁止'); |
|
|
|
}); |
|
|
|
}*/ |
|
|
|
} |