23 changed files with 1220 additions and 7 deletions
-
70MySQL_change.sql
-
120app/Admin/Controllers/IndustryProductController.php
-
56app/Admin/Extensions/Grid/AuditIndustryProduct.php
-
16app/Admin/Repositories/IndustryProduct.php
-
3app/Admin/routes.php
-
161app/AdminAgent/Controllers/IndustryOrderController.php
-
90app/AdminAgent/Controllers/IndustryProductController.php
-
16app/AdminAgent/Repositories/IndustryOrder.php
-
16app/AdminAgent/Repositories/IndustryProduct.php
-
3app/AdminAgent/routes.php
-
144app/AdminSupplier/Controllers/IndustryOrderController.php
-
247app/AdminSupplier/Controllers/IndustryProductController.php
-
34app/AdminSupplier/Controllers/ProductController.php
-
73app/AdminSupplier/Extensions/Grid/IndustryOrderStatus.php
-
20app/AdminSupplier/Lazys/ProductForm.php
-
16app/AdminSupplier/Repositories/IndustryOrder.php
-
16app/AdminSupplier/Repositories/IndustryProduct.php
-
4app/AdminSupplier/routes.php
-
27app/Models/IndustryOrder.php
-
31app/Models/IndustryProduct.php
-
8dcat_admin_ide_helper.php
-
27resources/lang/zh_CN/industry-order.php
-
29resources/lang/zh_CN/industry-product.php
@ -1,3 +1,73 @@ |
|||||
# 16:37 2021/9/16 |
# 16:37 2021/9/16 |
||||
ALTER TABLE `products` |
ALTER TABLE `products` |
||||
ADD COLUMN `service_persons` INT NOT NULL DEFAULT '1' COMMENT '涉及用户数' AFTER `content`; |
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`; |
||||
@ -0,0 +1,120 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Admin\Extensions\Grid\AuditIndustryProduct; |
||||
|
use App\Admin\Repositories\IndustryProduct; |
||||
|
use App\Common\ProductStatus; |
||||
|
use App\Common\UserStatus; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Http\Controllers\AdminController; |
||||
|
use Illuminate\Support\Facades\Route; |
||||
|
|
||||
|
class IndustryProductController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new IndustryProduct(['category']), function (Grid $grid) { |
||||
|
$grid->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.*?>.*?<\/script>/is', '', $v)); |
||||
|
$show->field('content')->unescape()->as(fn($v) => preg_replace('/<script.*?>.*?<\/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) { |
||||
|
|
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,56 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Extensions\Grid; |
||||
|
use App\Common\ProductStatus; |
||||
|
use App\Models\IndustryProduct; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
/** |
||||
|
* 行业产品审核 |
||||
|
* Class AuditAgentProduct |
||||
|
* @package App\Admin\Extensions\Grid |
||||
|
*/ |
||||
|
class AuditIndustryProduct extends RowAction |
||||
|
{ |
||||
|
private $action; |
||||
|
|
||||
|
public function __construct($title = null, $action = 1) |
||||
|
{ |
||||
|
parent::__construct($title); |
||||
|
$this->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 "<a {$this->formatHtmlAttributes()}>{$this->title}</a>"; |
||||
|
} |
||||
|
|
||||
|
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]; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Repositories; |
||||
|
|
||||
|
use App\Models\IndustryProduct as Model; |
||||
|
use Dcat\Admin\Repositories\EloquentRepository; |
||||
|
|
||||
|
class IndustryProduct extends EloquentRepository |
||||
|
{ |
||||
|
/** |
||||
|
* Model. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $eloquentClass = Model::class; |
||||
|
} |
||||
@ -0,0 +1,161 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminAgent\Controllers; |
||||
|
|
||||
|
use App\AdminAgent\Repositories\IndustryOrder; |
||||
|
use App\Common\OrderStatus; |
||||
|
use App\Common\PayType; |
||||
|
use App\Common\ProductStatus; |
||||
|
use App\Models\IndustryProduct; |
||||
|
use App\Models\SystemSetting; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Http\Controllers\AdminController; |
||||
|
|
||||
|
class IndustryOrderController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new IndustryOrder(['supplier:id,name,contact_phone']), function (Grid $grid) { |
||||
|
$grid->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('操作禁止'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,90 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminAgent\Controllers; |
||||
|
|
||||
|
use App\AdminAgent\Forms\IndustryProductBuy; |
||||
|
use App\AdminAgent\Repositories\IndustryProduct; |
||||
|
use App\Common\ProductStatus; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Http\Controllers\AdminController; |
||||
|
|
||||
|
class IndustryProductController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new IndustryProduct(['category:id,name']), function (Grid $grid) { |
||||
|
$grid->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('<a class="btn btn-sm" href="' . admin_url('industry_product/list', $this->id) . '">查看</a> '); |
||||
|
$column->append('<a class="btn btn-sm btn-success" href="' . admin_url('industry_order/list/create?pid=' . $this->id) . '">购买</a>'); |
||||
|
}); |
||||
|
|
||||
|
$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.*?>.*?<\/script>/is', '', $v)); |
||||
|
$show->field('content')->unescape()->as(fn($v) => preg_replace('/<script.*?>.*?<\/script>/is', '', $v)); |
||||
|
$show->field('service_persons'); |
||||
|
$show->field('min_sale'); |
||||
|
$show->field('verify_mobile'); |
||||
|
$show->field('created_at'); |
||||
|
$show->field('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminAgent\Repositories; |
||||
|
|
||||
|
use App\Models\IndustryOrder as Model; |
||||
|
use Dcat\Admin\Repositories\EloquentRepository; |
||||
|
|
||||
|
class IndustryOrder extends EloquentRepository |
||||
|
{ |
||||
|
/** |
||||
|
* Model. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $eloquentClass = Model::class; |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminAgent\Repositories; |
||||
|
|
||||
|
use App\Models\IndustryProduct as Model; |
||||
|
use Dcat\Admin\Repositories\EloquentRepository; |
||||
|
|
||||
|
class IndustryProduct extends EloquentRepository |
||||
|
{ |
||||
|
/** |
||||
|
* Model. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $eloquentClass = Model::class; |
||||
|
} |
||||
@ -0,0 +1,144 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminSupplier\Controllers; |
||||
|
|
||||
|
use App\AdminSupplier\Extensions\Grid\IndustryOrderStatus; |
||||
|
use App\AdminSupplier\Repositories\IndustryOrder; |
||||
|
use App\Common\OrderStatus; |
||||
|
use App\Models\AdminSetting; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Http\Controllers\AdminController; |
||||
|
use EasyWeChat\Factory; |
||||
|
use EasyWeChat\Kernel\Http\StreamResponse; |
||||
|
use Illuminate\Support\Facades\Storage; |
||||
|
|
||||
|
class IndustryOrderController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new IndustryOrder(['agent:id,name']), function (Grid $grid) { |
||||
|
$grid->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('<br>' . $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('操作禁止'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,247 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminSupplier\Controllers; |
||||
|
|
||||
|
use App\AdminSupplier\Repositories\IndustryProduct; |
||||
|
use App\Common\ProductStatus; |
||||
|
use App\Models\Category; |
||||
|
use App\Models\Supplier; |
||||
|
use App\Models\SystemSetting; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Form\NestedForm; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Http\Controllers\AdminController; |
||||
|
|
||||
|
class IndustryProductController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new IndustryProduct(['category:id,name']), function (Grid $grid) { |
||||
|
$grid->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.*?>.*?<\/script>/is', '', $v)); |
||||
|
$show->field('content')->unescape()->as(fn($v) => preg_replace('/<script.*?>.*?<\/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('数据不存在'); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,73 @@ |
|||||
|
<?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); |
||||
|
//操作订单表
|
||||
|
$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 ['确定要设置为已付款吗?', '']; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
<?php |
||||
|
|
||||
|
|
||||
|
namespace App\AdminSupplier\Lazys; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Support\LazyRenderable; |
||||
|
|
||||
|
/** |
||||
|
* 供应商产品异步表单 |
||||
|
* Class ProductForm |
||||
|
* @package App\AdminSupplier\Lazys |
||||
|
*/ |
||||
|
class ProductForm extends LazyRenderable |
||||
|
{ |
||||
|
public function render() |
||||
|
{ |
||||
|
$id = $this->id; |
||||
|
return Form::make(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminSupplier\Repositories; |
||||
|
|
||||
|
use App\Models\IndustryOrder as Model; |
||||
|
use Dcat\Admin\Repositories\EloquentRepository; |
||||
|
|
||||
|
class IndustryOrder extends EloquentRepository |
||||
|
{ |
||||
|
/** |
||||
|
* Model. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $eloquentClass = Model::class; |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminSupplier\Repositories; |
||||
|
|
||||
|
use App\Models\IndustryProduct as Model; |
||||
|
use Dcat\Admin\Repositories\EloquentRepository; |
||||
|
|
||||
|
class IndustryProduct extends EloquentRepository |
||||
|
{ |
||||
|
/** |
||||
|
* Model. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $eloquentClass = Model::class; |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Models; |
||||
|
|
||||
|
use Dcat\Admin\Traits\HasDateTimeFormatter; |
||||
|
use Illuminate\Database\Eloquent\SoftDeletes; |
||||
|
|
||||
|
class IndustryOrder extends BaseModel |
||||
|
{ |
||||
|
use HasDateTimeFormatter; |
||||
|
use SoftDeletes; |
||||
|
|
||||
|
public function supplier() |
||||
|
{ |
||||
|
return $this->belongsTo(Supplier::class); |
||||
|
} |
||||
|
|
||||
|
public function agent() |
||||
|
{ |
||||
|
return $this->belongsTo(Agent::class); |
||||
|
} |
||||
|
|
||||
|
public function industryProduct() |
||||
|
{ |
||||
|
return $this->belongsTo(IndustryProduct::class); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,31 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Models; |
||||
|
|
||||
|
use Dcat\Admin\Traits\HasDateTimeFormatter; |
||||
|
use Illuminate\Database\Eloquent\SoftDeletes; |
||||
|
|
||||
|
class IndustryProduct extends BaseModel |
||||
|
{ |
||||
|
use HasDateTimeFormatter; |
||||
|
use SoftDeletes; |
||||
|
|
||||
|
protected $casts = ['pictures' => '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); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
<?php |
||||
|
return [ |
||||
|
'labels' => [ |
||||
|
'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' => [ |
||||
|
], |
||||
|
]; |
||||
@ -0,0 +1,29 @@ |
|||||
|
<?php |
||||
|
return [ |
||||
|
'labels' => [ |
||||
|
'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'), |
||||
|
], |
||||
|
]; |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue