ComBinPackage.Class.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. namespace JinDouYun\Controller\Market;
  3. use JinDouYun\Controller\BaseController;
  4. use JinDouYun\Model\Market\MComBinPackage;
  5. use Mall\Framework\Core\ErrorCode;
  6. use Mall\Framework\Core\StatusCode;
  7. /**
  8. * @copyright Copyright (c) https://www.qianniaovip.com All rights reserved
  9. * Description:
  10. * Class ComBinPackage
  11. * @package JinDouYun\Controller\Market
  12. */
  13. class ComBinPackage extends BaseController
  14. {
  15. /**
  16. * @var MComBinPackage
  17. */
  18. private $objMComBinPackage;
  19. /**
  20. * ComBinPackage constructor.
  21. * @param bool $isCheckAcl
  22. * @param bool $isMustLogin
  23. * @param bool $checkToken
  24. * @param false $getAreaCode
  25. * @param bool $checkShopToken
  26. * @param bool $checkSupplierToken
  27. * @throws \Exception
  28. */
  29. public function __construct($isCheckAcl = true, $isMustLogin = true, $checkToken = true, $getAreaCode = false, $checkShopToken = true, $checkSupplierToken = true)
  30. {
  31. parent::__construct($isCheckAcl, $isMustLogin, $checkToken, $getAreaCode, $checkShopToken, $checkSupplierToken);
  32. $this->objMComBinPackage = new MComBinPackage($this->onlineEnterpriseId, $this->onlineUserId);
  33. }
  34. /**
  35. * 添加,编辑
  36. * @return array
  37. */
  38. public function commonFieldFilter()
  39. {
  40. $params = $this->request->getRawJson();
  41. if (empty($params)) {
  42. self::sendOutput('参数为空', ErrorCode::$paramError);
  43. }
  44. $data = [
  45. "title" => getArrayItem($params, 'title', ''),
  46. //varchar(30) DEFAULT '' COMMENT '活动名称',
  47. "isExpire" => getArrayItem($params, 'isExpire', StatusCode::$delete),
  48. //tinyint(3) DEFAULT '4' COMMENT '是否具有时间限制 默认5 4不限时间 5限制时间',
  49. "shopId" => getArrayItem($params, 'shopId', 0),
  50. //int(10) NOT NULL DEFAULT '0' COMMENT '商铺id',
  51. "shopName" => getArrayItem($params, 'shopName', ''),
  52. //varchar(30) DEFAULT NULL COMMENT '商铺名称',
  53. "goodsData" => getArrayItem($params, 'goodsData', null),
  54. //json DEFAULT NULL COMMENT '活动商品数据',
  55. "price" => getArrayItem($params, 'price', 0),
  56. //decimal(10,2) DEFAULT '0.00' COMMENT '套餐价格',
  57. "originPrice" => getArrayItem($params, 'originPrice', 0),
  58. //decimal(10,2) DEFAULT '0.00' COMMENT '套餐价格',
  59. "inventory" => getArrayItem($params, 'inventory', 0),
  60. //decimal(10,2) DEFAULT NULL COMMENT '套餐设置库存',
  61. "isLimit" => getArrayItem($params, 'isLimit', StatusCode::$delete),
  62. //tinyint(3) DEFAULT '4' COMMENT '是否开启每人限购 默认4 4不开启 5开启',
  63. "expressType" => getArrayItem($params, 'expressType', StatusCode::$delete),
  64. //tinyint(3) DEFAULT '4' COMMENT '运费设置 默认4 4默认跟随商品 5包邮',
  65. "enableStatus" => getArrayItem($params, 'enableStatus', StatusCode::$delete),
  66. //tinyint(3) DEFAULT '4' COMMENT '是否启用 默认4 4禁用 5启用',
  67. "materielNum" => getArrayItem($params,'materielNum',0),
  68. ];
  69. foreach ($data as $key => $value) {
  70. if (empty($value) && $value !== 0) {
  71. self::sendOutput($key . '参数错误', ErrorCode::$paramError);
  72. }
  73. }
  74. $goodsArr = [];
  75. foreach ($data['goodsData'] as $val){
  76. if (!in_array($val['goodsId'],$goodsArr)){
  77. $goodsArr[] = $val['goodsId'];
  78. }
  79. }
  80. $data['goodsIds'] = implode(',',$goodsArr);//产品ids
  81. $data['goodsData'] = json_encode($data['goodsData'],320);
  82. $data['startTime'] = getArrayItem($params, 'startTime', 0);
  83. $data['endTime'] = getArrayItem($params, 'endTime', 0);
  84. $data['limitNum'] = getArrayItem($params, 'limitNum', 0);
  85. return $data;
  86. }
  87. /**
  88. * Doc: (des="添加组合套餐")
  89. * User: XMing
  90. * Date: 2021/1/21
  91. * Time: 3:47 下午
  92. */
  93. public function add()
  94. {
  95. $data = $this->commonFieldFilter();
  96. $result = $this->objMComBinPackage->add($data);
  97. if ($result->isSuccess()) {
  98. parent::sendOutput($result->getData());
  99. }
  100. parent::sendOutput($result->getData(), $result->getErrorCode());
  101. }
  102. /**
  103. * Doc: (des="")
  104. * User: XMing
  105. * Date: 2021/1/22
  106. * Time: 10:11 上午
  107. */
  108. public function edit()
  109. {
  110. $id = $this->request->param('request_id');
  111. if (empty($id)) {
  112. $this->sendOutput('参数错误', ErrorCode::$paramError);
  113. }
  114. $data = $this->commonFieldFilter();
  115. $result = $this->objMComBinPackage->edit($data,$id);
  116. if ($result->isSuccess()) {
  117. parent::sendOutput($result->getData());
  118. }
  119. parent::sendOutput($result->getData(), $result->getErrorCode());
  120. }
  121. /**
  122. * Doc: (des="")
  123. * User: XMing
  124. * Date: 2021/1/21
  125. * Time: 5:45 下午
  126. */
  127. public function getAll()
  128. {
  129. $params = $this->request->getRawJson();
  130. $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
  131. $params['limit'] = $pageParams['limit'];
  132. $params['offset'] = $pageParams['offset'];
  133. $result = $this->objMComBinPackage->getAll($params);
  134. if ($result->isSuccess()) {
  135. $returnData = $result->getData();
  136. $pageData = [
  137. 'pageIndex' => isset($params['page']) ? $params['page'] : 1,
  138. 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
  139. 'pageTotal' => $returnData['total'],
  140. ];
  141. parent::sendOutput($returnData['data'], 0, $pageData);
  142. }
  143. parent::sendOutput($result->getData(), $result->getErrorCode());
  144. }
  145. /**
  146. * Doc: (des="")
  147. * User: XMing
  148. * Date: 2021/1/21
  149. * Time: 6:39 下午
  150. * @throws \Exception
  151. */
  152. public function get()
  153. {
  154. $id = $this->request->param('request_id');
  155. if (empty($id)) {
  156. $this->sendOutput('参数错误', ErrorCode::$paramError);
  157. }
  158. $result = $this->objMComBinPackage->get($id);
  159. if ($result->isSuccess()) {
  160. parent::sendOutput($result->getData());
  161. }
  162. parent::sendOutput($result->getData(), $result->getErrorCode());
  163. }
  164. /**
  165. * Doc: (des="启用/禁用")
  166. * User: XMing
  167. * Date: 2021/1/21
  168. * Time: 6:40 下午
  169. */
  170. public function enable()
  171. {
  172. $id = $this->request->param('request_id');
  173. if (empty($id)) {
  174. $this->sendOutput('参数错误', ErrorCode::$paramError);
  175. }
  176. $result = $this->objMComBinPackage->enable($id);
  177. if ($result->isSuccess()) {
  178. parent::sendOutput($result->getData());
  179. }
  180. parent::sendOutput($result->getData(), $result->getErrorCode());
  181. }
  182. }