| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?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\admin\model\study;
- use traits\ModelTrait;
- use basic\ModelBasic;
- use app\wap\model\special\Special;
- use app\wap\model\special\SpecialBuy;
- use app\wap\model\topic\TestPaperObtain;
- /**
- * Class plan 讲师
- * @package app\admin\model\special
- */
- class PlanBuy extends ModelBasic {
- use ModelTrait;
- /**检查专题是否获得
- * @param $special_id
- * @param $uid
- * @return bool
- * @throws \think\Exception
- */
- public static function PayPlan($id, $uid) {
- //self::where(['uid' => $uid, 'planid' => $id, 'is_del' => 0])->update(['is_del' => 1]);
- return self::where(['uid' => $uid, 'planid' => $id, 'is_del' => 0])->count() ? true : false;
- }
- /**获得专题
- * @param $order_id
- * @param $uid
- * @param $plan_id
- * @param int $type
- * @return bool
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function setAllBuyPlan($order_id, $uid, $plan_id, $type = 0){
- if (!$order_id || !$uid || !$plan_id) return false;
- //如果是专栏,记录专栏下所有专题购买。
- $plan = Plan::where(['id'=>$plan_id])->find();
- $planItem = PlanItems::where('pid', $plan['id'])->select();
- if ($planItem) {
- foreach ($planItem as $k => $v) {
- $task_special = Special::PreWhere()->where(['id'=>$v['cid']])->find();
- if (!$task_special) continue;
- if ($task_special['is_show'] != 1) continue;
- SpecialBuy::setBuySpecial($order_id, $uid, $v['cid'], $type, $task_special['validity'], $plan_id);
- TestPaperObtain::setTestPaper($order_id, $uid, $v['cid'], 2);
- }
- }
- self::setBuyPlan($order_id, $uid, $plan_id, $type);
- }
- public static function setBuyPlan($order_id, $uid, $plan_id, $type){
- $data = [
- 'orderid' => $order_id,
- 'uid' => $uid,
- 'planid' => $plan_id,
- 'type' => $type,
- 'add_time' => time(),
- ];
- self::set($data);
- }
- }
|