public function weiXinUnifiedOrderByApp($orderId = 0, $orderLongId = 0) { $orderInfo = null; if ($orderId > 0) { $orderInfo = UserOrder::findFirst('order_id = ' . $orderId); } elseif ($orderLongId > 0) { $orderInfo = UserOrder::findFirst('order_long_id = ' . $orderLongId); } if (!$orderInfo) { return false; } $orderId = $orderInfo->order_id; $orderLongId = $orderInfo->order_long_id; $totalFee = $orderInfo->order_money; $titleArr = []; // 商品信息 $goods = UserOrderGoods::query()->columns('service_name name')->where('order_id = :oid:', ['oid' => $orderId])->leftJoin('Apps\\Common\\Models\\BeautyParlorService', 'service_id = goods_id', 'bps')->execute(); foreach ($goods as $d) { $titleArr[] = $d->name; } $title = implode(',', $titleArr); $payConfig = (include APP_COMMON_PATH . "base-config/pay.php"); $wxPay = new WeiXinPay($payConfig['weixin']); $info = $wxPay->unifiedOrder($orderLongId, $title, $totalFee, 'APP'); if ($info == false) { return false; } return $info['prepayId']; }
public function setRefundAction() { $req = $this->request; if ($req->isPost()) { $id = intval($req->getPost('id', null, 0)); $state = -10; $info = UserOrder::findFirst('order_id=' . $id); if ($info) { $info->update(['order_state' => $state, 'order_pay_state' => $state]); } return (new ResponseResult())->sendResult('ok'); } else { return (new ResponseResult())->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '请求异常'); } }
/** * @param $orderLongId * @return UserOrder */ protected function getOrderInfo($orderLongId) { return UserOrder::findFirst('order_long_id = ' . $orderLongId); }
public function run() { /** * 验证用户权限 */ if (false == $this->verifyUserAuth()) { return false; } $userId = $this->getUserAuth()->userId; $longId = $this->getDataItem('long_id', 0); $payType = $this->getDataItem('pay_type', ''); $state = $this->getDataItem('state', null); $payOrderNum = $this->getDataItem('pay_order_num', null); if ($longId == 0 || empty($state)) { return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR); } $payTypeValue = $this->getPayTypeNum($payType); if ($payTypeValue <= 0) { return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '支付方式不支持.'); } $stateValues = ['success', 'fail']; if (!in_array($state, $stateValues)) { return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '状态值错误.'); } $stateValue = 0; $logState = 0; switch ($state) { case $stateValues[0]: $stateValue = 1; $logState = PayState::SYNC_SUCCESS; break; case $stateValues[1]: $stateValue = 0; $logState = PayState::SYNC_FAIL; break; } // 获取订单ID $orderInfo = UserOrder::findFirst("order_long_id={$longId} AND user_id={$userId}"); if (!$orderInfo) { $this->setResult(['success' => 0, 'message' => '长订单号不存在.']); return; } $orderId = $orderInfo->order_id; $this->savePayLog($longId, $payType, $payOrderNum, $logState); if ($stateValue == 0) { // 支付失败,不处理 $this->setResult(['success' => 1]); return; } if ($orderInfo->order_pay_state < $stateValue) { if ($orderInfo->order_state < $stateValue) { $orderInfo->order_state = $stateValue; } $orderInfo->order_pay_state = $stateValue; if (!$orderInfo->save()) { return $this->databaseErrorLog($orderInfo); } } // 添加支付记录 $this->setResult(['success' => 1]); }