Browse Source
			
			
			Merge remote-tracking branch 'origin/master'
			
				
		Merge remote-tracking branch 'origin/master'
	
		
	
			
				# Conflicts: # app/Http/Controllers/Api/TestController.phpmaster
				 72 changed files with 1941 additions and 242 deletions
			
			
		- 
					80MySQL_change.sql
 - 
					16app/Admin/Controllers/AgentController.php
 - 
					12app/Admin/Controllers/GuideController.php
 - 
					122app/Admin/Controllers/IndustryProductController.php
 - 
					1app/Admin/Controllers/OrderController.php
 - 
					17app/Admin/Controllers/ServicePersonsSettingController.php
 - 
					12app/Admin/Controllers/SupplierController.php
 - 
					6app/Admin/Extensions/Grid/AuditAgent.php
 - 
					88app/Admin/Extensions/Grid/AuditIndustryProduct.php
 - 
					56app/Admin/Forms/ServicePersonsSetting.php
 - 
					16app/Admin/Repositories/IndustryProduct.php
 - 
					4app/Admin/routes.php
 - 
					26app/AdminAgent/Controllers/AgentProductController.php
 - 
					20app/AdminAgent/Controllers/DemandController.php
 - 
					161app/AdminAgent/Controllers/IndustryOrderController.php
 - 
					90app/AdminAgent/Controllers/IndustryProductController.php
 - 
					3app/AdminAgent/Controllers/NoticeController.php
 - 
					1app/AdminAgent/Controllers/OrderController.php
 - 
					2app/AdminAgent/Renderable/SelectAgentCloudProduct.php
 - 
					16app/AdminAgent/Repositories/IndustryOrder.php
 - 
					16app/AdminAgent/Repositories/IndustryProduct.php
 - 
					4app/AdminAgent/routes.php
 - 
					2app/AdminGuide/Controllers/DemandBiddingController.php
 - 
					27app/AdminGuide/Controllers/DemandController.php
 - 
					4app/AdminGuide/Controllers/MyDemandProductController.php
 - 
					2app/AdminGuide/Controllers/WorkorderController.php
 - 
					86app/AdminGuide/Extensions/Grid/ChooseDemand.php
 - 
					48app/AdminGuide/Lazys/DemandBiddingLazys.php
 - 
					16app/AdminGuide/Repositories/Workorder.php
 - 
					25app/AdminSupplier/Controllers/DemandController.php
 - 
					1app/AdminSupplier/Controllers/FinanceStatisticsController.php
 - 
					144app/AdminSupplier/Controllers/IndustryOrderController.php
 - 
					284app/AdminSupplier/Controllers/IndustryProductController.php
 - 
					3app/AdminSupplier/Controllers/MyBiddingProductController.php
 - 
					4app/AdminSupplier/Controllers/MyDemandProductController.php
 - 
					1app/AdminSupplier/Controllers/OrderController.php
 - 
					34app/AdminSupplier/Controllers/ProductController.php
 - 
					4app/AdminSupplier/Controllers/ProductStatisticsController.php
 - 
					2app/AdminSupplier/Controllers/WithdrawalAlipayController.php
 - 
					2app/AdminSupplier/Controllers/WorkorderController.php
 - 
					2app/AdminSupplier/Extensions/Grid/ChooseDemand.php
 - 
					73app/AdminSupplier/Extensions/Grid/IndustryOrderStatus.php
 - 
					4app/AdminSupplier/Lazys/DemandBiddingLazys.php
 - 
					20app/AdminSupplier/Lazys/ProductForm.php
 - 
					1app/AdminSupplier/Renderable/SelectProduct.php
 - 
					16app/AdminSupplier/Repositories/IndustryOrder.php
 - 
					16app/AdminSupplier/Repositories/IndustryProduct.php
 - 
					16app/AdminSupplier/Repositories/Workorder.php
 - 
					4app/AdminSupplier/routes.php
 - 
					4app/Common/StatementType.php
 - 
					2app/Http/Controllers/Api/AgentProductController.php
 - 
					2app/Http/Controllers/Api/IndexController.php
 - 
					3app/Http/Controllers/Api/NoticeController.php
 - 
					31app/Http/Controllers/Api/OrderController.php
 - 
					2app/Http/Controllers/Api/SharePayController.php
 - 
					296app/Http/Controllers/Api/VerificationController.php
 - 
					27app/Models/IndustryOrder.php
 - 
					31app/Models/IndustryProduct.php
 - 
					5app/Models/Notice.php
 - 
					2app/Models/Order.php
 - 
					2app/Traits/DemandTraits.php
 - 
					38database/migrations/2021_09_18_110418_update_order_table_0917_table.php
 - 
					32database/migrations/2021_09_18_153814_update_notice_table_table.php
 - 
					8dcat_admin_ide_helper.php
 - 
					3ready.md
 - 
					3resources/lang/zh_CN/agent-info.php
 - 
					1resources/lang/zh_CN/agent-product.php
 - 
					27resources/lang/zh_CN/industry-order.php
 - 
					29resources/lang/zh_CN/industry-product.php
 - 
					5resources/lang/zh_CN/order.php
 - 
					18resources/lang/zh_CN/waterfall-ad.php
 - 
					2routes/api.php
 
@ -1,3 +1,83 @@ | 
				
			|||
# 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`; | 
				
			|||
 | 
				
			|||
# 15:59 2021/9/18 | 
				
			|||
ALTER TABLE `agent_products` | 
				
			|||
	CHANGE COLUMN `guide_id` `guide_id` INT(10) NOT NULL DEFAULT '0' COMMENT '绑定地接(计调版旅行社才能绑定)' AFTER `category_id`, | 
				
			|||
	CHANGE COLUMN `type` `type` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '0:单品销售;1:组合销售;2:计调旅行社的云产品;' AFTER `is_rec`, | 
				
			|||
	CHANGE COLUMN `is_cloud` `is_cloud` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '是否是(计调旅行社特有)云产品,。0:否;1:是;' AFTER `earnest_timeout`, | 
				
			|||
	CHANGE COLUMN `agent_cloud_pid` `agent_cloud_pid` INT(10) NOT NULL DEFAULT '0' COMMENT '计调版旅行社的云产品ID' AFTER `is_cloud`; | 
				
			|||
ALTER TABLE `orders` | 
				
			|||
	CHANGE COLUMN `agent_cloud_pid` `agent_cloud_pid` INT(10) NOT NULL DEFAULT '0' COMMENT '计调云产品ID' AFTER `verify_code`, | 
				
			|||
	CHANGE COLUMN `agent_cloud_price` `agent_cloud_price` DECIMAL(20,2) NOT NULL DEFAULT '0.00' COMMENT '计调云产品销售价格' AFTER `agent_cloud_pid`; | 
				
			|||
@ -0,0 +1,122 @@ | 
				
			|||
<?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(); | 
				
			|||
			$grid->disableDeleteButton(); | 
				
			|||
			$grid->disableEditButton(); | 
				
			|||
 | 
				
			|||
			//如果是审核页面,多加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->disableDeleteButton(); | 
				
			|||
			$show->disableEditButton(); | 
				
			|||
 | 
				
			|||
			$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->disableDeleteButton(); | 
				
			|||
 | 
				
			|||
            $form->display('id'); | 
				
			|||
            $form->select('status')->options(ProductStatus::array()); | 
				
			|||
        })->saving(function (Form $form) { | 
				
			|||
			return $form->response()->error('操作禁止!')->refresh(); //禁止编辑,如果非要编辑的话,记录冻结和解决交易金
 | 
				
			|||
		})->deleting(function (Form $form) { | 
				
			|||
			return $form->response()->error('操作禁止!')->refresh(); | 
				
			|||
		}); | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,17 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace App\Admin\Controllers; | 
				
			|||
 | 
				
			|||
use App\Admin\Forms\ServicePersonsSetting; | 
				
			|||
use Dcat\Admin\Layout\Content; | 
				
			|||
use Dcat\Admin\Http\Controllers\AdminController; | 
				
			|||
use Dcat\Admin\Widgets\Card; | 
				
			|||
class ServicePersonsSettingController extends AdminController | 
				
			|||
{ | 
				
			|||
	public function index(Content $content) | 
				
			|||
	{ | 
				
			|||
		return $content | 
				
			|||
			->title('交易设置') | 
				
			|||
			->body(new Card(new ServicePersonsSetting())); | 
				
			|||
	} | 
				
			|||
} | 
				
			|||
@ -0,0 +1,88 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace App\Admin\Extensions\Grid; | 
				
			|||
use App\Common\ProductStatus; | 
				
			|||
use App\Models\IndustryProduct; | 
				
			|||
use App\Models\Supplier; | 
				
			|||
use App\Models\SystemSetting; | 
				
			|||
use Dcat\Admin\Admin; | 
				
			|||
use Dcat\Admin\Grid\RowAction; | 
				
			|||
use Illuminate\Http\Request; | 
				
			|||
use Illuminate\Support\Facades\DB; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * 行业产品审核 | 
				
			|||
 * 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) | 
				
			|||
	{ | 
				
			|||
		DB::beginTransaction(); | 
				
			|||
		try { | 
				
			|||
			//修改产品状态
 | 
				
			|||
			$industry = IndustryProduct::find($this->getKey()); | 
				
			|||
			$industry->status = $request->action == 1 ? ProductStatus::ON_SALE : ProductStatus::REFUSE; | 
				
			|||
			$industry->save(); | 
				
			|||
 | 
				
			|||
			//如果是通过,扣除交易金,如果拒绝返还冻结金额
 | 
				
			|||
			$single = SystemSetting::val('single', 'price'); //单人头交易金
 | 
				
			|||
 | 
				
			|||
			$supplier = Supplier::find(Admin::user()->id); | 
				
			|||
 | 
				
			|||
			$change_deposit = $single * $industry->stock * $industry->service_persons; | 
				
			|||
			if ($industry->status == ProductStatus::ON_SALE) { | 
				
			|||
				if ($supplier->deposit_normal < $change_deposit) { | 
				
			|||
					throw new \Exception('交易金不足,无法扣除'); | 
				
			|||
				} | 
				
			|||
 | 
				
			|||
				$supplier->deposit_normal = $supplier->deposit_normal - $change_deposit; | 
				
			|||
				$supplier->deposit_frozen = $supplier->deposit_frozen + $change_deposit; | 
				
			|||
				$supplier->save(); | 
				
			|||
			} /*else if ($industry->status == ProductStatus::REFUSE) { //拒绝无需处理
 | 
				
			|||
				if ($supplier->deposit_frozen < $change_deposit) { | 
				
			|||
					throw new \Exception('冻结金不足,无法扣除'); | 
				
			|||
				} | 
				
			|||
 | 
				
			|||
				$supplier->deposit_normal = $supplier->deposit_normal + $change_deposit; | 
				
			|||
				$supplier->deposit_frozen = $supplier->deposit_frozen - $change_deposit; | 
				
			|||
				$supplier->save(); | 
				
			|||
			}*/ | 
				
			|||
 | 
				
			|||
			DB::commit(); | 
				
			|||
			return $this->response()->success("审核成功")->refresh(); | 
				
			|||
		} catch (\Exception $e) { | 
				
			|||
			DB::rollBack(); | 
				
			|||
			return $this->response()->error($e->getMessage()); | 
				
			|||
		} | 
				
			|||
	} | 
				
			|||
 | 
				
			|||
	public function confirm() | 
				
			|||
	{ | 
				
			|||
		return ['确定要'.$this->title.'该产品吗?', '']; | 
				
			|||
	} | 
				
			|||
 | 
				
			|||
	public function parameters() | 
				
			|||
	{ | 
				
			|||
		return ['action' => $this->action]; | 
				
			|||
	} | 
				
			|||
} | 
				
			|||
@ -0,0 +1,56 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace App\Admin\Forms; | 
				
			|||
 | 
				
			|||
use App\Traits\WithdrawalTraits; | 
				
			|||
use Dcat\Admin\Widgets\Form; | 
				
			|||
 | 
				
			|||
class ServicePersonsSetting extends Form | 
				
			|||
{ | 
				
			|||
    /** | 
				
			|||
     * Handle the form request. | 
				
			|||
     * | 
				
			|||
     * @param array $input | 
				
			|||
     * | 
				
			|||
     * @return mixed | 
				
			|||
     */ | 
				
			|||
    public function handle(array $input) | 
				
			|||
    { | 
				
			|||
		$system = \App\Models\SystemSetting::query()->firstOrCreate([ | 
				
			|||
			'key' => 'single' | 
				
			|||
		]); | 
				
			|||
 | 
				
			|||
		$arr = [ | 
				
			|||
			'price' => $input['price'], | 
				
			|||
		]; | 
				
			|||
		$system->value = $arr; | 
				
			|||
		$system->save(); | 
				
			|||
        return $this | 
				
			|||
				->response() | 
				
			|||
				->success('设置成功') | 
				
			|||
				->refresh(); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * Build a form here. | 
				
			|||
     */ | 
				
			|||
    public function form() | 
				
			|||
    { | 
				
			|||
		$this->decimal('price','单人头交易费')->rules('required|numeric|min:0|not_in:0',[ | 
				
			|||
			'*' => '金额为必填字段且必须大于0', | 
				
			|||
		]); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * The data of the form. | 
				
			|||
     * | 
				
			|||
     * @return array | 
				
			|||
     */ | 
				
			|||
    public function default() | 
				
			|||
    { | 
				
			|||
    	$system = \App\Models\SystemSetting::query()->where('key','single')->value('value'); | 
				
			|||
        return [ | 
				
			|||
			'price' => $system['price'] ?? 0, | 
				
			|||
        ]; | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -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,86 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace App\AdminGuide\Extensions\Grid; | 
				
			|||
 | 
				
			|||
use App\Models\AgentProduct; | 
				
			|||
use App\Models\DemandBidding; | 
				
			|||
use App\Traits\DemandTraits; | 
				
			|||
use Dcat\Admin\Grid\RowAction; | 
				
			|||
use Illuminate\Http\Request; | 
				
			|||
use Illuminate\Support\Facades\DB; | 
				
			|||
use Illuminate\Support\Facades\Log; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * 供应商审核 | 
				
			|||
 * Class AuditSupplier | 
				
			|||
 * @package App\Admin\Extensions\Grid | 
				
			|||
 */ | 
				
			|||
class ChooseDemand extends RowAction | 
				
			|||
{ | 
				
			|||
	private $id; | 
				
			|||
 | 
				
			|||
	public function __construct($biddingId = '') | 
				
			|||
	{ | 
				
			|||
		parent::__construct('选中竞标'); | 
				
			|||
		$this->id = $biddingId; | 
				
			|||
		$this->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) | 
				
			|||
	{ | 
				
			|||
		$demandBiddingId = request('bidding_id',0); | 
				
			|||
		$demandBidding = DemandBidding::find($demandBiddingId); | 
				
			|||
		if (empty($demandBidding)) { | 
				
			|||
			return $this->response()->error('订单异常'); | 
				
			|||
		} | 
				
			|||
 | 
				
			|||
		$demand = \App\Models\Demand::find($demandBidding->demand_id); | 
				
			|||
 | 
				
			|||
		if (empty($demand)) { | 
				
			|||
			return $this->response()->error('订单异常'); | 
				
			|||
		} | 
				
			|||
 | 
				
			|||
		DB::beginTransaction(); | 
				
			|||
		try { | 
				
			|||
			$demandBidding->state = 1; | 
				
			|||
			$demandBidding->save(); | 
				
			|||
			//改变订单状态
 | 
				
			|||
			$demand->bidding_id = $demandBidding->id; | 
				
			|||
			$demand->bidding_user_id = $demandBidding->bidding_user_id; | 
				
			|||
			$demand->state = DemandTraits::$stateKey[1]; | 
				
			|||
			$demand->save(); | 
				
			|||
			//如果是地接类型 绑定地接到订单
 | 
				
			|||
			if ($demand->bidding_user_type ==  DemandTraits::$col[2]){ | 
				
			|||
				$agentProduct = AgentProduct::find($demand->agent_product_id); | 
				
			|||
				$agentProduct->guide_id = $demandBidding->bidding_user_id; | 
				
			|||
				$agentProduct->guide_price = $demandBidding->price; | 
				
			|||
				$agentProduct->save(); | 
				
			|||
			} | 
				
			|||
			DB::commit(); | 
				
			|||
			return $this->response()->success("选中竞标成功")->refresh(); | 
				
			|||
		} catch (\Exception $e) { | 
				
			|||
			Log::error('选中竞标失败::'.$e->getTraceAsString()); | 
				
			|||
			DB::rollBack(); | 
				
			|||
			return $this->response()->error($e->getMessage()); | 
				
			|||
		} | 
				
			|||
	} | 
				
			|||
 | 
				
			|||
	public function confirm() | 
				
			|||
	{ | 
				
			|||
		return ['确定要选中该竞标吗?', '']; | 
				
			|||
	} | 
				
			|||
 | 
				
			|||
	public function parameters() | 
				
			|||
	{ | 
				
			|||
		return ['bidding_id' => $this->id]; | 
				
			|||
	} | 
				
			|||
} | 
				
			|||
@ -0,0 +1,48 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
 | 
				
			|||
namespace App\AdminGuide\Lazys; | 
				
			|||
 | 
				
			|||
use App\AdminGuide\Extensions\Grid\ChooseDemand; | 
				
			|||
use App\AdminGuide\Repositories\DemandBidding; | 
				
			|||
use App\Models\Demand; | 
				
			|||
use App\Traits\DemandTraits; | 
				
			|||
use Dcat\Admin\Grid; | 
				
			|||
use Dcat\Admin\Grid\LazyRenderable; | 
				
			|||
use Illuminate\Support\Arr; | 
				
			|||
 | 
				
			|||
class DemandBiddingLazys extends LazyRenderable | 
				
			|||
{ | 
				
			|||
    public function grid(): Grid | 
				
			|||
    { | 
				
			|||
        return Grid::make(new DemandBidding(['biddingUser']), function (Grid $grid) { | 
				
			|||
            $demandId = request('demand_id',''); | 
				
			|||
			$demand = Demand::find($demandId); | 
				
			|||
			$grid->model()->where('demand_id',$demandId); | 
				
			|||
			$grid->column('id'); | 
				
			|||
			$grid->column('price','出价')->sortable(); | 
				
			|||
			$grid->column('comment','内容'); | 
				
			|||
			$grid->column('biddingUser.name','竞拍人'); | 
				
			|||
			$grid->column('bidding','竞标') | 
				
			|||
				->if(function () use ($demand){ | 
				
			|||
					return $demand->state == 1; | 
				
			|||
				}) | 
				
			|||
				->then(function (Grid\Column $column) { | 
				
			|||
					$column->append(new ChooseDemand($this->id)); | 
				
			|||
				}) | 
				
			|||
				->if(function () use ($demand){ | 
				
			|||
					return $demand->state == 2; | 
				
			|||
				}) | 
				
			|||
				->then(function (Grid\Column $column) use ($demand){ | 
				
			|||
					if ($demand->bidding_id == $this->id) { | 
				
			|||
						$column->append('<span class="text-success">已中标</span>'); | 
				
			|||
					} else { | 
				
			|||
						$column->append('<span class="text-danger">未中标</span>'); | 
				
			|||
					} | 
				
			|||
				}); | 
				
			|||
			$grid->column('created_at'); | 
				
			|||
			$grid->disableActions(); | 
				
			|||
			$grid->disableRowSelector(); | 
				
			|||
        }); | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,16 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace App\AdminGuide\Repositories; | 
				
			|||
 | 
				
			|||
use App\Models\Workorder as Model; | 
				
			|||
use Dcat\Admin\Repositories\EloquentRepository; | 
				
			|||
 | 
				
			|||
class Workorder 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个字符,故通过下面这种方式传参
 | 
				
			|||
		//pt表示使用普通订单,使用api/verification/verify接口核销;
 | 
				
			|||
		//hy表示行业产品订单,使用api/verification/industry_verify接口核销
 | 
				
			|||
		$response = $app->app_code->getUnlimit('hy' . $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,284 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace App\AdminSupplier\Controllers; | 
				
			|||
 | 
				
			|||
use App\AdminSupplier\Repositories\IndustryProduct; | 
				
			|||
use App\Common\ProductStatus; | 
				
			|||
use App\Models\Category; | 
				
			|||
use App\Models\Order; | 
				
			|||
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; | 
				
			|||
use Illuminate\Support\Facades\DB; | 
				
			|||
 | 
				
			|||
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->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) { | 
				
			|||
			$show->disableDeleteButton(); | 
				
			|||
 | 
				
			|||
			//不允许查看非自己的数据
 | 
				
			|||
			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); | 
				
			|||
		$change_deposit = 0; | 
				
			|||
		return Form::make(new IndustryProduct(), function (Form $form) { | 
				
			|||
			$form->disableDeleteButton(); | 
				
			|||
 | 
				
			|||
            $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) use (&$change_deposit) { | 
				
			|||
			//不允许编辑非自己数据
 | 
				
			|||
			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'); | 
				
			|||
			} | 
				
			|||
 | 
				
			|||
			//忽略字段
 | 
				
			|||
			$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; | 
				
			|||
			} | 
				
			|||
 | 
				
			|||
        	//处理交易金
 | 
				
			|||
			//判断交易金是否充足
 | 
				
			|||
			$single = SystemSetting::val('single', 'price'); //单人头交易费
 | 
				
			|||
			if (!$single) { | 
				
			|||
				return $form->response()->error('未设置单人头交易费,请联系管理员在后台设置'); | 
				
			|||
			} | 
				
			|||
 | 
				
			|||
			//TODO 还需要计算涉及用户数
 | 
				
			|||
 | 
				
			|||
			//目前逻辑不考虑单人头交易费变动的情况
 | 
				
			|||
			if ($form->isCreating() || $form->isEditing() && $form->model()->stock != $form->stock) { | 
				
			|||
 | 
				
			|||
				if ($form->isCreating()) { //新增处理
 | 
				
			|||
					$change_deposit = $single * $form->service_persons * $form->stock; | 
				
			|||
				} else if ($form->isEditing() && $form->model()->stock != $form->stock) { //库存变动时冻结或解冻相应的保证金
 | 
				
			|||
					$new_deposit = $single * $form->service_persons * $form->stock; | 
				
			|||
					$old_deposit = $single * $form->service_persons * $form->model()->stock; | 
				
			|||
					$change_deposit = $new_deposit - $old_deposit; //saved里面获取的$form->model()->stock是不对的
 | 
				
			|||
				} | 
				
			|||
 | 
				
			|||
				if (Admin::user()->deposit_normal < $change_deposit) { | 
				
			|||
					return $form->response()->error('交易金不足,请先联系管理员充值'); | 
				
			|||
				} | 
				
			|||
			} | 
				
			|||
		})->saved(function (Form $form, $result) use (&$change_deposit) { | 
				
			|||
			if ($form->isEditing()) { //有extends判断不准
 | 
				
			|||
				//待审核
 | 
				
			|||
				if ($form->model()->wasChanged(['title', 'price', 'original_price', 'pictures', 'know', 'content'])) { | 
				
			|||
					DB::beginTransaction(); | 
				
			|||
					try { | 
				
			|||
						//将产品状态改为未审核
 | 
				
			|||
						$form->model()->update(['status' => ProductStatus::UNAUDITED]); | 
				
			|||
 | 
				
			|||
						//如果产品未审核,重新计算交易金。通过或拒绝之后再扣掉 TODO 改变库存和涉及用户数要考虑。未审核也需要重新全部减掉
 | 
				
			|||
						$supplier = Supplier::query()->find(Admin::user()->id); //不能使用Admin::user()修改,必须使用Supplier模型才能正确记录资金变动日志
 | 
				
			|||
 | 
				
			|||
						$supplier->deposit_normal = $supplier->deposit_normal - $change_deposit; //正常交易金
 | 
				
			|||
						$supplier->deposit_frozen = $supplier->deposit_frozen + $change_deposit; //冻结交易金
 | 
				
			|||
						$supplier->save(); | 
				
			|||
						DB::commit(); | 
				
			|||
					} catch (\Exception $e) { | 
				
			|||
						DB::rollBack(); | 
				
			|||
					} | 
				
			|||
				} else { //不是待审核
 | 
				
			|||
 | 
				
			|||
				} | 
				
			|||
			} | 
				
			|||
 | 
				
			|||
			/*if ($result && ($form->isCreating() || $form->isEditing() && $form->model()->wasChanged('stock'))) { | 
				
			|||
 | 
				
			|||
			}*/ | 
				
			|||
		})->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,16 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace App\AdminSupplier\Repositories; | 
				
			|||
 | 
				
			|||
use App\Models\Workorder as Model; | 
				
			|||
use Dcat\Admin\Repositories\EloquentRepository; | 
				
			|||
 | 
				
			|||
class Workorder 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,38 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
use Illuminate\Database\Migrations\Migration; | 
				
			|||
use Illuminate\Database\Schema\Blueprint; | 
				
			|||
use Illuminate\Support\Facades\Schema; | 
				
			|||
 | 
				
			|||
class UpdateOrderTable0917Table extends Migration | 
				
			|||
{ | 
				
			|||
    /** | 
				
			|||
     * Run the migrations. | 
				
			|||
     * | 
				
			|||
     * @return void | 
				
			|||
     */ | 
				
			|||
    public function up() | 
				
			|||
    { | 
				
			|||
		Schema::table('orders', function (Blueprint $table) { | 
				
			|||
			$table->decimal('single_price') | 
				
			|||
				->default(0) | 
				
			|||
				->comment('下单时的单人头交易费'); | 
				
			|||
		}); | 
				
			|||
 | 
				
			|||
		Schema::table('order_product_items', function (Blueprint $table) { | 
				
			|||
			$table->integer('service_persons') | 
				
			|||
				->default(0) | 
				
			|||
				->comment('涉及人数'); | 
				
			|||
		}); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * Reverse the migrations. | 
				
			|||
     * | 
				
			|||
     * @return void | 
				
			|||
     */ | 
				
			|||
    public function down() | 
				
			|||
    { | 
				
			|||
        //
 | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,32 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
use Illuminate\Database\Migrations\Migration; | 
				
			|||
use Illuminate\Database\Schema\Blueprint; | 
				
			|||
use Illuminate\Support\Facades\Schema; | 
				
			|||
 | 
				
			|||
class UpdateNoticeTableTable extends Migration | 
				
			|||
{ | 
				
			|||
    /** | 
				
			|||
     * Run the migrations. | 
				
			|||
     * | 
				
			|||
     * @return void | 
				
			|||
     */ | 
				
			|||
    public function up() | 
				
			|||
    { | 
				
			|||
		Schema::table('notices', function (Blueprint $table) { | 
				
			|||
			$table->tinyInteger('status') | 
				
			|||
				->default(0) | 
				
			|||
				->comment('是否启用 0禁用 1启用'); | 
				
			|||
		}); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * Reverse the migrations. | 
				
			|||
     * | 
				
			|||
     * @return void | 
				
			|||
     */ | 
				
			|||
    public function down() | 
				
			|||
    { | 
				
			|||
        //
 | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -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'), | 
				
			|||
    ], | 
				
			|||
]; | 
				
			|||
@ -1,18 +0,0 @@ | 
				
			|||
<?php | 
				
			|||
return [ | 
				
			|||
    'labels' => [ | 
				
			|||
        'WaterfallAd' => '产品列表内嵌广告', | 
				
			|||
        'waterfall-ad' => '产品列表内嵌广告', | 
				
			|||
    ], | 
				
			|||
    'fields' => [ | 
				
			|||
        'title' => '广告名称', | 
				
			|||
        'agent_id' => '代理商ID', | 
				
			|||
        'picture' => '广告图片', | 
				
			|||
        'type' => '链接', | 
				
			|||
        'url' => '链接地址', | 
				
			|||
        'sort' => '排序', | 
				
			|||
        'status' => '状态', | 
				
			|||
    ], | 
				
			|||
    'options' => [ | 
				
			|||
    ], | 
				
			|||
]; | 
				
			|||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue