CpController.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\cp\classes\PtCpClass;
  4. use bizGhs\cp\classes\CpClass;
  5. use bizGhs\cp\classes\CpClassClass;
  6. use bizGhs\cp\services\CpService;
  7. use common\components\imgUtil;
  8. use common\components\stringUtil;
  9. use common\components\util;
  10. use Yii;
  11. class CpController extends BaseController
  12. {
  13. //采用平台花材 ssh 20240226
  14. public function actionAddPtCp()
  15. {
  16. util::fail('开发中');
  17. $get = Yii::$app->request->get();
  18. $ptCpId = $get['id'] ?? 0;
  19. $ptCp = PtCpClass::getById($ptCpId, true);
  20. if (empty($ptCp)) {
  21. util::fail('没有找到产品');
  22. }
  23. $cp = CpService::addPtCp($ptCp, $this->shop);
  24. util::success(['cp' => $cp]);
  25. }
  26. //根据分类id取集合,带分页 ssh 20231228
  27. public function actionList()
  28. {
  29. $get = Yii::$app->request->get();
  30. $classId = $get['classId'] ?? 0;
  31. $search = $get['search'] ?? '';
  32. $mainId = $this->mainId ?? 0;
  33. $where = [];
  34. $requestType = $get['requestType'] ?? 'cp';
  35. $where['mainId'] = $mainId;
  36. if ($requestType == 'cp') {
  37. $where['delStatus'] = 0;
  38. }
  39. if ($requestType == 'del') {
  40. $where['delStatus'] = 1;
  41. }
  42. if (!empty($search)) {
  43. if (stringUtil::isLetter($search)) {
  44. $where['py'] = ['like', $search];
  45. } else {
  46. $where['name'] = ['like', $search];
  47. }
  48. } else {
  49. if (!empty($classId)) {
  50. $where['classId'] = $classId;
  51. }
  52. }
  53. $respond = CpClass::getCpList($where);
  54. util::success($respond);
  55. }
  56. //添加产品 ssh 20240106
  57. public function actionAddCp()
  58. {
  59. util::fail('开发中');
  60. $post = Yii::$app->request->post();
  61. $post['mainId'] = $this->mainId;
  62. $post['adminId'] = $this->adminId;
  63. if (isset($post['name']) == false || empty($post['name'])) {
  64. util::fail('请填写名称');
  65. }
  66. $post['py'] = stringUtil::py($post['name']);
  67. $staff = $this->shopAdmin;
  68. $staffName = $staff->name ?? '';
  69. $post['staffName'] = $staffName;
  70. $shop = $this->shop;
  71. unset($post['id']);
  72. $connection = Yii::$app->db;
  73. $transaction = $connection->beginTransaction();
  74. try {
  75. CpClass::addCp($post, $shop);
  76. $transaction->commit();
  77. util::complete('添加成功');
  78. } catch (\Exception $e) {
  79. $transaction->rollBack();
  80. util::fail('添加没有成功');
  81. }
  82. }
  83. public function actionUpdateCp()
  84. {
  85. $post = Yii::$app->request->post();
  86. $id = $post['id'] ?? 0;
  87. $cp = CpClass::getById($id, true);
  88. if (empty($cp)) {
  89. util::fail('没有找到产品');
  90. }
  91. if ($cp->mainId != $this->mainId) {
  92. util::fail('不是你的产品');
  93. }
  94. $connection = Yii::$app->db;
  95. $transaction = $connection->beginTransaction();
  96. try {
  97. unset($post['id']);
  98. CpClass::updateCp($post, $cp, $this->shop);
  99. $transaction->commit();
  100. util::complete();
  101. } catch (\Exception $e) {
  102. $transaction->rollBack();
  103. util::fail('添加没有成功');
  104. }
  105. }
  106. public function actionRecoverCp()
  107. {
  108. $masterShop = $this->shop;
  109. if (isset($masterShop->default) == false || $masterShop->default == 0) {
  110. util::fail('请在总店操作');
  111. }
  112. $get = Yii::$app->request->get();
  113. $id = $get['id'] ?? 0;
  114. $cp = CpClass::getById($id, true);
  115. if (isset($cp->mainId) == false || $cp->mainId != $this->mainId) {
  116. util::fail('无法查看');
  117. }
  118. $connection = Yii::$app->db;
  119. $transaction = $connection->beginTransaction();
  120. try {
  121. CpClass::recoverCp($cp, $this->shop);
  122. $transaction->commit();
  123. util::complete();
  124. } catch (\Exception $e) {
  125. $transaction->rollBack();
  126. Yii::info("删除失败原因:" . $e->getMessage());
  127. util::fail('删除失败');
  128. }
  129. }
  130. public function actionDelCp()
  131. {
  132. $masterShop = $this->shop;
  133. if (isset($masterShop->default) == false || $masterShop->default == 0) {
  134. util::fail('请在总店操作');
  135. }
  136. $get = Yii::$app->request->get();
  137. $id = $get['id'] ?? 0;
  138. $cp = CpClass::getById($id, true);
  139. if (isset($cp->mainId) == false || $cp->mainId != $this->mainId) {
  140. util::fail('无法查看');
  141. }
  142. $connection = Yii::$app->db;
  143. $transaction = $connection->beginTransaction();
  144. try {
  145. CpClass::delCp($cp, $this->shop);
  146. $transaction->commit();
  147. util::complete();
  148. } catch (\Exception $e) {
  149. $transaction->rollBack();
  150. Yii::info("删除失败原因:" . $e->getMessage());
  151. util::fail('删除失败');
  152. }
  153. }
  154. //查看详情 ssh 20240219
  155. public function actionDetail()
  156. {
  157. $get = Yii::$app->request->get();
  158. $id = $get['id'] ?? 0;
  159. $cp = CpClass::getById($id);
  160. if (isset($cp['mainId']) == false || $cp['mainId'] != $this->mainId) {
  161. util::fail('无法查看');
  162. }
  163. $classId = $cp['classId'] ?? 0;
  164. $class = CpClassClass::getById($classId, true);
  165. $className = $class->name ?? '';
  166. $shortCover = $cp['cover'] ?? '';
  167. $smallCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  168. $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  169. $cp['shortCover'] = $shortCover;
  170. $cp['cover'] = $bigCover;
  171. $cp['smallCover'] = $smallCover;
  172. $cp['bigCover'] = $bigCover;
  173. $cp['className'] = $className;
  174. util::success($cp);
  175. }
  176. }