PlanBuy.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\model\study;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. use app\wap\model\special\Special;
  15. use app\wap\model\special\SpecialBuy;
  16. use app\wap\model\topic\TestPaperObtain;
  17. /**
  18. * Class plan 讲师
  19. * @package app\admin\model\special
  20. */
  21. class PlanBuy extends ModelBasic {
  22. use ModelTrait;
  23. /**检查专题是否获得
  24. * @param $special_id
  25. * @param $uid
  26. * @return bool
  27. * @throws \think\Exception
  28. */
  29. public static function PayPlan($id, $uid) {
  30. //self::where(['uid' => $uid, 'planid' => $id, 'is_del' => 0])->update(['is_del' => 1]);
  31. return self::where(['uid' => $uid, 'planid' => $id, 'is_del' => 0])->count() ? true : false;
  32. }
  33. /**获得专题
  34. * @param $order_id
  35. * @param $uid
  36. * @param $plan_id
  37. * @param int $type
  38. * @return bool
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\ModelNotFoundException
  41. * @throws \think\exception\DbException
  42. */
  43. public static function setAllBuyPlan($order_id, $uid, $plan_id, $type = 0){
  44. if (!$order_id || !$uid || !$plan_id) return false;
  45. //如果是专栏,记录专栏下所有专题购买。
  46. $plan = Plan::where(['id'=>$plan_id])->find();
  47. $planItem = PlanItems::where('pid', $plan['id'])->select();
  48. if ($planItem) {
  49. foreach ($planItem as $k => $v) {
  50. $task_special = Special::PreWhere()->where(['id'=>$v['cid']])->find();
  51. if (!$task_special) continue;
  52. if ($task_special['is_show'] != 1) continue;
  53. SpecialBuy::setBuySpecial($order_id, $uid, $v['cid'], $type, $task_special['validity'], $plan_id);
  54. TestPaperObtain::setTestPaper($order_id, $uid, $v['cid'], 2);
  55. }
  56. }
  57. self::setBuyPlan($order_id, $uid, $plan_id, $type);
  58. }
  59. public static function setBuyPlan($order_id, $uid, $plan_id, $type){
  60. $data = [
  61. 'orderid' => $order_id,
  62. 'uid' => $uid,
  63. 'planid' => $plan_id,
  64. 'type' => $type,
  65. 'add_time' => time(),
  66. ];
  67. self::set($data);
  68. }
  69. }