DataDownloadBuy.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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\merchant\model\download;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. use app\merchant\model\system\Relation;
  15. use app\merchant\model\download\DataDownload;
  16. use app\merchant\model\order\DataDownloadOrder;
  17. use app\merchant\model\special\Special;
  18. use app\merchant\model\special\SpecialSource;
  19. /**
  20. * 获得资料 Model
  21. */
  22. class DataDownloadBuy extends ModelBasic
  23. {
  24. use ModelTrait;
  25. /**购买专题获得资料
  26. * @param $order_id
  27. * @param $uid
  28. * @param $special_id
  29. * @return bool
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. * @throws \think\exception\DbException
  33. */
  34. public static function setDataDownload($order_id, $uid, $special_id, $type = 0)
  35. {
  36. if (!$uid || !$special_id) return false;
  37. $special = Special::PreWhere()->where(['id'=>$special_id])->find();
  38. if ($special['type'] == 5) {
  39. $special_source = SpecialSource::getSpecialSource($special['id']);
  40. if (!$special_source) return false;
  41. foreach ($special_source as $k => $v) {
  42. $task_special = Special::PreWhere()->where(['id'=>$v['source_id']])->find();
  43. if (!$task_special) continue;
  44. if ($task_special['is_show'] != 1) continue;
  45. $data_ids = Relation::setWhere(4, $task_special['id'])->column('relation_id');
  46. if (count($data_ids) <= 0) continue;
  47. foreach ($data_ids as $ks => $value) {
  48. self::setUserDataDownload($order_id, $value, $uid, $type);
  49. }
  50. }
  51. } else {
  52. $data_ids = Relation::setWhere(4, $special_id)->column('relation_id');
  53. if (count($data_ids) <= 0) return false;
  54. foreach ($data_ids as $kf => $value) {
  55. self::setUserDataDownload($order_id, $value, $uid, $type);
  56. }
  57. }
  58. }
  59. /** 用户获得资料
  60. * @param $order_id
  61. * @param $data_id
  62. * @param $uid
  63. * @param $type
  64. * @return bool|object
  65. */
  66. public static function setUserDataDownload($order_id, $data_id, $uid, $type)
  67. {
  68. $add_time = time();
  69. if (self::be(['uid' => $uid, 'data_id' => $data_id, 'type' => $type, 'is_del' => 0])) return false;
  70. return self::set(compact('order_id', 'data_id', 'uid', 'type', 'add_time'));
  71. }
  72. /**删除专题时清除资料
  73. * @param $order_id
  74. * @param $uid
  75. * @param $special_id
  76. * @return bool
  77. * @throws \think\db\exception\DataNotFoundException
  78. * @throws \think\db\exception\ModelNotFoundException
  79. * @throws \think\exception\DbException
  80. */
  81. public static function delDataDownload($order_id, $uid, $special_id, $type)
  82. {
  83. if (!$uid || !$special_id) return false;
  84. $special = Special::PreWhere()->where(['id'=>$special_id])->find();
  85. if ($special['type'] == SPECIAL_COLUMN) {
  86. $special_source = SpecialSource::getSpecialSource($special['id']);
  87. if (!$special_source) return false;
  88. foreach ($special_source as $k => $v) {
  89. $task_special = Special::PreWhere()->where(['id'=>$v['source_id']])->find();
  90. if (!$task_special) continue;
  91. if ($task_special['is_show'] != 1) continue;
  92. $data_ids = Relation::setWhere(4, $task_special['id'])->column('relation_id');
  93. if (count($data_ids) <= 0) continue;
  94. foreach ($data_ids as $ks => $value) {
  95. self::delUserDataDownload($order_id, $value, $uid, $type);
  96. }
  97. }
  98. } else {
  99. $data_ids = Relation::setWhere(4, $special_id)->column('relation_id');
  100. if (count($data_ids) <= 0) return false;
  101. foreach ($data_ids as $kf => $value) {
  102. self::delUserDataDownload($order_id, $value, $uid, $type);
  103. }
  104. }
  105. }
  106. /** 清除资料
  107. * @param $order_id
  108. * @param $data_id
  109. * @param $uid
  110. * @param $type
  111. * @return bool|object
  112. */
  113. public static function delUserDataDownload($order_id, $data_id, $uid, $type)
  114. {
  115. if (!self::be(['order_id' => $order_id, 'uid' => $uid, 'data_id' => $data_id, 'type' => $type, 'is_del' => 0])) return false;
  116. return self::where(['order_id' => $order_id, 'uid' => $uid, 'data_id' => $data_id, 'type' => $type, 'is_del' => 0])->update(['is_del' => 1]);
  117. }
  118. }