BookController.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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\bookPfHd;
  7. use common\components\orderSn;
  8. use common\components\util;
  9. use Yii;
  10. class BookController extends BaseController
  11. {
  12. public $guestAccess = ['list', 'detail', 'jd-list'];
  13. //教程列表 ssh 20211206
  14. public function actionList()
  15. {
  16. $list = book::$list;
  17. util::success(['list' => $list]);
  18. }
  19. //基地教学视频 ssh 20231203
  20. public function actionJdList()
  21. {
  22. $list = bookJd::$list;
  23. util::success(['list' => $list]);
  24. }
  25. //手册详情页 ssh 20211206
  26. public function actionDetail()
  27. {
  28. $id = Yii::$app->request->get('id');
  29. $data = book::$data;
  30. $bookTitleList = book::$list;
  31. //取出title
  32. $titleData = [];
  33. foreach ($bookTitleList as $bookList) {
  34. foreach ($bookList['list'] as $item) {
  35. $currentId = $item['id'] ?? '';
  36. $title = $item['title'] ?? '';
  37. $titleData[$currentId] = $title;
  38. }
  39. }
  40. $currentTitle = $titleData[$id] ?? '';
  41. $info = $data[$id] ?? [];
  42. array_unshift($info, ['style' => 'title', 'value' => $currentTitle]);
  43. //组合出视频完整链接
  44. $apiHost = Yii::$app->params['ghsHost'];
  45. foreach ($info as $key => $val) {
  46. if (isset($val['style']) && $val['style'] == 'video') {
  47. $info[$key]['value'] = $apiHost . '/' . $val['value'];
  48. }
  49. }
  50. util::success(['list' => $info]);
  51. }
  52. //关闭手册 ssh 20211211
  53. public function actionCloseBook()
  54. {
  55. $cacheKey = 'close_book_' . $this->shopAdminId;
  56. Yii::$app->redis->executeCommand('SET', [$cacheKey, 'has']);
  57. util::complete();
  58. }
  59. //变更预订活动 ssh 20240623
  60. public function actionChangeBook()
  61. {
  62. $get = Yii::$app->request->get();
  63. $status = $get['status'] ?? 0;
  64. $shop = $this->shop;
  65. $staff = $this->shopAdmin;
  66. if ($staff->founder != 2 && $staff->mobile != 15280215347) {
  67. //util::fail('这个需要超管才能操作');
  68. }
  69. $pfLevel = $shop->pfLevel ?? 0;
  70. if ($pfLevel == 0) {
  71. util::fail('昆明批发才能使用');
  72. }
  73. $connection = Yii::$app->db;
  74. $transaction = $connection->beginTransaction();
  75. try {
  76. if ($status == 0) {
  77. if ($shop->bookSn == 0) {
  78. util::fail('已经关闭了');
  79. }
  80. $shop->bookSn = 0;
  81. $shop->save();
  82. $transaction->commit();
  83. $bookSn = $shop->bookSn ?? 0;
  84. //删除采购单货位需要更新标记
  85. $cacheKey1 = 'ghs_cg_order_staff_refresh_seat_' . $bookSn;
  86. Yii::$app->redis->executeCommand('DEL', [$cacheKey1]);
  87. $cacheKey2 = 'ghs_cg_order_guest_refresh_seat_' . $bookSn;
  88. Yii::$app->redis->executeCommand('DEL', [$cacheKey2]);
  89. util::success(['bookSn' => 0], '已关闭');
  90. } else {
  91. $orderSn = orderSn::getBookSn();
  92. $data = [
  93. 'orderSn' => $orderSn,
  94. 'shopId' => $this->shopId,
  95. 'mainId' => $this->mainId,
  96. ];
  97. BookClass::add($data, true);
  98. $shop = $this->shop;
  99. $shop->bookSn = $orderSn;
  100. $shop->save();
  101. $transaction->commit();
  102. util::success(['bookSn' => $orderSn], '开启成功');
  103. }
  104. } catch (\Exception $e) {
  105. Yii::info("操作失败原因:" . $e->getMessage());
  106. $transaction->rollBack();
  107. util::fail('操作失败');
  108. }
  109. }
  110. public function actionLsList()
  111. {
  112. $list = bookPfHd::$list;
  113. util::success(['list' => $list]);
  114. }
  115. //手册详情页 ssh 20211206
  116. public function actionLsDetail()
  117. {
  118. $id = Yii::$app->request->get('id');
  119. $data = bookPfHd::$data;
  120. $bookTitleList = bookPfHd::$list;
  121. //取出title
  122. $titleData = [];
  123. foreach ($bookTitleList as $bookList) {
  124. foreach ($bookList['list'] as $item) {
  125. $currentId = $item['id'] ?? '';
  126. $title = $item['title'] ?? '';
  127. $titleData[$currentId] = $title;
  128. }
  129. }
  130. $currentTitle = $titleData[$id] ?? '';
  131. $info = $data[$id] ?? [];
  132. array_unshift($info, ['style' => 'title', 'value' => $currentTitle]);
  133. //组合出视频完整链接
  134. $apiHost = Yii::$app->params['ghsHost'];
  135. foreach ($info as $key => $val) {
  136. if (isset($val['style']) && $val['style'] == 'video') {
  137. $info[$key]['value'] = $apiHost . '/' . $val['value'];
  138. }
  139. }
  140. util::success(['list' => $info]);
  141. }
  142. }