DataDownloadBuy.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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\wap\model\material;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. use app\wap\model\special\Special;
  15. use app\wap\model\special\SpecialSource;
  16. use app\wap\model\topic\Relation;
  17. use app\wap\model\material\DataDownload;
  18. use app\wap\model\material\DataDownloadOrder;
  19. /**
  20. * 获得资料 Model
  21. */
  22. class DataDownloadBuy extends ModelBasic
  23. {
  24. use ModelTrait;
  25. /** 用户获得资料
  26. * @param $order_id
  27. * @param $data_id
  28. * @param $uid
  29. * @param $type
  30. * @return bool|object
  31. */
  32. public static function setUserDataDownload($order_id, $data_id, $uid, $type)
  33. {
  34. $add_time = time();
  35. if (self::be(['uid' => $uid, 'data_id' => $data_id, 'type' => $type, 'is_del' => 0])) return false;
  36. return self::set(compact('order_id', 'data_id', 'uid', 'type', 'add_time'));
  37. }
  38. /**判断是否获得资料
  39. * @param $test_id
  40. * @param $uid
  41. * @param $type
  42. * @return bool
  43. * @throws \think\Exception
  44. */
  45. public static function PayDataDownload($data_id, $uid)
  46. {
  47. return self::where(['uid' => $uid, 'data_id' => $data_id, 'is_del' => 0])->count() ? true : false;
  48. }
  49. /**购买专题获得资料
  50. * @param $order_id
  51. * @param $uid
  52. * @param $special_id
  53. * @return bool
  54. * @throws \think\db\exception\DataNotFoundException
  55. * @throws \think\db\exception\ModelNotFoundException
  56. * @throws \think\exception\DbException
  57. */
  58. public static function setDataDownload($order_id, $uid, $special_id, $type = 0)
  59. {
  60. if (!$uid || !$special_id) return false;
  61. $special = Special::PreWhere()->where(['id'=>$special_id])->find();
  62. if ($special['type'] == SPECIAL_COLUMN) {
  63. $special_source = SpecialSource::getSpecialSource($special['id']);
  64. if (!$special_source) return false;
  65. foreach ($special_source as $k => $v) {
  66. $task_special = Special::PreWhere()->where(['id'=>$v['source_id']])->find();
  67. if (!$task_special) continue;
  68. if ($task_special['is_show'] != 1) continue;
  69. $data_ids = Relation::setWhere(4, $task_special['id'])->column('relation_id');
  70. if (count($data_ids) <= 0) continue;
  71. foreach ($data_ids as $ks => $value) {
  72. self::setUserDataDownload($order_id, $value, $uid, $type);
  73. }
  74. }
  75. } else {
  76. $data_ids = Relation::setWhere(4, $special_id)->column('relation_id');
  77. if (count($data_ids) <= 0) return false;
  78. foreach ($data_ids as $kf => $value) {
  79. self::setUserDataDownload($order_id, $value, $uid, $type);
  80. }
  81. }
  82. }
  83. /**获取用户的资料
  84. * @param $type
  85. * @param $uid
  86. */
  87. public static function getUserDataDownload($uid, $page, $limit)
  88. {
  89. $list = self::alias('b')->join('DataDownload d', 'b.data_id=d.id')
  90. ->where(['b.uid' => $uid, 'b.is_del' => 0, 'd.is_del' => 0, 'd.is_show' => 1])
  91. ->group('b.data_id')
  92. ->field('d.id,b.uid,b.data_id,b.type,b.add_time,d.title,d.image,d.money,d.pay_type,d.sales,d.ficti')
  93. ->page((int)$page, (int)$limit)->order('b.add_time DESC')
  94. ->select();
  95. $list = count($list) > 0 ? $list->toArray() : [];
  96. return $list;
  97. }
  98. }