/** * 设置订单支付成功 * @param \Apps\Common\Models\UserOrder $orderInfo * @param int $payType * @return bool */ protected function setOrderPaySuccess($orderInfo, $payType) { $data = ['order_pay_type' => $payType, 'order_pay_state' => 2]; if ($orderInfo->order_state < 2) { $data['order_state'] = 2; } return $orderInfo->update($data); }
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 run() { /** * 验证用户权限 */ if (false == $this->verifyUserAuth()) { return false; } $id = intval($this->getDataItem('id', 0)); $state = $this->getDataItem('state', null); if ($id <= 0 || empty($state)) { return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR); } $stateValues = ['cancel', 'delete']; if (!in_array($state, $stateValues)) { return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '状态值错误.'); } $stateValue = 0; switch ($state) { case $stateValues[0]: $stateValue = OrderState::Cancel; break; case $stateValues[1]: $stateValue = OrderState::Delete; break; } UserOrder::SetOrderState($this->getUserAuth()->userId, $id, $stateValue); $this->setResult(['success' => 1]); }
/** * 添加订单基础信息 * @param $longId * @param $mobile * @param $payType * @param $money * @param $userId * @return int */ private function addOrderBase($longId, $mobile, $payType, $money, $userId) { $order = new UserOrder(); $order->order_long_id = $longId; $order->order_type = 1; $order->user_id = $userId; $order->order_mobile = $mobile; $order->order_origin = 1; $order->order_money = $money; $order->order_freight = 0; $order->order_remake = ''; $order->order_pay_type = $payType; if ($order->save()) { return $order->order_id; } else { $this->databaseErrorLog($order); return 0; } }
public function run() { /** * 验证用户权限 */ if (false == $this->verifyUserAuth()) { return false; } $type = $this->getDataItem('type', 'all'); $page = intval($this->getDataItem('page', 0)); $page = $page < 1 ? 1 : $page; $limit = $this->getConfig()->limit; $offset = ($page - 1) * $limit; $userId = $this->getUserAuth()->userId; $typeArray = ['all', 'pay', 'end']; if (!in_array($type, $typeArray)) { return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '查询的类型不存在.'); } $where = 'user_id = :uid:'; $whereParams = ['uid' => $userId]; switch ($type) { case 'all': $where .= ' AND order_state >= 0'; break; case 'pay': $where .= ' AND order_state >= 0 AND order_pay_state = 0'; break; case 'end': $where .= ' AND order_state >= 0 AND order_pay_state > 0'; break; } $orders = UserOrder::query()->columns('order_id, order_long_id, order_money, order_mobile, order_pay_type, order_pay_state, order_addtime')->where($where, $whereParams)->orderBy('order_id desc')->limit($limit, $offset)->execute()->toArray(); $data = []; foreach ($orders as $order) { $order['order_pay_type'] = $this->getPayTypeStr($order['order_pay_type']); $order['order_pay_state'] = $order['order_pay_state'] > 0 ? 1 : 0; $order['order_addtime'] = date('Y-m-d', strtotime($order['order_addtime'])); $order['goods'] = $this->getGoods($order['order_id']); $data[] = $order; } $this->setResult($data); }
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, '请求异常'); } }
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]); }