BookController.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\book\classes\BookClass;
  4. use common\components\book;
  5. use common\components\bookJd;
  6. use common\components\orderSn;
  7. use common\components\util;
  8. use Yii;
  9. class BookController extends BaseController
  10. {
  11. public $guestAccess = ['list', 'detail', 'jd-list'];
  12. //教程列表 ssh 20211206
  13. public function actionList()
  14. {
  15. $list = book::$list;
  16. util::success(['list' => $list]);
  17. }
  18. //基地教学视频 ssh 20231203
  19. public function actionJdList()
  20. {
  21. $list = bookJd::$list;
  22. util::success(['list' => $list]);
  23. }
  24. //手册详情页 ssh 20211206
  25. public function actionDetail()
  26. {
  27. $id = Yii::$app->request->get('id');
  28. $data = book::$data;
  29. $bookTitleList = book::$list;
  30. //取出title
  31. $titleData = [];
  32. foreach ($bookTitleList as $bookList) {
  33. foreach ($bookList['list'] as $item) {
  34. $currentId = $item['id'] ?? '';
  35. $title = $item['title'] ?? '';
  36. $titleData[$currentId] = $title;
  37. }
  38. }
  39. $currentTitle = $titleData[$id] ?? '';
  40. $info = $data[$id] ?? [];
  41. array_unshift($info, ['style' => 'title', 'value' => $currentTitle]);
  42. //组合出视频完整链接
  43. $apiHost = Yii::$app->params['ghsHost'];
  44. foreach ($info as $key => $val) {
  45. if (isset($val['style']) && $val['style'] == 'video') {
  46. $info[$key]['value'] = $apiHost . '/' . $val['value'];
  47. }
  48. }
  49. util::success(['list' => $info]);
  50. }
  51. //关闭手册 ssh 20211211
  52. public function actionCloseBook()
  53. {
  54. $cacheKey = 'close_book_' . $this->shopAdminId;
  55. Yii::$app->redis->executeCommand('SET', [$cacheKey, 'has']);
  56. util::complete();
  57. }
  58. //开启预订活动 ssh 20240609
  59. public function actionOpenBook()
  60. {
  61. $connection = Yii::$app->db;
  62. $transaction = $connection->beginTransaction();
  63. try {
  64. $orderSn = orderSn::getBookSn();
  65. $data = [
  66. 'orderSn' => $orderSn,
  67. 'shopId' => $this->shopId,
  68. 'mainId' => $this->mainId,
  69. ];
  70. $repond = BookClass::add($data, true);
  71. $shop = $this->shop;
  72. $shop->bookSn = $orderSn;
  73. $shop->save();
  74. $transaction->commit();
  75. util::complete('开启成功');
  76. } catch (\Exception $e) {
  77. Yii::info("开启失败原因:" . $e->getMessage());
  78. $transaction->rollBack();
  79. util::fail('开启失败');
  80. }
  81. }
  82. }