From 14eb8df2a55839759e61b6fa28d59d18ed25a678 Mon Sep 17 00:00:00 2001 From: liapples Date: Sat, 18 Sep 2021 14:19:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A4=E6=98=93=E9=87=91=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MySQL_change.sql | 70 +++++ .../Controllers/IndustryProductController.php | 120 +++++++++ .../Extensions/Grid/AuditIndustryProduct.php | 56 ++++ app/Admin/Repositories/IndustryProduct.php | 16 ++ app/Admin/routes.php | 3 + .../Controllers/IndustryOrderController.php | 161 ++++++++++++ .../Controllers/IndustryProductController.php | 90 +++++++ app/AdminAgent/Repositories/IndustryOrder.php | 16 ++ .../Repositories/IndustryProduct.php | 16 ++ app/AdminAgent/routes.php | 3 + .../Controllers/IndustryOrderController.php | 144 ++++++++++ .../Controllers/IndustryProductController.php | 247 ++++++++++++++++++ .../Controllers/ProductController.php | 34 ++- .../Extensions/Grid/IndustryOrderStatus.php | 73 ++++++ app/AdminSupplier/Lazys/ProductForm.php | 20 ++ .../Repositories/IndustryOrder.php | 16 ++ .../Repositories/IndustryProduct.php | 16 ++ app/AdminSupplier/routes.php | 4 + app/Models/IndustryOrder.php | 27 ++ app/Models/IndustryProduct.php | 31 +++ dcat_admin_ide_helper.php | 8 +- resources/lang/zh_CN/industry-order.php | 27 ++ resources/lang/zh_CN/industry-product.php | 29 ++ 23 files changed, 1220 insertions(+), 7 deletions(-) create mode 100644 app/Admin/Controllers/IndustryProductController.php create mode 100644 app/Admin/Extensions/Grid/AuditIndustryProduct.php create mode 100644 app/Admin/Repositories/IndustryProduct.php create mode 100644 app/AdminAgent/Controllers/IndustryOrderController.php create mode 100644 app/AdminAgent/Controllers/IndustryProductController.php create mode 100644 app/AdminAgent/Repositories/IndustryOrder.php create mode 100644 app/AdminAgent/Repositories/IndustryProduct.php create mode 100644 app/AdminSupplier/Controllers/IndustryOrderController.php create mode 100644 app/AdminSupplier/Controllers/IndustryProductController.php create mode 100644 app/AdminSupplier/Extensions/Grid/IndustryOrderStatus.php create mode 100644 app/AdminSupplier/Lazys/ProductForm.php create mode 100644 app/AdminSupplier/Repositories/IndustryOrder.php create mode 100644 app/AdminSupplier/Repositories/IndustryProduct.php create mode 100644 app/Models/IndustryOrder.php create mode 100644 app/Models/IndustryProduct.php create mode 100644 resources/lang/zh_CN/industry-order.php create mode 100644 resources/lang/zh_CN/industry-product.php diff --git a/MySQL_change.sql b/MySQL_change.sql index cd6cbcf..fde968a 100644 --- a/MySQL_change.sql +++ b/MySQL_change.sql @@ -1,3 +1,73 @@ # 16:37 2021/9/16 ALTER TABLE `products` ADD COLUMN `service_persons` INT NOT NULL DEFAULT '1' COMMENT '涉及用户数' AFTER `content`; + +# 17:49 2021/9/17 +ALTER TABLE `suppliers` + CHANGE COLUMN `balance` `balance` DECIMAL(20,2) NOT NULL DEFAULT '0.00' COMMENT '余额' AFTER `area_id`, + CHANGE COLUMN `deposit_used` `deposit_used` DECIMAL(20,2) NOT NULL DEFAULT '0.00' COMMENT '交易金已消费' AFTER `balance`, + CHANGE COLUMN `deposit_frozen` `deposit_frozen` DECIMAL(20,2) NOT NULL DEFAULT '0.00' COMMENT '交易金冻结' AFTER `deposit_used`, + CHANGE COLUMN `deposit_normal` `deposit_normal` DECIMAL(20,2) NOT NULL DEFAULT '0.00' COMMENT '交易金正常' AFTER `deposit_frozen`; + +# 10:26 2021/9/18 增加industry_orders、industry_products两个表 +CREATE TABLE `industry_orders` ( + `id` INT(10) NOT NULL AUTO_INCREMENT, + `agent_id` INT(10) NOT NULL COMMENT '代理商ID', + `supplier_id` INT(10) NOT NULL COMMENT '供应商ID', + `order_no` CHAR(22) NOT NULL COMMENT '订单号' COLLATE 'utf8_general_ci', + `industry_product_id` INT(10) NOT NULL COMMENT '行业产品ID', + `num` INT(10) NOT NULL COMMENT '购买数量', + `price` DECIMAL(20,2) NOT NULL COMMENT '订单总价格', + `name` VARCHAR(20) NOT NULL COMMENT '客户姓名' COLLATE 'utf8_general_ci', + `mobile` CHAR(11) NOT NULL COMMENT '手机号' COLLATE 'utf8_general_ci', + `title` VARCHAR(255) NOT NULL COMMENT '产品名称' COLLATE 'utf8_general_ci', + `picture` VARCHAR(255) NOT NULL COMMENT '产品图片' COLLATE 'utf8_general_ci', + `status` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '订单状态,-1:已取消;0:待付款;1:已付订金/定金/首付款;2:已付全款;3:已付尾款;4:线下未支付;5:线下已支付;6:退款中;7:已退款;8:拒绝退款;16:已完成;', + `pay_type` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '支付方式,0:在线支付,1:线下支付,2:订金支付,3:定金支付,4:首款支付;5:追加/尾款支付;【注:订单生成后不应该再修改此项的值】', + `paid_at` TIMESTAMP NULL DEFAULT NULL COMMENT '付款时间', + `verify_code` CHAR(13) NOT NULL DEFAULT '' COMMENT '核销码' COLLATE 'utf8_general_ci', + `timeout` TIMESTAMP NULL DEFAULT NULL COMMENT '订单超时时间,超过这个时间,订单将变为“已取消”', + `created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` TIMESTAMP NULL DEFAULT NULL, + `deleted_at` TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE, + UNIQUE INDEX `order_no` (`order_no`) USING BTREE, + INDEX `agent_id` (`agent_id`) USING BTREE, + INDEX `mobile` (`mobile`) USING BTREE, + INDEX `user_id` (`supplier_id`) USING BTREE +) +COMMENT='行业产品订单表' +COLLATE='utf8_general_ci' +ENGINE=InnoDB; + +CREATE TABLE `industry_products` ( + `id` INT(10) NOT NULL AUTO_INCREMENT, + `supplier_id` INT(10) NOT NULL COMMENT '供应商ID', + `category_id` INT(10) NOT NULL COMMENT '分类ID', + `type` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '0:旅游线路、1:洒店、2:景区、3:餐厅、4:车队、5:单项', + `title` VARCHAR(255) NOT NULL COMMENT '标题' COLLATE 'utf8_general_ci', + `price` DECIMAL(20,2) NOT NULL COMMENT '售价', + `original_price` DECIMAL(20,2) NOT NULL DEFAULT '0.00' COMMENT '原价', + `pictures` TEXT NOT NULL COMMENT '产品图片,可能有多张,JSON格式' COLLATE 'utf8_general_ci', + `stock` INT(10) NOT NULL DEFAULT '0' COMMENT '库存量', + `sale` INT(10) NOT NULL DEFAULT '0' COMMENT '销量', + `status` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '-2:下架,-1:审核拒绝,0:未审核,1:上架', + `know` TEXT NULL DEFAULT NULL COMMENT '旅客须知' COLLATE 'utf8_general_ci', + `content` MEDIUMTEXT NULL DEFAULT NULL COMMENT '产品详情' COLLATE 'utf8_general_ci', + `service_persons` INT(10) NOT NULL DEFAULT '1' COMMENT '涉及用户数', + `min_sale` INT(10) NOT NULL DEFAULT '0' COMMENT '起售数', + `verify_mobile` VARCHAR(15) NOT NULL DEFAULT '' COMMENT '核销人员手机号' COLLATE 'utf8mb4_unicode_ci', + `extends` JSON NULL DEFAULT NULL, + `created_at` TIMESTAMP NULL DEFAULT NULL, + `updated_at` TIMESTAMP NULL DEFAULT NULL, + `deleted_at` TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE, + INDEX `supplier_id` (`supplier_id`) USING BTREE +) +COMMENT='行业产品表' +COLLATE='utf8_general_ci' +ENGINE=InnoDB; + +# 13:28 2021/9/18 +ALTER TABLE `industry_orders` + ADD COLUMN `deposit` DECIMAL(20,2) NOT NULL DEFAULT 0 COMMENT '需要扣除的交易金数量' AFTER `verify_code`; diff --git a/app/Admin/Controllers/IndustryProductController.php b/app/Admin/Controllers/IndustryProductController.php new file mode 100644 index 0000000..6b1138b --- /dev/null +++ b/app/Admin/Controllers/IndustryProductController.php @@ -0,0 +1,120 @@ +disableCreateButton(); + + //如果是审核页面,多加where条件判断 + if (strpos(Route::current()->uri, 'audit')) { + $grid->model()->where('status', UserStatus::UNAUDITED); + } + + $grid->column('id')->sortable(); + $grid->column('type')->using(admin_trans('product.options.publish_type')); + $grid->column('category.name', '分类'); + $grid->column('title')->limit(15); + $grid->column('picture')->image('', 60,60); + $grid->column('price'); + $grid->column('original_price'); + $grid->column('stock'); + $grid->column('sale'); + $grid->column('status') + ->if(fn() => $this->status == ProductStatus::UNAUDITED) + ->display('') + ->then(function ($column) { + $column->append((new AuditIndustryProduct(null, 1))->setKey($this->id))->append(' '); + $column->append((new AuditIndustryProduct(null, 2))->setKey($this->id)); + }) + ->else() + ->using(ProductStatus::array()) + ->dot([ + ProductStatus::ON_SALE => 'success', + ProductStatus::UNAUDITED => '', + ProductStatus::REFUSE => 'danger', + ProductStatus::SOLD_OUT => 'warning', + ], 'primary'); + $grid->column('service_persons'); + $grid->column('min_sale'); + $grid->column('created_at'); + + $grid->filter(function (Grid\Filter $filter) { + $filter->equal('id')->width(2); + + }); + }); + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + return Show::make($id, new IndustryProduct(['category:id,name', 'supplier:id,name,contact_phone']), function (Show $show) { + $show->field('id'); + $show->field('supplier.name', '供应商'); + $show->field('supplier.contact_phone', '供应商联系电话'); + $show->field('category.name', '分类'); + $show->field('type')->using(admin_trans('product.options.publish_type')); + $show->field('title'); + $show->field('pictures')->image('', 80, 80); + $show->field('price'); + $show->field('original_price'); + $show->field('stock'); + $show->field('sale'); + $show->field('status')->using(ProductStatus::array()); + $show->field('know')->unescape()->as(fn($v) => preg_replace('/.*?<\/script>/is', '', $v)); + $show->field('content')->unescape()->as(fn($v) => preg_replace('/.*?<\/script>/is', '', $v)); + $show->field('service_persons'); + $show->field('min_sale'); + $show->field('verify_mobile'); + $show->field('created_at'); + $show->field('updated_at'); + }); + } + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + return Form::make(new IndustryProduct(['supplier:id,name', 'category:id,name']), function (Form $form) { + $form->display('id'); + $form->select('status')->options(ProductStatus::array()); + })->saving(function (Form $form) { + if ($form->isEditing() && array_key_exists($form->status, ProductStatus::array())) { + $form->model()->update(['status' => $form->status]); + return $form->response()->success('更新成功!')->script('history.go(-1)'); + } else { + return $form->response()->error('操作禁止!')->refresh(); + } + })->deleting(function (Form $form) { + + }); + } +} diff --git a/app/Admin/Extensions/Grid/AuditIndustryProduct.php b/app/Admin/Extensions/Grid/AuditIndustryProduct.php new file mode 100644 index 0000000..0bba531 --- /dev/null +++ b/app/Admin/Extensions/Grid/AuditIndustryProduct.php @@ -0,0 +1,56 @@ +action = $action; //$action:1=通过;2=拒绝 + $this->title = $action == 1 ? '通过' : '拒绝'; + } + + protected function html() + { + $class = $this->action == 1 ? 'btn btn-sm btn-success' : 'btn btn-sm btn-danger'; + $this->appendHtmlAttribute('class', $class); + $this->defaultHtmlAttribute('href', 'javascript:;'); + + return "formatHtmlAttributes()}>{$this->title}"; + } + + public function handle(Request $request) + { + try { + $user = IndustryProduct::find($this->getKey()); + $user->status = $request->action == 1 ? ProductStatus::ON_SALE : ProductStatus::REFUSE; + $user->save(); + + return $this->response()->success("审核成功")->refresh(); + } catch (\Exception $e) { + return $this->response()->error($e->getMessage()); + } + } + + public function confirm() + { + return ['确定要'.$this->title.'该产品吗?', '']; + } + + public function parameters() + { + return ['action' => $this->action]; + } +} diff --git a/app/Admin/Repositories/IndustryProduct.php b/app/Admin/Repositories/IndustryProduct.php new file mode 100644 index 0000000..08e9da2 --- /dev/null +++ b/app/Admin/Repositories/IndustryProduct.php @@ -0,0 +1,16 @@ +resource('agent_product/audit', 'AgentProductController'); $router->resource('demand/product', 'DemandProductController'); + $router->resource('industry_product/list', 'IndustryProductController'); + $router->resource('industry_product/audit', 'IndustryProductController'); + $router->resource('finance_statistics', 'FinanceStatisticsController'); $router->resource('order_statistics', 'OrderStatisticsController'); $router->resource('user_statistics', 'UserStatisticsController'); diff --git a/app/AdminAgent/Controllers/IndustryOrderController.php b/app/AdminAgent/Controllers/IndustryOrderController.php new file mode 100644 index 0000000..72b5f5c --- /dev/null +++ b/app/AdminAgent/Controllers/IndustryOrderController.php @@ -0,0 +1,161 @@ +disableRowSelector(); + $grid->disableCreateButton(); + $grid->disableActions(); + + $grid->column('id')->sortable(); + $grid->column('supplier.name', '供应商'); + $grid->column('supplier.contact_phone', '供应商电话'); + $grid->column('order_no')->limit(10); + $grid->column('num'); + $grid->column('price'); + $grid->column('name', '预留姓名'); + $grid->column('mobile', '预留手机'); + $grid->column('title'); + $grid->column('picture')->image('', 80, 80); + $grid->column('status')->using(OrderStatus::array()); + $grid->column('paid_at', '订单确认时间'); + $grid->column('created_at'); + + $grid->filter(function (Grid\Filter $filter) { + $filter->equal('id')->width(2); + $filter->equal('order_no')->width(3); + }); + }); + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + /* return Show::make($id, new IndustryOrder(), function (Show $show) { + $show->field('id'); + $show->field('supplier_id'); + $show->field('agent_id'); + $show->field('order_no'); + $show->field('num'); + $show->field('price'); + $show->field('name'); + $show->field('mobile'); + $show->field('title'); + $show->field('picture')->image('', 80, 80); + $show->field('status'); + $show->field('pay_type'); + $show->field('paid_at'); + $show->field('verify_code'); + $show->field('timeout'); + $show->field('created_at'); + $show->field('updated_at'); + });*/ + } + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + $pid = request()->input('pid'); + $industry = IndustryProduct::where([ + ['status', '=', ProductStatus::ON_SALE], + ['stock', '>', 0], + ])->find($pid); + + return Form::make(new IndustryOrder(), function (Form $form) use ($industry) { + if (!$industry) { + Admin::exit('产品已下架或库存不足'); + } + + $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(); + + $form->divider(); + $form->text('', '购买产品')->default($industry->title)->disable(); + $form->text('', '单价')->default($industry->price)->disable(); + $form->text('', '库存')->default($industry->stock)->disable(); + $form->text('', '涉及用户数')->default($industry->service_persons)->disable(); + $form->text('', '起购数量')->default($industry->min_sale)->disable(); + $form->image('picture', '产品图')->default($industry->pictures)->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); + + $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', '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 * $industry->price; + $form->title = $industry->title; + $form->picture = $industry->pictures[0] ?? '' ; + $form->status = OrderStatus::OFFLINE_UNPAID; + $form->pay_type = PayType::OFFLINE; + $form->paid_at = null; + $form->verify_code = ''; + $form->deposit = SystemSetting::val('single', 'price') * $form->num * $industry->service_persons; + $form->timeout = null; + })->saved(function (Form $form) { + return $form->response()->success('下单成功,请等待供应商审核订单')->script('history.go(-1)'); + })->deleting(function (Form $form) { + return $form->response()->error('操作禁止'); + }); + } +} diff --git a/app/AdminAgent/Controllers/IndustryProductController.php b/app/AdminAgent/Controllers/IndustryProductController.php new file mode 100644 index 0000000..62d6daf --- /dev/null +++ b/app/AdminAgent/Controllers/IndustryProductController.php @@ -0,0 +1,90 @@ +disableDeleteButton(); + $grid->disableRowSelector(); + $grid->disableCreateButton(); + $grid->disableEditButton(); + $grid->disableActions(); + + $grid->model()->where('status', ProductStatus::ON_SALE); + + $grid->column('id')->sortable(); + $grid->column('type')->using(admin_trans('product.options.publish_type')); + $grid->column('category.name', '分类'); + $grid->column('title')->limit(15); + $grid->column('picture')->image('', 60,60); + $grid->column('price'); + $grid->column('original_price'); + $grid->column('stock'); + $grid->column('sale'); + $grid->column('service_persons'); + $grid->column('min_sale'); + $grid->column('created_at'); + $grid->column('op', '操作') + ->if(fn() => true) + ->then(function ($column) { + $column->append('查看  '); + $column->append('购买'); + }); + + $grid->filter(function (Grid\Filter $filter) { + $filter->equal('id')->width(2); + + }); + }); + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + return Show::make($id, new IndustryProduct(['category:id,name', 'supplier:id,name,contact_phone']), function (Show $show) { + $show->disableEditButton(); + $show->disableDeleteButton(); + + $show->field('id'); + $show->field('supplier.name', '供应商'); + $show->field('supplier.contact_phone', '供应商联系电话'); + $show->field('category.name', '分类'); + $show->field('type')->using(admin_trans('product.options.publish_type')); + $show->field('title'); + $show->field('pictures')->image('', 80, 80); + $show->field('price'); + $show->field('original_price'); + $show->field('stock'); + $show->field('sale'); + $show->field('status')->using(ProductStatus::array()); + $show->field('know')->unescape()->as(fn($v) => preg_replace('/.*?<\/script>/is', '', $v)); + $show->field('content')->unescape()->as(fn($v) => preg_replace('/.*?<\/script>/is', '', $v)); + $show->field('service_persons'); + $show->field('min_sale'); + $show->field('verify_mobile'); + $show->field('created_at'); + $show->field('updated_at'); + }); + } +} diff --git a/app/AdminAgent/Repositories/IndustryOrder.php b/app/AdminAgent/Repositories/IndustryOrder.php new file mode 100644 index 0000000..e536314 --- /dev/null +++ b/app/AdminAgent/Repositories/IndustryOrder.php @@ -0,0 +1,16 @@ +resource('special/list', 'SpecialController'); $router->resource('waterfall_ad/list', 'WaterfallAdController'); + $router->resource('industry_product/list', 'IndustryProductController'); + $router->resource('industry_order/list', 'IndustryOrderController'); + $router->resource('demand', 'DemandController'); $router->resource('demand_bidding', 'DemandBiddingController'); $router->resource('my_demand_product', 'MyDemandProductController'); diff --git a/app/AdminSupplier/Controllers/IndustryOrderController.php b/app/AdminSupplier/Controllers/IndustryOrderController.php new file mode 100644 index 0000000..feec48e --- /dev/null +++ b/app/AdminSupplier/Controllers/IndustryOrderController.php @@ -0,0 +1,144 @@ +disableCreateButton(); + $grid->disableRowSelector(); + $grid->disableActions(); + + $grid->model()->where('supplier_id', Admin::user()->id); + + $grid->column('id')->sortable(); + $grid->column('agent.name', '代理商名称'); + $grid->column('order_no'); + $grid->column('num'); + $grid->column('price'); + $grid->column('name'); + $grid->column('mobile'); + $grid->column('industry_product_id', '产品ID'); + $grid->column('title'); + $grid->column('picture')->image('', 60, 60); + $grid->column('status') + ->using(OrderStatus::array()) + ->if(fn() => $this->status == OrderStatus::OFFLINE_UNPAID) + ->action(new IndustryOrderStatus); + $grid->column('paid_at'); + $grid->column('verify_qrcode', '核销二维码') + ->if(fn() => $this->verify_code) + ->then(function ($column) { + $verify_code = $this->id . '-' . $this->verify_code; + $column->append(admin_url('industry_order/qrcode', $verify_code))->image('', 60, 60); + $column->append('
' . $verify_code); + }) + ->else() + ->display(''); +// $grid->column('timeout'); + $grid->column('created_at'); + + $grid->filter(function (Grid\Filter $filter) { + $filter->equal('id')->width(2); + $filter->equal('order_no')->width(3); + }); + }); + } + + //生成核销二维码,行业产品订单使用支付小程序核销 + public function qrcode() + { + $verify_code = request()->route('verify_code'); + + $qrcode = storage_path("app/public/industry_verify_code/$verify_code.jpg"); + if (file_exists($qrcode)) { + return redirect(Storage::disk('public')->url("industry_verify_code/$verify_code.jpg")); + } + + $setting = AdminSetting::val(['payee_appid', 'payee_appsecret']); + $config = [ + 'app_id' => $setting['payee_appid'], + 'secret' => $setting['payee_appsecret'], + ]; + $app = Factory::miniProgram($config); + + //由于参数最多只能32个字符,故通过下面这种方式传参 + //0$表示使用普通订单,使用api/verification/verify接口核销; + //1$表示行业产品订单,使用api/verification/industry_verify接口核销 + $response = $app->app_code->getUnlimit('1$' . $verify_code, ['page' => 'pages/verification/index']); + + if ($response instanceof StreamResponse) { + $filename = $response->saveAs(storage_path('app/public/industry_verify_code'), $verify_code); //保存二维码 + // $qrcode = Storage::disk('public')->url('industry_verify_code/' . $filename); //获取前端路径 + header("Content-Type: " . $response->getHeaderLine('Content-Type')); + exit($response); //输出图片 + } + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + /*return Show::make($id, new IndustryOrder(), function (Show $show) { + $show->field('id'); + $show->field('agent_id'); + $show->field('supplier_id'); + $show->field('order_no'); + $show->field('industry_product_id'); + $show->field('num'); + $show->field('price'); + $show->field('name'); + $show->field('mobile'); + $show->field('title'); + $show->field('picture'); + $show->field('status'); + $show->field('paid_at'); + $show->field('verify_code'); + $show->field('timeout'); + $show->field('created_at'); + $show->field('updated_at'); + });*/ + } + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + return Form::make(new IndustryOrder(), function (Form $form) { + $form->display('id'); +// $form->select('status')->options([OrderStatus::OFFLINE_PAID => '已付款']); + })->saving(function(Form $form) { + return $form->response()->error('操作禁止'); + })->deleting(function(Form $form) { + return $form->response()->error('操作禁止'); + }); + } +} diff --git a/app/AdminSupplier/Controllers/IndustryProductController.php b/app/AdminSupplier/Controllers/IndustryProductController.php new file mode 100644 index 0000000..3d58505 --- /dev/null +++ b/app/AdminSupplier/Controllers/IndustryProductController.php @@ -0,0 +1,247 @@ +model()->where('supplier_id', Admin::user()->id); + + $grid->column('id')->sortable(); + $grid->column('type')->using(admin_trans('product.options.publish_type')); + $grid->column('category.name', '分类'); + $grid->column('title')->limit(15); + $grid->column('picture')->image('', 60,60); + $grid->column('price'); + $grid->column('original_price'); + $grid->column('stock'); + $grid->column('sale'); + $grid->column('status') + /*->if(fn() => in_array($this->status, [ProductStatus::SOLD_OUT, ProductStatus::ON_SALE])) + ->using([ProductStatus::SOLD_OUT => 0, ProductStatus::ON_SALE => 1]) + ->switch() + ->else()*/ + ->using(ProductStatus::array()); + $grid->column('service_persons'); + $grid->column('min_sale'); + $grid->column('created_at'); + + $grid->filter(function (Grid\Filter $filter) { + $filter->equal('id')->width(2); + + }); + }); + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + return Show::make($id, new IndustryProduct(['category:id,name']), function (Show $show) { + //不允许查看非自己的数据 + if ($show->model()->agent_id != Admin::user()->id) { + Admin::exit('数据不存在'); + } + + $show->field('id'); + $show->field('type')->using(admin_trans('product.options.publish_type')); + $show->field('category.name', '分类'); + $show->field('title'); + $show->field('pictures')->image('', 80, 80); + $show->field('price'); + $show->field('original_price'); + $show->field('stock'); + $show->field('sale'); + $show->field('status')->using(ProductStatus::array()); + $show->field('know')->unescape()->as(fn($v) => preg_replace('/.*?<\/script>/is', '', $v)); + $show->field('content')->unescape()->as(fn($v) => preg_replace('/.*?<\/script>/is', '', $v)); + $show->field('service_persons'); + $show->field('min_sale'); + $show->field('verify_mobile'); + $show->field('created_at'); + $show->field('updated_at'); + }); + } + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + Admin::user()->publish_type = json_decode(Admin::user()->publish_type, true); + return Form::make(new IndustryProduct(), function (Form $form) { + $form->display('id'); + + $options = Category::selectOptions(fn($query) => $query->where('agent_id', 0)); + $form->select('category_id')->options(array_slice($options, 1, null, true))->required(); + $form->text('title')->required(); + $form->currency('price')->required(); + $form->currency('original_price')->required(); + $form->number('service_persons')->min(0)->required(); + $form->number('stock')->required(); + $form->number('min_sale')->min(1)->required(); + $form->radio('status')->options([1 => '上架', -2 => '下架'])->default(1); + $form->multipleImage('pictures')->required(); + $form->editor('know'); + $form->editor('content')->required(); + $form->mobile('verify_mobile')->required(); + + //扩展字段 + $publish_type = array_intersect_key( + admin_trans('product.options.publish_type'), + array_flip(Admin::user()->publish_type) + ); + + $form->radio('type', '产品类型') + ->options($publish_type)->disable($form->isEditing()) + ->default(current(Admin::user()->publish_type)) + ->when(0, function (Form $form) { //旅游线路 + if ($form->isEditing() && $form->model()->type != 0) { + return; + } + $form->table('extends.field_0.project', '包含项目', function (NestedForm $table) { + $table->text('name', '字段1'); + $table->text('num', '字段2'); + $table->text('price', '字段3'); + })->help('第一行数据默认是表头,如:项目名称、数量、额外费用'); + + $form->dateRange('extends.field_0.date.start', 'extends.field_0.date.end', '行程时间'); + })->when(1, function (Form $form) { //酒店 + if ($form->isEditing() && $form->model()->type != 1) { + return; + } + $default = [ + ['tag' => '行李寄存'], ['tag' => '24小时前台'], ['tag' => '前台保险柜'], ['tag' => '唤醒服务'], + ['tag' => '早餐'], ['tag' => '送餐服务'], ['tag' => '电梯'], ['tag' => '空调'], + ['tag' => '新风系统'], ['tag' => '24小时热水'], ['tag' => '吹风机'], ['tag' => '加湿器'], + ['tag' => '自动售货机'], ['tag' => '健身房'], ['tag' => '桌球室'], ['tag' => '洗衣服务'] + ]; + $form->table('extends.field_1.tags', '酒店设施', function (NestedForm $table) { + $table->text('tag', '包含项目')->placeholder('如:24小时热水、干洗服务等'); + })->value($default)->help('首次创建时,系统会默认填充基本服务,请根据本酒店情况进行删减或新增'); + + $form->text('extends.field_1.name', '酒店名'); + $form->text('extends.field_1.address', '地址'); + $form->map('extends.field_1.latitude', 'extends.field_1.longitude', '位置'); + })->when(2, function (Form $form) { //景区 + if ($form->isEditing() && $form->model()->type != 2) { + return; + } + $form->table('extends.field_2.open_time', '开放时间', function (NestedForm $table) { + $table->text('node', '字段1')->placeholder('如:周一至周五'); + $table->text('summer', '字段2')->placeholder('如:08:00~19:00'); + $table->text('winter', '字段3')->placeholder('如:08:00~18:00'); + })->help('第一行数据默认是表头,如:项目名称、数量、额外费用'); + + $form->table('extends.field_2.project', '包含项目', function (NestedForm $table) { + $table->text('name', '字段1'); + $table->text('num', '字段2'); + $table->text('price', '字段3'); + })->help('第一行数据默认是表头,如:项目名称、数量、额外费用'); + + $form->text('extends.field_2.name', '景区名'); + $form->text('extends.field_2.address', '地址'); + $form->map('extends.field_2.latitude', 'extends.field_2.longitude', '位置'); + })->when(3, function (Form $form) { //餐厅 + if ($form->isEditing() && $form->model()->type != 3) { + return; + } + $form->table('extends.field_3.open_time', '开放时间', function (NestedForm $table) { + $table->text('week', '字段1')->placeholder('如:周一至周五'); + $table->text('section', '字段2')->placeholder('如:上午/下午'); + $table->text('time', '字段3')->placeholder('如:08:00~18:00'); + })->help('第一行数据默认是表头,如:项目名称、数量、额外费用'); + + $form->table('extends.field_3.package', '包含套餐', function (NestedForm $table) { + $table->text('name', '字段1')->placeholder('如:清蒸鱿鱼'); + $table->text('num', '字段2')->placeholder('如:1条'); + $table->text('price', '字段3')->placeholder('如:99元'); + })->help('第一行数据默认是表头,如:项目名称、数量、额外费用'); + + $form->text('extends.field_3.name', '餐厅名'); + $form->text('extends.field_3.address', '地址'); + $form->map('extends.field_3.latitude', 'extends.field_3.longitude', '位置'); + }); + })->saving(function (Form $form) { + //不允许编辑非自己数据 + if ($form->isEditing() && $form->model()->supplier_id != Admin::user()->id) { + return $form->response()->error('数据不存在'); + } + + if ($form->isCreating()) { + if (!Admin::user()->publish_type || !in_array($form->type, Admin::user()->publish_type)) { + return $form->response()->error('对不起,你没有此类产品的发布、编辑权限'); + } + } else if ($form->isEditing()) { //type不允许编辑 + $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']); + + $form->hidden(['status', 'supplier_id']); + $form->supplier_id = Admin::user()->id; + if ($form->isCreating()) { + $form->status = ProductStatus::UNAUDITED; + } 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]); + } + + //目前逻辑不考虑单人头交易费变动的情况 + if ($result) { //新增处理 + if ($form->isCreating()) { + $single = SystemSetting::val('single', 'price'); //单人头交易费 + $change = $single * $form->service_persons * $form->stock; //变动的交易金 + + $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()) { + + } + } + })->deleting(function (Form $form) { + //不允许删除非自己的数据 + if (array_filter($form->model()->toArray(), fn($v) => $v['supplier_id'] != Admin::user()->id)) { + return $form->response()->error('数据不存在'); + } + }); + } +} diff --git a/app/AdminSupplier/Controllers/ProductController.php b/app/AdminSupplier/Controllers/ProductController.php index 6edecf4..e0404e9 100644 --- a/app/AdminSupplier/Controllers/ProductController.php +++ b/app/AdminSupplier/Controllers/ProductController.php @@ -37,7 +37,12 @@ class ProductController extends AdminController $grid->column('original_price'); $grid->column('stock'); $grid->column('sale'); - $grid->column('status')->using(ProductStatus::array()); + $grid->column('status') + /*->if(fn() => in_array($this->status, [ProductStatus::SOLD_OUT, ProductStatus::ON_SALE])) + ->using([ProductStatus::SOLD_OUT => 0, ProductStatus::ON_SALE => 1]) + ->switch() + ->else()*/ + ->using(ProductStatus::array()); $grid->column('verify_mobile','核销员手机'); $grid->column('created_at'); $grid->column('updated_at'); @@ -104,6 +109,7 @@ class ProductController extends AdminController $form->currency('original_price')->symbol('¥')->required(); $form->number('service_persons')->required(); $form->number('stock')->required(); + $form->radio('status')->options([1 => '上架', -2 => '下架'])->default(1); $form->multipleImage('pictures')->required()->removable(false)->retainable()->uniqueName(); $form->editor('know'); $form->editor('content')->required(); @@ -116,9 +122,12 @@ class ProductController extends AdminController ); $form->radio('type', '产品类型') - ->options($publish_type) + ->options($publish_type)->disable($form->isEditing()) ->default(current(Admin::user()->publish_type)) ->when(0, function (Form $form) { //旅游线路 + if ($form->isEditing() && $form->model()->type != 0) { + return; + } $form->table('extends.field_0.project', '包含项目', function (NestedForm $table) { $table->text('name', '字段1'); $table->text('num', '字段2'); @@ -127,6 +136,9 @@ class ProductController extends AdminController $form->dateRange('extends.field_0.date.start', 'extends.field_0.date.end', '行程时间'); })->when(1, function (Form $form) { //酒店 + if ($form->isEditing() && $form->model()->type != 1) { + return; + } $default = [ ['tag' => '行李寄存'], ['tag' => '24小时前台'], ['tag' => '前台保险柜'], ['tag' => '唤醒服务'], ['tag' => '早餐'], ['tag' => '送餐服务'], ['tag' => '电梯'], ['tag' => '空调'], @@ -141,6 +153,9 @@ class ProductController extends AdminController $form->text('extends.field_1.address', '地址'); $form->map('extends.field_1.latitude', 'extends.field_1.longitude', '位置'); })->when(2, function (Form $form) { //景区 + if ($form->isEditing() && $form->model()->type != 2) { + return; + } $form->table('extends.field_2.open_time', '开放时间', function (NestedForm $table) { $table->text('node', '字段1')->placeholder('如:周一至周五'); $table->text('summer', '字段2')->placeholder('如:08:00~19:00'); @@ -157,6 +172,9 @@ class ProductController extends AdminController $form->text('extends.field_2.address', '地址'); $form->map('extends.field_2.latitude', 'extends.field_2.longitude', '位置'); })->when(3, function (Form $form) { //餐厅 + if ($form->isEditing() && $form->model()->type != 3) { + return; + } $form->table('extends.field_3.open_time', '开放时间', function (NestedForm $table) { $table->text('week', '字段1')->placeholder('如:周一至周五'); $table->text('section', '字段2')->placeholder('如:上午/下午'); @@ -183,12 +201,16 @@ class ProductController extends AdminController return $form->response()->error('数据不存在'); } - if (!Admin::user()->publish_type || !in_array($form->type, Admin::user()->publish_type)) { - return $form->response()->error('对不起,你没有此类产品的发布、编辑权限'); + if ($form->isCreating()) { + if (!Admin::user()->publish_type || !in_array($form->type, Admin::user()->publish_type)) { + return $form->response()->error('对不起,你没有此类产品的发布、编辑权限'); + } + } else if ($form->isEditing()) { //type不允许编辑 + $form->deleteInput('type'); } //不允许编辑的字段,忽略字段不起作用? - $form->ignore(['id', 'supplier_id', 'sale', 'status', 'created_at', 'updated_at', 'deleted_at']); + $form->ignore(['id', 'supplier_id', 'sale', 'created_at', 'updated_at', 'deleted_at']); //null字段转为'' foreach ($form->input() as $k => $v) { @@ -202,6 +224,8 @@ class ProductController extends AdminController $form->hidden(['status', 'supplier_id']); //表单没有的字段,必须加上这句才能重置值 $form->supplier_id = Admin::user()->id; $form->status = ProductStatus::UNAUDITED; + } 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() && $result) { diff --git a/app/AdminSupplier/Extensions/Grid/IndustryOrderStatus.php b/app/AdminSupplier/Extensions/Grid/IndustryOrderStatus.php new file mode 100644 index 0000000..74b3f5e --- /dev/null +++ b/app/AdminSupplier/Extensions/Grid/IndustryOrderStatus.php @@ -0,0 +1,73 @@ +appendHtmlAttribute('class', $class); + $this->defaultHtmlAttribute('href', 'javascript:;'); + + return "formatHtmlAttributes()}>{$this->title}"; + } + + public function handle(Request $request) + { + $id = $this->getKey(); + DB::beginTransaction(); + try { + $order = IndustryOrder::where(['id' => $id, 'status' => OrderStatus::OFFLINE_UNPAID])->find($id); + //操作订单表 + $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 ['确定要设置为已付款吗?', '']; + } +} diff --git a/app/AdminSupplier/Lazys/ProductForm.php b/app/AdminSupplier/Lazys/ProductForm.php new file mode 100644 index 0000000..37b82cb --- /dev/null +++ b/app/AdminSupplier/Lazys/ProductForm.php @@ -0,0 +1,20 @@ +id; + return Form::make(); + } +} diff --git a/app/AdminSupplier/Repositories/IndustryOrder.php b/app/AdminSupplier/Repositories/IndustryOrder.php new file mode 100644 index 0000000..90ef2e6 --- /dev/null +++ b/app/AdminSupplier/Repositories/IndustryOrder.php @@ -0,0 +1,16 @@ +post('auth/login', 'AuthController@postLogin'); $router->resource('product/list', 'ProductController'); + $router->resource('industry_product/list', 'IndustryProductController'); + $router->resource('industry_order/list', 'IndustryOrderController'); + $router->get('industry_order/qrcode/{verify_code}', 'IndustryOrderController@qrcode'); + $router->resource('order/list', 'OrderController'); $router->resource('agent/list', 'AgentController'); $router->resource('supplier_info', 'SupplierInfoController'); diff --git a/app/Models/IndustryOrder.php b/app/Models/IndustryOrder.php new file mode 100644 index 0000000..7a5a4ac --- /dev/null +++ b/app/Models/IndustryOrder.php @@ -0,0 +1,27 @@ +belongsTo(Supplier::class); + } + + public function agent() + { + return $this->belongsTo(Agent::class); + } + + public function industryProduct() + { + return $this->belongsTo(IndustryProduct::class); + } +} diff --git a/app/Models/IndustryProduct.php b/app/Models/IndustryProduct.php new file mode 100644 index 0000000..9b9cd8d --- /dev/null +++ b/app/Models/IndustryProduct.php @@ -0,0 +1,31 @@ + 'json', 'extends' => 'json']; + protected $appends = ['picture']; + protected $fillable = ['status']; + + public function getPictureAttribute($value): string + { + return $this->pictures[0] ?? ''; + } + + public function supplier() + { + return $this->belongsTo(Supplier::class); + } + + public function category() + { + return $this->belongsTo(Category::class); + } +} diff --git a/dcat_admin_ide_helper.php b/dcat_admin_ide_helper.php index 88f1b62..a0d5a39 100644 --- a/dcat_admin_ide_helper.php +++ b/dcat_admin_ide_helper.php @@ -117,6 +117,7 @@ namespace Dcat\Admin { * @property Grid\Column|Collection queue * @property Grid\Column|Collection uuid * @property Grid\Column|Collection photo + * @property Grid\Column|Collection industry_product_id * @property Grid\Column|Collection mobile * @property Grid\Column|Collection num * @property Grid\Column|Collection order_no @@ -296,6 +297,7 @@ namespace Dcat\Admin { * @method Grid\Column|Collection queue(string $label = null) * @method Grid\Column|Collection uuid(string $label = null) * @method Grid\Column|Collection photo(string $label = null) + * @method Grid\Column|Collection industry_product_id(string $label = null) * @method Grid\Column|Collection mobile(string $label = null) * @method Grid\Column|Collection num(string $label = null) * @method Grid\Column|Collection order_no(string $label = null) @@ -480,6 +482,7 @@ namespace Dcat\Admin { * @property Show\Field|Collection queue * @property Show\Field|Collection uuid * @property Show\Field|Collection photo + * @property Show\Field|Collection industry_product_id * @property Show\Field|Collection mobile * @property Show\Field|Collection num * @property Show\Field|Collection order_no @@ -659,6 +662,7 @@ namespace Dcat\Admin { * @method Show\Field|Collection queue(string $label = null) * @method Show\Field|Collection uuid(string $label = null) * @method Show\Field|Collection photo(string $label = null) + * @method Show\Field|Collection industry_product_id(string $label = null) * @method Show\Field|Collection mobile(string $label = null) * @method Show\Field|Collection num(string $label = null) * @method Show\Field|Collection order_no(string $label = null) @@ -743,7 +747,7 @@ namespace Dcat\Admin { namespace Dcat\Admin\Grid { /** - + */ class Column {} @@ -755,7 +759,7 @@ namespace Dcat\Admin\Grid { namespace Dcat\Admin\Show { /** - + */ class Field {} } diff --git a/resources/lang/zh_CN/industry-order.php b/resources/lang/zh_CN/industry-order.php new file mode 100644 index 0000000..e0c5a73 --- /dev/null +++ b/resources/lang/zh_CN/industry-order.php @@ -0,0 +1,27 @@ + [ + 'IndustryOrder' => '行业产品订单', + 'industry-order' => '行业产品订单', + 'industry_order' => '行业产品订单', + ], + 'fields' => [ + 'supplier_id' => '供应商ID', + 'agent_id' => '代理商ID', + 'order_no' => '订单号', + 'num' => '购买数量', + 'price' => '订单总价', + 'name' => '客户姓名', + 'mobile' => '手机号', + 'title' => '产品名称', + 'picture' => '产品图片', + 'status' => '订单状态', + 'pay_type' => '支付方式', + 'paid_at' => '付款时间', + 'verify_code' => '核销码', + 'timeout' => '订单超时时间', + 'created_at' => '下单时间', + ], + 'options' => [ + ], +]; diff --git a/resources/lang/zh_CN/industry-product.php b/resources/lang/zh_CN/industry-product.php new file mode 100644 index 0000000..e17148a --- /dev/null +++ b/resources/lang/zh_CN/industry-product.php @@ -0,0 +1,29 @@ + [ + 'IndustryProduct' => '行业产品', + 'industry-product' => '行业产品', + 'industry_product' => '行业产品', + ], + 'fields' => [ + 'supplier_id' => '供应商ID', + 'type' => '产品类型', + 'category_id' => '分类ID', + 'title' => '标题', + 'pictures' => '产品图片', + 'picture' => '产品图片', + 'price' => '售价', + 'original_price' => '原价', + 'stock' => '库存量', + 'sale' => '销量', + 'status' => '状态', + 'know' => '旅客须知', + 'content' => '产品详情', + 'service_persons' => '涉及用户数', + 'min_sale' => '起售数', + 'verify_mobile' => '核销人员手机号', + ], + 'options' => [ + 'publish_type' => admin_trans('product.options.publish_type'), + ], +];