| 
					
					
						
							
						
					
					
				 | 
				@ -2,6 +2,7 @@ | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
				namespace App\Http\Controllers\Api; | 
				 | 
				 | 
				namespace App\Http\Controllers\Api; | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				use App\Common\PayType; | 
			
		
		
	
		
			
				 | 
				 | 
				use App\Http\Controllers\Controller; | 
				 | 
				 | 
				use App\Http\Controllers\Controller; | 
			
		
		
	
		
			
				 | 
				 | 
				use App\Models\Agent; | 
				 | 
				 | 
				use App\Models\Agent; | 
			
		
		
	
		
			
				 | 
				 | 
				use App\Models\AgentProduct; | 
				 | 
				 | 
				use App\Models\AgentProduct; | 
			
		
		
	
	
		
			
				| 
					
						
							
						
					
					
						
							
						
					
					
				 | 
				@ -82,11 +83,12 @@ class OrderController extends Controller | 
			
		
		
	
		
			
				 | 
				 | 
						$formData = array_map(fn($v) => trim($v), $formData); //过滤,删除首尾空
 | 
				 | 
				 | 
						$formData = array_map(fn($v) => trim($v), $formData); //过滤,删除首尾空
 | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
						//表单验证
 | 
				 | 
				 | 
						//表单验证
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
						$pay_type_values = join(',', array_keys(PayType::array())); | 
			
		
		
	
		
			
				 | 
				 | 
						$request->validate([ | 
				 | 
				 | 
						$request->validate([ | 
			
		
		
	
		
			
				 | 
				 | 
							'id' => ['required', 'regex:/^\d+$/'], | 
				 | 
				 | 
							'id' => ['required', 'regex:/^\d+$/'], | 
			
		
		
	
		
			
				 | 
				 | 
							'name' => ['required', 'between:2,20'], | 
				 | 
				 | 
							'name' => ['required', 'between:2,20'], | 
			
		
		
	
		
			
				 | 
				 | 
							'mobile' => ['required', 'regex:/^1[3-9]\d{9}$/'], | 
				 | 
				 | 
							'mobile' => ['required', 'regex:/^1[3-9]\d{9}$/'], | 
			
		
		
	
		
			
				 | 
				 | 
							'pay_type' => ['required', 'in:0,1,2,3'], | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							'pay_type' => ['required', 'in:' . $pay_type_values], | 
			
		
		
	
		
			
				 | 
				 | 
							'num' => ['required', 'min:1'], | 
				 | 
				 | 
							'num' => ['required', 'min:1'], | 
			
		
		
	
		
			
				 | 
				 | 
						], [ | 
				 | 
				 | 
						], [ | 
			
		
		
	
		
			
				 | 
				 | 
							'id.required' => '未指定产品ID', | 
				 | 
				 | 
							'id.required' => '未指定产品ID', | 
			
		
		
	
	
		
			
				| 
					
						
							
						
					
					
						
							
						
					
					
				 | 
				@ -145,8 +147,8 @@ class OrderController extends Controller | 
			
		
		
	
		
			
				 | 
				 | 
								'picture' => $ap->product->picture, | 
				 | 
				 | 
								'picture' => $ap->product->picture, | 
			
		
		
	
		
			
				 | 
				 | 
								'agent_product_id' => $ap->id, | 
				 | 
				 | 
								'agent_product_id' => $ap->id, | 
			
		
		
	
		
			
				 | 
				 | 
								'product_id' => $ap->product_id, | 
				 | 
				 | 
								'product_id' => $ap->product_id, | 
			
		
		
	
		
			
				 | 
				 | 
								'product_ids' => $ap->product->product_ids, | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
								'status' => $formData['pay_type'] == 3 ? Status::OFFLINE_UNPAID : Status::UNPAID, | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
								'product_ids' => $ap->product->product_ids ?? $ap->product_id, | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
								'status' => $formData['pay_type'] == PayType::OFFLINE ? Status::OFFLINE_UNPAID : Status::UNPAID, | 
			
		
		
	
		
			
				 | 
				 | 
								'pay_type' => $formData['pay_type'], | 
				 | 
				 | 
								'pay_type' => $formData['pay_type'], | 
			
		
		
	
		
			
				 | 
				 | 
								'coupon_id' => join(',', $coupon_ids), | 
				 | 
				 | 
								'coupon_id' => join(',', $coupon_ids), | 
			
		
		
	
		
			
				 | 
				 | 
							]); | 
				 | 
				 | 
							]); | 
			
		
		
	
	
		
			
				| 
					
					
					
						
							
						
					
				 | 
				@ -157,7 +159,7 @@ class OrderController extends Controller | 
			
		
		
	
		
			
				 | 
				 | 
							return $this->error($e->getMessage()); | 
				 | 
				 | 
							return $this->error($e->getMessage()); | 
			
		
		
	
		
			
				 | 
				 | 
						} | 
				 | 
				 | 
						} | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
						if ($formData['pay_type'] == 3) { //线下支付
 | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
						if ($formData['pay_type'] == PayType::OFFLINE) { //线下支付
 | 
			
		
		
	
		
			
				 | 
				 | 
							return $this->success('操作成功,请及时联系客服付款'); | 
				 | 
				 | 
							return $this->success('操作成功,请及时联系客服付款'); | 
			
		
		
	
		
			
				 | 
				 | 
						} else { //在线支付或定金支付
 | 
				 | 
				 | 
						} else { //在线支付或定金支付
 | 
			
		
		
	
		
			
				 | 
				 | 
							$config = $this->payConfig($order, $price); | 
				 | 
				 | 
							$config = $this->payConfig($order, $price); | 
			
		
		
	
	
		
			
				| 
					
						
							
						
					
					
						
							
						
					
					
				 | 
				@ -231,6 +233,11 @@ class OrderController extends Controller | 
			
		
		
	
		
			
				 | 
				 | 
							return $this->error('产品信息不存在'); | 
				 | 
				 | 
							return $this->error('产品信息不存在'); | 
			
		
		
	
		
			
				 | 
				 | 
						} | 
				 | 
				 | 
						} | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
						//如果是线下支付,显示的价格跟在线全款支付价格一样
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
						if ($formData['pay_type'] == PayType::OFFLINE) { | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							$formData['pay_type'] = PayType::ONLINE; | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
						} | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
						$ap->final_price = $this->calc($ap->price, $ap->coupon, $formData['num'], $formData['pay_type']); | 
				 | 
				 | 
						$ap->final_price = $this->calc($ap->price, $ap->coupon, $formData['num'], $formData['pay_type']); | 
			
		
		
	
		
			
				 | 
				 | 
						$ap->num = $formData['num']; | 
				 | 
				 | 
						$ap->num = $formData['num']; | 
			
		
		
	
		
			
				 | 
				 | 
						return $this->success($ap); | 
				 | 
				 | 
						return $this->success($ap); | 
			
		
		
	
	
		
			
				| 
					
						
							
						
					
					
						
							
						
					
					
				 | 
				@ -341,12 +348,8 @@ class OrderController extends Controller | 
			
		
		
	
		
			
				 | 
				 | 
					private function calc($price, $coupon, $num, $pay_type) | 
				 | 
				 | 
					private function calc($price, $coupon, $num, $pay_type) | 
			
		
		
	
		
			
				 | 
				 | 
					{ | 
				 | 
				 | 
					{ | 
			
		
		
	
		
			
				 | 
				 | 
						//根据支付方式计算价格
 | 
				 | 
				 | 
						//根据支付方式计算价格
 | 
			
		
		
	
		
			
				 | 
				 | 
						switch ($pay_type) { | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
							case 1: | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
							case 2: | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
								return $this->earnest; | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
							case 3: | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
								return 0; | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
						if (in_array($pay_type, [PayType::SUBSCRIPTION, PayType::DEPOSIT, PayType::DOWN_PAYMENT])) { | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
							return $this->earnest; | 
			
		
		
	
		
			
				 | 
				 | 
						} | 
				 | 
				 | 
						} | 
			
		
		
	
		
			
				 | 
				 | 
						//TODO 还要计算尾款支付金额
 | 
				 | 
				 | 
						//TODO 还要计算尾款支付金额
 | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
	
		
			
				| 
					
						
							
						
					
					
					
				 | 
				
  |