// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\api\controller; use think\response\Json; use app\api\model\Retail as RetailModel; use app\api\model\RetailOrder as RetailOrderModel; use app\api\model\Agreement as AgreementModel; use app\api\service\order\Checkout as CheckoutService; class Retail extends Controller { /** * 获取零售批发会员列表 * @param int $retailType * @return Json */ public function list(int $retailType): Json { $list = RetailModel::withoutGlobalScope()->where('retail_type',$retailType)->where('retail_status',10)->select(); return $this->renderSuccess(compact('list')); } /** * 获取软件付费协议 * @return Json */ public function getSoftAgreement(): Json { $params = $this->request->param(); if (empty($params['type'])) { return $this->renderSuccess("参数错误"); } $detail = AgreementModel::detail(['type' => $params['type']]); if (!empty($detail->content)) { $detail->content = str_ireplace('nowrap', 'inherit', $detail->content); } return $this->renderSuccess(compact('detail')); } /** * 购买会员 * @return Json */ public function purchase(): Json { $model = new RetailModel(); $date = $this->request->post(); // print_r($date); // exit; // $detail = $model->where('retail_price_id',$date['retail_price_id'])->where('retail_status',10)->find(); $detail = $model::detail($date); if(empty($detail)){ return $this->renderError("该会员不存在"); } $data = [ 'user_id'=>$this->user['user_id'], 'retail_order_number'=>$date['num'], ]; print_r($this->user['user_id']); return $this->renderSuccess(compact('pk')); } // /** // * 订单提交 // * @param string $mode // * @return Json // * @throws \think\db\exception\DataNotFoundException // * @throws \think\db\exception\DbException // * @throws \think\db\exception\ModelNotFoundException // * @throws \cores\exception\BaseException // */ // public function submit(string $mode = 'buyNow'): Json // { // return $this->order($mode); // } // public function order(string $mode = 'buyNow'): Json // { // if ($mode === 'buyNow') { // return $this->buyNow(); // // } elseif ($mode === 'cart') { // // return $this->cart(); // } // return $this->renderError('结算模式不合法'); // } // /** // * 订单确认-立即购买 // * @return Json // * @throws \think\db\exception\DataNotFoundException // * @throws \think\db\exception\DbException // * @throws \think\db\exception\ModelNotFoundException // * @throws \cores\exception\BaseException // */ // private function buyNow(): Json // { // // 实例化结算台服务 // $Checkout = new CheckoutService; // // 订单结算api参数 // $params = $Checkout->setParam($this->getParam([ // 'goodsId' => 0, // 'goodsSkuId' => '', // 'goodsNum' => 0, // ])); // // print_r($params); // // 表单验证 // if (!$this->getValidate()->scene('buyNow')->check($params)) { // return $this->renderError($this->getValidate()->getError(), ['isCreated' => false]); // } // // 立即购买:获取订单商品列表 // $model = new RetailOrderModel; // $goodsList = $model->getOrderGoodsListByNow( // (int)$params['goodsId'], // (string)$params['goodsSkuId'], // (int)$params['goodsNum'] // ); // $merchantId = 0; // foreach ($goodsList as $g) { // $merchantId = $g['merchant_id']; // } // // 获取订单确认信息 // $orderInfo = $Checkout->onCheckout($goodsList); // // echo "
";
    //     // print_r($orderInfo['goodsList']->toArray());
    //     // exit;
    //    // print_r($this->request->isGet());
    //     if ($this->request->isGet()) {
    //         return $this->renderSuccess([
    //             'order' => $orderInfo,
    //             'personal' => $Checkout->getPersonal(),
    //             'setting' => $Checkout->getSetting(),
    //         ]);
    //     }
    //     // 验证订单是否存在错误
    //     if ($Checkout->hasError()) {
    //         return $this->renderError($Checkout->getError(), ['isCreated' => false]);
    //     }
    //     // 创建订单 增加订单
    //     $orderInfo['merchantId'] = $merchantId; 
    //     if ($merchantId) {
    //         $model = \app\store\model\Merchant::detail($merchantId, $this->storeId);
    //         $orderInfo['commission_ratio'] = $model['commission_ratio'];
    //     }
    //     //print_r($orderInfo);die;
    //     if (!$Checkout->createOrder($orderInfo)) {
    //         return $this->renderError($Checkout->getError() ?: '订单创建失败', ['isCreated' => false]);
    //     }
    //     // 返回状态
    //     return $this->renderSuccess(['orderId' => $Checkout->model['order_id']], '订单创建成功');
    // }

    //     /**
    //  * 获取结算台验证器
    //  * @return CheckoutValidate
    //  */
    // private function getValidate(): CheckoutValidate
    // {
    //     if (is_null($this->validate)) {
    //         $this->validate = new CheckoutValidate;
    //     }
    //     return $this->validate;
    // }

    //     /**
    //  * 订单结算提交的参数
    //  * @param array $define
    //  * @return array
    //  */
    // private function getParam(array $define = []): array
    // {
    //     return array_merge($define, $this->request->param());
    // }


}