BookController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 20240623
  59. public function actionChangeBook()
  60. {
  61. $get = Yii::$app->request->get();
  62. $status = $get['status'] ?? 0;
  63. $shop = $this->shop;
  64. $staff = $this->shopAdmin;
  65. if($staff->founder!=2 && $staff->mobile!=15280215347){
  66. util::fail('这个需要超管才能操作');
  67. }
  68. $connection = Yii::$app->db;
  69. $transaction = $connection->beginTransaction();
  70. try {
  71. if ($status == 0) {
  72. if ($shop->bookSn == 0) {
  73. util::fail('已经关闭了');
  74. }
  75. $shop->bookSn = 0;
  76. $shop->save();
  77. $transaction->commit();
  78. $bookSn = $shop->bookSn ?? 0;
  79. //删除采购单货位需要更新标记
  80. $cacheKey1 = 'ghs_cg_order_staff_refresh_seat_' . $bookSn;
  81. Yii::$app->redis->executeCommand('DEL', [$cacheKey1]);
  82. $cacheKey2 = 'ghs_cg_order_guest_refresh_seat_' . $bookSn;
  83. Yii::$app->redis->executeCommand('DEL', [$cacheKey2]);
  84. util::success(['bookSn' => 0], '已关闭');
  85. } else {
  86. $orderSn = orderSn::getBookSn();
  87. $data = [
  88. 'orderSn' => $orderSn,
  89. 'shopId' => $this->shopId,
  90. 'mainId' => $this->mainId,
  91. ];
  92. BookClass::add($data, true);
  93. $shop = $this->shop;
  94. $shop->bookSn = $orderSn;
  95. $shop->save();
  96. $transaction->commit();
  97. util::success(['bookSn' => $orderSn], '开启成功');
  98. }
  99. } catch (\Exception $e) {
  100. Yii::info("操作失败原因:" . $e->getMessage());
  101. $transaction->rollBack();
  102. util::fail('操作失败');
  103. }
  104. }
  105. }