Certificate.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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\controller\questions;
  12. use app\admin\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\admin\model\questions\Certificate as CertificateModel;
  19. use app\admin\model\questions\TestPaper as TestPaperModel;
  20. use app\admin\model\questions\CertificateRecord;
  21. use app\admin\model\merchant\Merchant;
  22. /**
  23. * 证书
  24. * Class Certificate
  25. */
  26. class Certificate extends AuthController
  27. {
  28. /**
  29. * 证书列表
  30. */
  31. public function index()
  32. {
  33. $mer_list = Merchant::getMerchantList();
  34. $this->assign([
  35. 'mer_list' => $mer_list
  36. ]);
  37. return $this->fetch();
  38. }
  39. /**
  40. * 获取证书列表
  41. */
  42. public function getCertificateList()
  43. {
  44. $where = parent::getMore([
  45. ['page', 1],
  46. ['limit', 20],
  47. ['obtain', 0],
  48. ['title', ''],
  49. ['status', 1],
  50. ['mer_id', 0],
  51. ]);
  52. return Json::successlayui(CertificateModel::getCertificateList($where));
  53. }
  54. /**证书审核
  55. * @return mixed
  56. */
  57. public function examine()
  58. {
  59. $mer_list = Merchant::getMerchantList();
  60. $this->assign([
  61. 'mer_list' => $mer_list
  62. ]);
  63. return $this->fetch();
  64. }
  65. /**获得审核证书
  66. * @throws \think\Exception
  67. */
  68. public function get_certificate_examine_list()
  69. {
  70. $where = parent::getMore([
  71. ['status', ''],
  72. ['page', 1],
  73. ['limit', 20],
  74. ['obtain', 0],
  75. ['mer_id', 0],
  76. ['title', '']
  77. ]);
  78. return Json::successlayui(CertificateModel::get_certificate_examine_list($where));
  79. }
  80. public function examineDetails($id)
  81. {
  82. if (!$id) return Json::fail('参数错误');
  83. $certificate = CertificateModel::get($id);
  84. if (!$certificate) return Json::fail('证书不存在');
  85. $this->assign(['certificate' => json_encode($certificate)]);
  86. return $this->fetch('material');
  87. }
  88. /**不通过
  89. * @param $id
  90. * @throws \think\exception\DbException
  91. */
  92. public function fail($id)
  93. {
  94. $fail_msg = parent::postMore([
  95. ['message', ''],
  96. ]);
  97. if (!CertificateModel::be(['id' => $id, 'status' => 0])) return Json::fail('操作记录不存在或状态错误!');
  98. $certificate = CertificateModel::get($id);
  99. if (!$certificate) return Json::fail('操作记录不存!');
  100. if ($certificate->status != 0) return Json::fail('您已审核,请勿重复操作');
  101. CertificateModel::beginTrans();
  102. $res = CertificateModel::changeFail($id, $certificate['mer_id'], $fail_msg['message']);
  103. if ($res) {
  104. CertificateModel::commitTrans();
  105. return Json::successful('操作成功!');
  106. } else {
  107. CertificateModel::rollbackTrans();
  108. return Json::fail('操作失败!');
  109. }
  110. }
  111. /**通过
  112. * @param $id
  113. * @throws \think\exception\DbException
  114. */
  115. public function succ($id)
  116. {
  117. if (!CertificateModel::be(['id' => $id, 'status' => 0])) return Json::fail('操作记录不存在或状态错误!');
  118. $certificate = CertificateModel::get($id);
  119. if (!$certificate) return Json::fail('操作记录不存!');
  120. if ($certificate->status != 0) return Json::fail('您已审核,请勿重复操作');
  121. CertificateModel::beginTrans();
  122. $res = CertificateModel::changeSuccess($id, $certificate['mer_id']);
  123. if ($res) {
  124. CertificateModel::commitTrans();
  125. return Json::successful('操作成功!');
  126. } else {
  127. CertificateModel::rollbackTrans();
  128. return Json::fail('操作失败!');
  129. }
  130. }
  131. /**
  132. * 快速编辑
  133. * @param string $field 字段名
  134. * @param int $id 修改的主键
  135. * @param string value 修改后的值
  136. * @return json
  137. */
  138. public function set_value($field = '', $id = '', $value = '', $test = 0)
  139. {
  140. if (!$field || !$id || $value == '') Json::fail('缺少参数3');
  141. if ($field == 'sort' && bcsub($value, 0, 0) < 0) return Json::fail('排序不能为负数');
  142. $res = parent::getDataModification('certificate', $id, $field, $value);
  143. if ($res)
  144. return Json::successful('保存成功');
  145. else
  146. return Json::fail('保存失败');
  147. }
  148. /**添加/编辑
  149. * @param int $id
  150. * @return mixed
  151. */
  152. public function add($id = 0)
  153. {
  154. $certificate = $id > 0 ? CertificateModel::get($id) : [];
  155. $this->assign(['id' => $id, 'certificate' => json_encode($certificate)]);
  156. return $this->fetch('create');
  157. }
  158. /**添加/编辑证书
  159. * @param int $id
  160. */
  161. public function save_add($id = 0)
  162. {
  163. $data = parent::postMore([
  164. ['title', ''],
  165. ['background', ''],
  166. ['qr_code', ''],
  167. ['obtain', 0],
  168. ['explain', ''],
  169. ['sort', 0]
  170. ]);
  171. if ($data['title'] == '') return Json::fail('请输入证书标题');
  172. if ($data['background'] == '') return Json::fail('请上传证书背景');
  173. if (mb_strlen($data['explain'], "utf-8") > 30 || mb_strlen($data['explain'], "utf-8") <= 0) return Json::fail('证书说明不能大于30个字或者为空');
  174. if ($id) {
  175. $res = CertificateModel::edit($data, $id);
  176. } else {
  177. $data['add_time'] = time();
  178. if (CertificateModel::be(['title' => $data['title'], 'is_del' => 0])) {
  179. return Json::fail('证书标题已存在!');
  180. }
  181. $res = CertificateModel::set($data);
  182. }
  183. if ($res) {
  184. return Json::successful('添加/编辑成功');
  185. } else {
  186. return Json::fail('添加/编辑失败');
  187. }
  188. }
  189. /**删除证书
  190. * @param int $id
  191. */
  192. public function delete($id = 0)
  193. {
  194. if (!$id) return Json::fail('参数错误');
  195. $test = CertificateModel::get($id);
  196. if (!$test) return Json::fail('要删除的证书不存在');
  197. $res = parent::getDataModification('certificate', $id, 'is_del', 1);
  198. if ($res) {
  199. return Json::successful('删除成功');
  200. } else {
  201. return Json::fail('删除失败');
  202. }
  203. }
  204. /**
  205. *试卷列表
  206. */
  207. public function getTestPaperList()
  208. {
  209. $where = parent::getMore([
  210. ['page', 1],
  211. ['limit', 20],
  212. ['pid', ''],
  213. ['type', 2],
  214. ['title', '']
  215. ]);
  216. return Json::successlayui(TestPaperModel::testPaperExercisesList($where));
  217. }
  218. /**证书获取记录
  219. * @return mixed
  220. */
  221. public function record()
  222. {
  223. $this->assign(['certificate' => CertificateModel::certificateList()]);
  224. return $this->fetch();
  225. }
  226. /**
  227. * 证书获取记录列表
  228. */
  229. public function getCertificateRecord()
  230. {
  231. $where = parent::getMore([
  232. ['page', 1],
  233. ['limit', 20],
  234. ['cid', 0],
  235. ['title', ''],
  236. ['excel', 0]
  237. ]);
  238. return Json::successlayui(CertificateRecord::getCertificateRecordList($where));
  239. }
  240. /**证书获取记录删除
  241. * @param int $id
  242. * @throws \think\exception\DbException
  243. */
  244. public function deleteRecord($id = 0)
  245. {
  246. if (!$id) Json::fail('缺少参数');
  247. $test = CertificateRecord::get($id);
  248. if (!$test) return Json::fail('要删除的记录不存在');
  249. $res = parent::getDataModification('record', $id, 'is_del', 1);
  250. if ($res) {
  251. return Json::successful('删除成功');
  252. } else {
  253. return Json::fail('删除失败');
  254. }
  255. }
  256. /**证书获取记录撤销
  257. * @param int $id
  258. * @throws \think\exception\DbException
  259. */
  260. public function revokeRecord($id = 0)
  261. {
  262. if (!$id) Json::fail('缺少参数');
  263. $test = CertificateRecord::get($id);
  264. if (!$test) return Json::fail('要撤销的记录不存在');
  265. $res = parent::getDataModification('record', $id, 'status', 0);
  266. if ($res) {
  267. return Json::successful('撤销成功');
  268. } else {
  269. return Json::fail('撤销失败');
  270. }
  271. }
  272. }