request->post(); $ghsId = $post['ghsId'] ?? 0; //供货商 $supplier = GhsClass::getById($ghsId); if (empty($supplier)) { util::fail('没有找到供货商'); } $currentShopId = $supplier['shopId'] ?? 0; $post['merchantId'] = $this->sjId; $post['shopId'] = $this->shopId; $post['shopAdminId'] = $this->shopAdminId; $shopAdmin = $this->shopAdmin; $name = $shopAdmin['name'] ?? ''; $post['shopAdminName'] = $name; $product = $post['product'] ?? ''; $productList = json_decode($product, true); //判断product数据是不是同个供货商的 ProductClass::valid($productList, $currentShopId); $post['product'] = $productList; $respond = PurchaseClass::addPurchase($post); $orderSn = $respond['orderSn'] ?? ''; $actPrice = $respond['actPrice'] ?? ''; $data = [ 'orderSn' => $orderSn, 'actPrice' => $actPrice, 'hasBalancePay' => 1, 'hasPayPassword' => 0, 'hasDebtPay' => 1, ]; util::success($data); } //延期支付 ssh 2021.1.24 public function actionDebtPay() { $get = Yii::$app->request->get(); $orderSn = $get['orderSn'] ?? 0; $info = PurchaseClass::getByCondition(['orderSn' => $orderSn]); PurchaseClass::valid($info, $this->shopId); PurchaseClass::debt($info); util::complete(); } //余额支付 ssh 2021.1.24 public function actionBalancePay() { $get = Yii::$app->request->get(); $orderSn = $get['orderSn'] ?? 0; $password = $get['password'] ?? ''; $info = PurchaseClass::getByCondition(['orderSn' => $orderSn]); if (empty($info)) { util::fail('没有找到采购单'); } PurchaseClass::valid($info, $this->shopId); purchaseClass::balancePay($info); util::complete(); } //采购记录 ssh 2021.1.24 public function actionList() { $get = Yii::$app->request->get(); $where = ['shopId' => $this->shopId]; $status = $get['status'] ?? 0; if (!empty($status)) { $where['status'] = $status; } $list = PurchaseService::getPurchaseList($where); util::success($list); } //采购详情 ssh 2021.01.25 public function actionDetail() { $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $info = PurchaseClass::getInfo($id, true, true); PurchaseClass::valid($info, $this->shopId); util::success($info); } //可用的支付方式 ssh 2021.1.25 public function actionPayWay() { $button = [ ['type' => 'wxPay', 'show' => 1, 'disable' => 1], ['type' => 'debtPay', 'show' => 1, 'disable' => 0], ['type' => 'balancePay', 'show' => 1, 'disable' => 0], ]; util::success(['button' => $button]); } //待结款明细 ssh 2021.1.26 public function actionDebtList() { $where = [ 'merchantId' => $this->sjId, 'debt' => PurchaseClass::DEBT_YES ]; $respond = PurchaseService::getDebtList($where); util::success($respond); } //微信支付 shish 2021.4.11 public function actionWxPay() { ini_set('date.timezone', 'Asia/Shanghai'); $post = Yii::$app->request->post(); $couponId = $post['couponId'] ?? 0; $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0; $order = PurchaseClass::getByCondition(['orderSn' => $orderSn]); if (empty($order)) { util::fail('订单号无效'); } $id = $order['id']; $name = $orderSn; $totalFee = $order['actPrice']; //强制使用小程序的miniOpenId $openId = $this->admin['miniOpenId']; $typeList = dict::getConfig('capitalType'); $capitalType = $typeList['xhPurchase']['id']; //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调 $wxPayType = 0; if (httpUtil::isMiniProgram()) { $wxPayType = 1; } $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType; //订单30分钟后过期 $now = time(); $expireTime = $now + 1800; $wx = Yii::getAlias("@vendor/weixin"); require_once($wx . '/lib/WxPay.Api.php'); require_once($wx . '/example/WxPay.JsApiPay.php'); $input = new \WxPayUnifiedOrder(); $input->SetBody($name); $input->SetOut_trade_no($orderSn); $input->SetTotal_fee($totalFee * 100); $input->SetTime_start(date("YmdHis", $now)); $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传 $input->SetTime_expire(date("YmdHis", $expireTime)); $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/'); $input->SetTrade_type("JSAPI"); //花卉宝代为申请的微信支付 $merchantExtend = WxOpenClass::getWxInfo(); if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) { $input->SetSub_openid($openId); } else { $input->SetOpenid($openId); } //强制使用小程序的miniAppId $merchantExtend['wxAppId'] = $merchantExtend['miniAppId']; $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend); $tools = new \JsApiPay(); $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend); $newParams = json_decode($jsApiParameters, true); $current = date("Y-m-d H:i:s"); $updateData = ['deadline' => $current, 'changePrice' => 2]; PurchaseClass::updateById($id, $updateData); util::success($newParams); } //运费计算 linqh 2021.4.12 暂反回固定 public function actionFreight() { util::success(['sedCost' => 10]); } }