Material.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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\controller;
  12. use service\JsonService;
  13. use service\SystemConfigService;
  14. use think\Url;
  15. use app\wap\model\user\User;
  16. use app\wap\model\material\DataDownloadCategpry;
  17. use app\wap\model\material\DataDownload;
  18. use app\wap\model\material\DataDownloadBuy;
  19. use app\wap\model\material\DataDownloadRecords;
  20. use service\UtilService;
  21. use app\wap\model\special\SpecialRelation;
  22. /**资料控制器
  23. * Class Material
  24. * @package app\wap\controller
  25. */
  26. class Material extends AuthController
  27. {
  28. /**
  29. * 白名单
  30. * */
  31. public static function WhiteList()
  32. {
  33. return [
  34. 'material_list',
  35. 'get_material_cate',
  36. 'get_material_list'
  37. ];
  38. }
  39. /**资料列表
  40. * @param int $pid
  41. * @param int $cate_id
  42. * @return mixed
  43. */
  44. public function material_list($pid = 0, $cate_id = 0)
  45. {
  46. $this->assign([
  47. 'homeLogo' => SystemConfigService::get('home_logo'),
  48. 'pid' => (int)$pid,
  49. 'cate_id' => (int)$cate_id
  50. ]);
  51. return $this->fetch();
  52. }
  53. /**我的资料
  54. * @return mixed
  55. */
  56. public function my_material()
  57. {
  58. return $this->fetch();
  59. }
  60. /**
  61. * 资料分类
  62. */
  63. public function get_material_cate()
  64. {
  65. $cateogry = DataDownloadCategpry::with('children')->where(['is_show' => 1, 'is_del' => 0])->order('sort desc,id desc')->where('pid', 0)->select();
  66. return JsonService::successful($cateogry->toArray());
  67. }
  68. /**
  69. * 资料列表
  70. */
  71. public function get_material_list()
  72. {
  73. list($page, $limit, $pid, $cate_id, $search) = UtilService::PostMore([
  74. ['page', 1],
  75. ['limit', 10],
  76. ['pid', 0],
  77. ['cate_id', 0],
  78. ['search', '']
  79. ], $this->request, true);
  80. return JsonService::successful(DataDownload::getDataDownloadExercisesList($page, $limit, $pid, $cate_id, $search));
  81. }
  82. /**
  83. * 我的资料
  84. */
  85. public function my_material_list()
  86. {
  87. list($page, $limit) = UtilService::PostMore([
  88. ['page', 1],
  89. ['limit', 10]
  90. ], $this->request, true);
  91. return JsonService::successful(DataDownloadBuy::getUserDataDownload($this->uid, $page, $limit));
  92. }
  93. /**
  94. * 资料收藏
  95. * @param $id int 资料id
  96. * @return json
  97. */
  98. public function collect($id = 0)
  99. {
  100. if (!$id) return JsonService::fail('缺少参数');
  101. if (SpecialRelation::SetCollect($this->uid, $id, 1))
  102. return JsonService::successful('成功');
  103. else
  104. return JsonService::fail('失败');
  105. }
  106. /**用户下载记录
  107. * @param $id
  108. * @throws \think\db\exception\DataNotFoundException
  109. * @throws \think\db\exception\ModelNotFoundException
  110. * @throws \think\exception\DbException
  111. */
  112. public function userDownload($id)
  113. {
  114. if (!$id) return JsonService::fail('缺少参数');
  115. $res = DataDownloadRecords::addDataDownloadRecords($id, $this->uid);
  116. if ($res) {
  117. DataDownload::where('id', $id)->setInc('sales');
  118. return JsonService::successful('');
  119. } else
  120. return JsonService::fail();
  121. }
  122. }