success('', ['list' => MemberService::plans()]); } /** * 我的会员状态 */ public function status() { $status = MemberService::status($this->auth->id); $orders = Db::name('member_order') ->where('user_id', $this->auth->id) ->order('id', 'desc') ->limit(10) ->field('order_no,plan_code,amount,pay_status,createtime,start_time,expire_time') ->select(); foreach ($orders as &$order) { $order['amount'] = (float)$order['amount']; $order['create_date'] = $order['createtime'] ? date('Y-m-d H:i', (int)$order['createtime']) : ''; $order['status_text'] = ['unpaid' => '待支付', 'paid' => '已支付', 'refunded' => '已退款'][$order['pay_status']] ?? $order['pay_status']; } $this->success('', ['member' => $status, 'orders' => $orders]); } /** * 创建会员订单 * POST plan_id=2 pay_type=wechat */ public function order() { $userId = $this->auth->id; $planId = (int)$this->request->post('plan_id', 0); $payType = $this->request->post('pay_type', 'wechat'); $plan = Db::name('member_plan')->where('id', $planId)->where('status', 'normal')->find(); if (!$plan) { $this->error('套餐不存在或已下架'); } if (!in_array($payType, ['wechat', 'alipay'])) { $this->error('不支持的支付方式'); } $orderNo = 'HQ' . date('YmdHis') . Random::numeric(4); $now = time(); $id = Db::name('member_order')->insertGetId([ 'order_no' => $orderNo, 'user_id' => $userId, 'plan_id' => (int)$plan['id'], 'plan_code' => $plan['code'], 'amount' => $plan['price'], 'pay_type' => $payType, 'pay_status' => 'unpaid', 'createtime' => $now, 'updatetime' => $now, ]); $this->success('订单已创建', [ 'order_id' => (int)$id, 'order_no' => $orderNo, 'amount' => (float)$plan['price'], 'plan' => [ 'code' => $plan['code'], 'name' => $plan['name'], ], 'pay_type' => $payType, 'pay_hint' => '支付通道(微信/易支付)待接入,可由后台确认订单后开通权益', 'pay_status' => 'unpaid', ]); } }