BookController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. public function actionLsList()
  26. {
  27. $list = bookPfHd::$list;
  28. util::success(['list' => $list]);
  29. }
  30. //手册详情页 ssh 20211206
  31. public function actionDetail()
  32. {
  33. $id = Yii::$app->request->get('id');
  34. $data = book::$data;
  35. $bookTitleList = book::$list;
  36. //取出title
  37. $titleData = [];
  38. foreach ($bookTitleList as $bookList) {
  39. foreach ($bookList['list'] as $item) {
  40. $currentId = $item['id'] ?? '';
  41. $title = $item['title'] ?? '';
  42. $titleData[$currentId] = $title;
  43. }
  44. }
  45. $currentTitle = $titleData[$id] ?? '';
  46. $info = $data[$id] ?? [];
  47. array_unshift($info, ['style' => 'title', 'value' => $currentTitle]);
  48. //组合出视频完整链接
  49. $apiHost = Yii::$app->params['ghsHost'];
  50. foreach ($info as $key => $val) {
  51. if (isset($val['style']) && $val['style'] == 'video') {
  52. $info[$key]['value'] = $apiHost . '/' . $val['value'];
  53. }
  54. }
  55. util::success(['list' => $info]);
  56. }
  57. //关闭手册 ssh 20211211
  58. public function actionCloseBook()
  59. {
  60. $cacheKey = 'close_book_' . $this->shopAdminId;
  61. Yii::$app->redis->executeCommand('SET', [$cacheKey, 'has']);
  62. util::complete();
  63. }
  64. //变更预订活动 ssh 20240623
  65. public function actionChangeBook()
  66. {
  67. $get = Yii::$app->request->get();
  68. $status = $get['status'] ?? 0;
  69. $shop = $this->shop;
  70. $staff = $this->shopAdmin;
  71. if ($staff->founder != 2 && $staff->mobile != 15280215347) {
  72. //util::fail('这个需要超管才能操作');
  73. }
  74. $pfLevel = $shop->pfLevel ?? 0;
  75. if ($pfLevel == 0) {
  76. util::fail('昆明批发才能使用');
  77. }
  78. $connection = Yii::$app->db;
  79. $transaction = $connection->beginTransaction();
  80. try {
  81. if ($status == 0) {
  82. if ($shop->bookSn == 0) {
  83. util::fail('已经关闭了');
  84. }
  85. $shop->bookSn = 0;
  86. $shop->save();
  87. $transaction->commit();
  88. $bookSn = $shop->bookSn ?? 0;
  89. //删除采购单货位需要更新标记
  90. $cacheKey1 = 'ghs_cg_order_staff_refresh_seat_' . $bookSn;
  91. Yii::$app->redis->executeCommand('DEL', [$cacheKey1]);
  92. $cacheKey2 = 'ghs_cg_order_guest_refresh_seat_' . $bookSn;
  93. Yii::$app->redis->executeCommand('DEL', [$cacheKey2]);
  94. util::success(['bookSn' => 0], '已关闭');
  95. } else {
  96. $orderSn = orderSn::getBookSn();
  97. $data = [
  98. 'orderSn' => $orderSn,
  99. 'shopId' => $this->shopId,
  100. 'mainId' => $this->mainId,
  101. ];
  102. BookClass::add($data, true);
  103. $shop = $this->shop;
  104. $shop->bookSn = $orderSn;
  105. $shop->save();
  106. $transaction->commit();
  107. util::success(['bookSn' => $orderSn], '开启成功');
  108. }
  109. } catch (\Exception $e) {
  110. Yii::info("操作失败原因:" . $e->getMessage());
  111. $transaction->rollBack();
  112. util::fail('操作失败');
  113. }
  114. }
  115. }