service = new OrderService(); parent::__construct($app); } /** * @return \think\response\Json * @throws BaseException */ public function create() { $params = (new CreateOrderValidate())->message([ 'store_id.require' => lang("Stores do not exist"), 'customer_id.require' => lang("Customer do not exist"), 'products.require' => lang("Products do not exist"), ])->requestBodyCheck($this->request); $products = json_decode($params['products']); predicate($products != null, 'products 解析错误'); for ($i = 0; $i < count($products); $i++) { $product = $products[$i]; predicate(isset($product->store_product_id) && $product->store_product_id > 0, '商品ID错误!'); predicate($product->quantity > 0, '商品数量错误!'); predicate($product->adviser_1_id > 0, '销售顾问1必须存在!'); if(isset($product->adviser_2_id)) predicate($product->adviser_2_id > 0, '销售顾问2不符合规则!'); if(isset($product->teacher_id)) predicate($product->teacher_id > 0, '老师不符合规则!'); } $res = $this->service->create($params, $products); predicate($res->bool,$res->message); return $this->ok($res->data); } /** * @return \think\response\Json * @throws BaseException */ public function payment() { $params = $this->request->param(); if(!isset($params['order_id'])) { return $this->fail("订单ID不存在!"); } if(!isset($params['channels'])) { return $this->fail("支付记录不存在!"); } $channels = json_decode($params['channels']); predicate($channels != null, 'channels 解析错误'); for ($i = 0; $i < count($channels); $i++) { $channel = $channels[$i]; predicate(isset($channel->channel_id) && $channel->channel_id > 0, '支付渠道错误!'); if (isset($channel->fee)) { predicate($channel->fee > 0, '支付费用错误!'); } if (isset($channel->credit_card)) { predicate(is_array($channel->credit_card), 'credit_card 不符合规则!'); for ($j = 0; $j < count($channel->credit_card); $j++) { $credit_card = $channel->credit_card[$j]; predicate(isset($credit_card->credit_card_id) && $credit_card->credit_card_id > 0, '信用卡配置id错误!'); predicate($credit_card->fee > 0, '支付费用错误!'); if (isset($credit_card->stage_num)) predicate(in_array($credit_card->stage_num,[6, 9, 12, 24, 36]), '分期数不符合规则!'); } } } $res = $this->service->payment($params, $channels); predicate($res->bool,$res->message); return $this->ok($res->data); } }