| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\wap\controller;
- use app\admin\model\study\Plan;
- use app\admin\model\study\PlanSteps;
- use app\admin\model\study\PlanItems;
- use app\wap\model\special\Special as SpecialModel;
- use app\wap\model\store\StoreOrder;
- use service\JsonService;
- use think\Url;
- /**商品控制器
- * Class Store
- * @package app\wap\controller
- */
- class Studyplan extends AuthController{
- /*
- * 白名单
- * */
- public static function WhiteList(){
- return [
- 'index',
- 'detail',
- ];
- }
- public function index($page = 1, $limit = 20, $op = ''){
- if ($op == 'list') {
- $model = Plan::alias('p')->where('p.is_del', 0)->page((int)$page, (int)$limit);
- $model = $model->join('PlanBuy pb', 'pb.uid = ' . $this->uid .' and pb.planid = p.id ', 'left');
- $orderList = $model->order('p.shelf_time DESC')->field('p.*, pb.id as isbuy')->select();
- $orderList = count($orderList) > 0 ? $orderList->toArray() : [];
- return JsonService::successful($orderList);
- }
- //微信支付
- $user_level = !$this->uid ? 0 : $this->userInfo;
- $this->assign('is_member', isset($user_level['level']) ? $user_level['level'] : 0);
- return $this->fetch();
- }
- public function details($id = 0) {
- if (!$id) $this->failed('缺少参数,无法访问', Url::build('index/index'));
- $planinfo = Plan::get($id);
- if (!$planinfo) $this->failed('参数错误,无法访问', Url::build('index/index'));
- $planinfo['introduction'] = htmlspecialchars_decode($planinfo['introduction']);
- $steps = PlanSteps::where('is_del', 0)->where('pid', $id)->select();
- $stepids = [];
- foreach($steps as $v){
- $stepids[] = $v['id'];
- }
- $itemsList = [];
- $join = [
- ['special s', 's.id = it.cid and s.is_del = 0 and s.status = 1']
- ];
- $items = PlanItems::alias('it')->field('s.*, it.stepsid,it.pid')
- ->join($join)
- ->where('pid', $id)
- ->where('stepsid', 'in', $stepids)
- ->select();
- foreach ($items as $v) {
- $v['count'] = SpecialModel::numberChapters($v['type'], $v['id']);
- $itemsList[$v['stepsid']][] = $v->toArray();
- }
- //微信支付相关代码
- $user_level = !$this->uid ? 0 : $this->userInfo;
- $this->assign('is_member', isset($user_level['level']) ? $user_level['level'] : 0);
- $this->assign('steps', json_encode($steps));
- $this->assign('itemsList', json_encode($itemsList));
- $this->assign('planinfo', json_encode($planinfo));
-
- return $this->fetch();
- }
- /**
- * 创建专题支付订单
- * @param int $special_id 专题id
- * @param int $pay_type 购买类型 1=礼物,2=普通购买,3=开团或者拼团
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function create_order($special_id, $pay_type_num, $payType, $pinkId = 0, $total_num = 1, $link_pay_uid = 0, $from = 'weixin')
- {
- if (!$special_id) return JsonService::fail('缺少购买参数');
- if ($pay_type_num == -1) return JsonService::fail('选择购买方式');
-
- $Plan = Plan::where('is_del', 0)->where('is_show', 1)->find($special_id);
- if (!$Plan) return JsonService::status('ORDER_ERROR', '购买的学习计划不存在');
- $order = StoreOrder::createPlanOrder($Plan, $pinkId, $pay_type_num, $this->uid, $payType, $link_pay_uid, $total_num);
- $orderId = $order['order_id'];
- $info = compact('orderId');
- if ($orderId) {
- $orderInfo = StoreOrder::where('order_id', $orderId)->find();
- if (!$orderInfo || !isset($orderInfo['paid'])) return JsonService::status('pay_error', '支付订单不存在!');
- if ($orderInfo['paid']) return JsonService::status('pay_error', '支付已支付!');
- if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
- if (StoreOrder::jsPayPlanPrice($orderId, $this->uid))
- return JsonService::status('success', '支付成功', $info);
- else
- return JsonService::status('pay_error', StoreOrder::getErrorInfo());
- } else {
- switch ($payType) {
- case 'weixin':
- try {
- if ($from == 'weixinh5') {
- $jsConfig = StoreOrder::h5PlanPay($orderId);
- } else {
- $jsConfig = StoreOrder::jsPlanPay($orderId);
- }
- } catch (\Exception $e) {
- return JsonService::status('pay_error', $e->getMessage(), $info);
- }
- $info['jsConfig'] = $jsConfig;
- if ($from == 'weixinh5') {
- return JsonService::status('wechat_h5_pay', '订单创建成功', $info);
- } else {
- return JsonService::status('wechat_pay', '订单创建成功', $info);
- }
- break;
- case 'yue':
- if (StoreOrder::yuePlanPay($orderId, $this->uid))
- return JsonService::status('success', '余额支付成功', $info);
- else
- return JsonService::status('pay_error', StoreOrder::getErrorInfo());
- break;
- case 'zhifubao':
- $info['pay_price'] = $orderInfo['pay_price'];
- $info['orderName'] = '购买学习计划';
- return JsonService::status('zhifubao_pay', '订单创建成功', base64_encode(json_encode($info)));
- break;
- }
- }
- } else {
- return JsonService::fail(StoreOrder::getErrorInfo('订单生成失败!'));
- }
- }
- }
|