Certificate.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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\controller\questions;
  12. use app\merchant\controller\AuthController;
  13. use service\JsonService as Json;
  14. use service\UploadService as Upload;
  15. use think\Request;
  16. use think\Url;
  17. use service\FormBuilder as Form;
  18. use app\merchant\model\questions\Certificate as CertificateModel;
  19. use app\merchant\model\questions\TestPaper as TestPaperModel;
  20. use app\merchant\model\questions\CertificateRecord;
  21. /**
  22. * 证书
  23. * Class Certificate
  24. */
  25. class Certificate extends AuthController
  26. {
  27. /**
  28. * 证书列表
  29. */
  30. public function index()
  31. {
  32. return $this->fetch();
  33. }
  34. /**
  35. * 获取证书列表
  36. */
  37. public function getCertificateList()
  38. {
  39. $where = parent::getMore([
  40. ['page', 1],
  41. ['limit', 20],
  42. ['obtain', 0],
  43. ['title', ''],
  44. ]);
  45. $where['mer_id'] = $this->merchantId;
  46. return Json::successlayui(CertificateModel::getCertificateList($where));
  47. }
  48. /**
  49. * 快速编辑
  50. * @param string $field 字段名
  51. * @param int $id 修改的主键
  52. * @param string value 修改后的值
  53. * @return json
  54. */
  55. public function set_value($field = '', $id = '', $value = '', $test = 0)
  56. {
  57. if (!$field || !$id || $value == '') Json::fail('缺少参数3');
  58. if ($field == 'sort' && bcsub($value, 0, 0) < 0) return Json::fail('排序不能为负数');
  59. $res = parent::getDataModification('certificate', $id, $field, $value);
  60. if ($res)
  61. return Json::successful('保存成功');
  62. else
  63. return Json::fail('保存失败');
  64. }
  65. /**添加/编辑
  66. * @param int $id
  67. * @return mixed
  68. */
  69. public function add($id = 0)
  70. {
  71. $certificate = $id > 0 ? CertificateModel::get($id) : [];
  72. $this->assign(['id' => $id, 'certificate' => json_encode($certificate)]);
  73. return $this->fetch('create');
  74. }
  75. /**添加/编辑证书
  76. * @param int $id
  77. */
  78. public function save_add($id = 0)
  79. {
  80. $data = parent::postMore([
  81. ['title', ''],
  82. ['background', ''],
  83. ['qr_code', ''],
  84. ['obtain', 0],
  85. ['explain', ''],
  86. ['sort', 0]
  87. ]);
  88. if ($data['title'] == '') return Json::fail('请输入证书标题');
  89. if ($data['background'] == '') return Json::fail('请上传证书背景');
  90. if (mb_strlen($data['explain'], "utf-8") > 30 || mb_strlen($data['explain'], "utf-8") <= 0) return Json::fail('证书说明不能大于30个字或者为空');
  91. if ($id) {
  92. $data['status'] = $this->isAudit == 1 ? 0 : 1;
  93. $res = CertificateModel::edit($data, $id);
  94. } else {
  95. $data['add_time'] = time();
  96. $data['status'] = $this->isAudit == 1 ? 0 : 1;
  97. $data['mer_id'] = $this->merchantId;
  98. if (CertificateModel::be(['title' => $data['title'], 'mer_id' => $this->merchantId, 'is_del' => 0])) {
  99. return Json::fail('证书标题已存在!');
  100. }
  101. $res = CertificateModel::set($data);
  102. }
  103. if ($res) {
  104. return Json::successful('添加/编辑成功');
  105. } else {
  106. return Json::fail('添加/编辑失败');
  107. }
  108. }
  109. /**删除证书
  110. * @param int $id
  111. */
  112. public function delete($id = 0)
  113. {
  114. if (!$id) return Json::fail('参数错误');
  115. $test = CertificateModel::get($id);
  116. if (!$test) return Json::fail('要删除的证书不存在');
  117. $res = parent::getDataModification('certificate', $id, 'is_del', 1);
  118. if ($res) {
  119. return Json::successful('删除成功');
  120. } else {
  121. return Json::fail('删除失败');
  122. }
  123. }
  124. /**
  125. *试卷列表
  126. */
  127. public function getTestPaperList()
  128. {
  129. $where = parent::getMore([
  130. ['page', 1],
  131. ['limit', 20],
  132. ['pid', ''],
  133. ['type', 2],
  134. ['title', '']
  135. ]);
  136. return Json::successlayui(TestPaperModel::testPaperExercisesList($where));
  137. }
  138. /**证书获取记录
  139. * @return mixed
  140. */
  141. public function record()
  142. {
  143. $this->assign(['certificate' => CertificateModel::certificateList($this->merchantId)]);
  144. return $this->fetch();
  145. }
  146. /**
  147. * 证书获取记录列表
  148. */
  149. public function getCertificateRecord()
  150. {
  151. $where = parent::getMore([
  152. ['page', 1],
  153. ['limit', 20],
  154. ['cid', 0],
  155. ['title', ''],
  156. ['excel', 0]
  157. ]);
  158. $where['mer_id'] = $this->merchantId;
  159. return Json::successlayui(CertificateRecord::getCertificateRecordList($where));
  160. }
  161. /**证书获取记录删除
  162. * @param int $id
  163. * @throws \think\exception\DbException
  164. */
  165. public function deleteRecord($id = 0)
  166. {
  167. if (!$id) Json::fail('缺少参数');
  168. $test = CertificateRecord::get($id);
  169. if (!$test) return Json::fail('要删除的记录不存在');
  170. $res = parent::getDataModification('record', $id, 'is_del', 1);
  171. if ($res) {
  172. return Json::successful('删除成功');
  173. } else {
  174. return Json::fail('删除失败');
  175. }
  176. }
  177. /**证书获取记录撤销
  178. * @param int $id
  179. * @throws \think\exception\DbException
  180. */
  181. public function revokeRecord($id = 0)
  182. {
  183. if (!$id) Json::fail('缺少参数');
  184. $test = CertificateRecord::get($id);
  185. if (!$test) return Json::fail('要撤销的记录不存在');
  186. $res = parent::getDataModification('record', $id, 'status', 0);
  187. if ($res) {
  188. return Json::successful('撤销成功');
  189. } else {
  190. return Json::fail('撤销失败');
  191. }
  192. }
  193. }