BookController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. $pfLevel = $shop->pfLevel ?? 0;
  69. if ($pfLevel == 0) {
  70. util::fail('昆明批发才能使用');
  71. }
  72. $connection = Yii::$app->db;
  73. $transaction = $connection->beginTransaction();
  74. try {
  75. if ($status == 0) {
  76. if ($shop->bookSn == 0) {
  77. util::fail('已经关闭了');
  78. }
  79. $shop->bookSn = 0;
  80. $shop->save();
  81. $transaction->commit();
  82. $bookSn = $shop->bookSn ?? 0;
  83. //删除采购单货位需要更新标记
  84. $cacheKey1 = 'ghs_cg_order_staff_refresh_seat_' . $bookSn;
  85. Yii::$app->redis->executeCommand('DEL', [$cacheKey1]);
  86. $cacheKey2 = 'ghs_cg_order_guest_refresh_seat_' . $bookSn;
  87. Yii::$app->redis->executeCommand('DEL', [$cacheKey2]);
  88. util::success(['bookSn' => 0], '已关闭');
  89. } else {
  90. $orderSn = orderSn::getBookSn();
  91. $data = [
  92. 'orderSn' => $orderSn,
  93. 'shopId' => $this->shopId,
  94. 'mainId' => $this->mainId,
  95. ];
  96. BookClass::add($data, true);
  97. $shop = $this->shop;
  98. $shop->bookSn = $orderSn;
  99. $shop->save();
  100. $transaction->commit();
  101. util::success(['bookSn' => $orderSn], '开启成功');
  102. }
  103. } catch (\Exception $e) {
  104. Yii::info("操作失败原因:" . $e->getMessage());
  105. $transaction->rollBack();
  106. util::fail('操作失败');
  107. }
  108. }
  109. }