Giftcard.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\giftcard\shop\controller;
  11. use addon\giftcard\model\giftcard\Category as CategoryModel;
  12. use addon\giftcard\model\giftcard\GiftCard as GiftCardModel;
  13. use addon\giftcard\model\giftcard\Media as MediaModel;
  14. use app\shop\controller\BaseShop;
  15. use addon\giftcard\model\card\Card;
  16. use addon\giftcard\model\giftcard\Category as GiftCardCategoryModel;
  17. /**
  18. * 礼品卡控制器
  19. */
  20. class Giftcard extends BaseShop
  21. {
  22. public function __construct()
  23. {
  24. parent::__construct();
  25. if (!request()->isAjax()) {
  26. $this->forthMenu();
  27. }
  28. $this->replace = [
  29. 'GIFTCARD_CSS' => __ROOT__ . '/addon/giftcard/shop/view/public/css',
  30. 'GIFTCARD_JS' => __ROOT__ . '/addon/giftcard/shop/view/public/js',
  31. 'GIFTCARD_IMG' => __ROOT__ . '/addon/giftcard/shop/view/public/img',
  32. 'GIFTCARD_CSV' => __ROOT__ . '/addon/giftcard/shop/view/public/csv',
  33. ];
  34. }
  35. /**
  36. * 兑换卡列表
  37. * @return array|mixed
  38. */
  39. public function lists()
  40. {
  41. if (request()->isAjax()) {
  42. $page = input('page', 1);
  43. $page_size = input('page_size', PAGE_LIST_ROWS);
  44. $search_text = input('search_text', '');
  45. $status = input('status', 'all');
  46. $category_id = input('category_id', 0);
  47. $card_type = input('card_type', 'all');
  48. $condition = array (
  49. [ 'site_id', '=', $this->site_id ],
  50. [ 'is_delete', '=', 0 ]
  51. );
  52. if (!empty($search_text)) {
  53. $condition[] = [ 'card_name', 'like', '%' . $search_text . '%' ];
  54. }
  55. if (!empty($card_type) && $card_type != 'all') {
  56. $condition[] = [ 'card_type', '=', $card_type ];
  57. }
  58. if ($status != 'all') {
  59. $condition[] = [ 'status', '=', $status ];
  60. }
  61. if ($category_id > 0) {
  62. $condition[] = [ 'category_id', '=', $category_id ];
  63. }
  64. $giftcard_model = new GiftCardModel();
  65. $list = $giftcard_model->getGiftcardDetailPageList($condition, $page, $page_size, 'giftcard_id desc')[ 'data' ];
  66. return $list;
  67. } else {
  68. return $this->fetch("giftcard/lists");
  69. }
  70. }
  71. /**
  72. * 添加礼品卡
  73. * @return array|mixed
  74. */
  75. public function add()
  76. {
  77. $card_type = input('card_type', 'virtual');
  78. if (request()->isAjax()) {
  79. $goods_sku_list = input('goods_sku_list', '');
  80. $goods_sku_list = empty($goods_sku_list) ? [] : json_decode($goods_sku_list, true);
  81. $cdk_type_array = input()[ 'cdk_type' ] ?? [];
  82. $data = [
  83. 'card_name' => input('card_name', ''),
  84. 'card_count' => input('card_count', 0),
  85. 'card_cover' => input('card_cover', ''),
  86. 'media_ids' => input('media_ids', ''),
  87. 'cdk_length' => input('cdk_length', 0),
  88. 'cdk_type' => implode(',', $cdk_type_array),
  89. 'card_prefix' => input('card_prefix', ''),
  90. 'card_suffix' => input('card_suffix', ''),
  91. 'card_right_type' => input('card_right_type', ''),
  92. 'card_right_goods_type' => input('card_right_goods_type', ''),
  93. 'card_right_goods_count' => input('card_right_goods_count', ''),
  94. 'card_price' => input('card_price', 0),
  95. 'balance' => input('balance', 0),
  96. 'sort' => input('sort', 0),
  97. 'validity_type' => input('validity_type', ''),
  98. 'validity_time' => input('validity_time', 0),
  99. 'validity_day' => input('validity_day', 0),
  100. 'status' => input('status', 0),
  101. 'category_id' => input('category_id', 0),
  102. 'is_allow_transfer' => input('is_allow_transfer', 0),
  103. 'site_id' => $this->site_id,
  104. 'goods_sku_list' => $goods_sku_list,
  105. 'desc' => input('desc', ''),
  106. 'card_type' => input('card_type', ''),
  107. 'instruction' => input('instruction', ''),
  108. ];
  109. $giftcard_model = new GiftCardModel();
  110. $result = $giftcard_model->addGiftCard($data);
  111. return $result;
  112. } else {
  113. $this->assign('category_list', ( new GiftCardCategoryModel() )->getList([ [ 'site_id', '=', $this->site_id ] ])[ 'data' ] ?? []);
  114. $this->assign('card_right_type_list', ( new GiftCardModel )->card_right_type_list ?? []);
  115. $this->assign('card_type', $card_type);
  116. return $this->fetch('giftcard/add', [], $this->replace);
  117. }
  118. }
  119. /**
  120. * 编辑礼品卡活动
  121. */
  122. public function edit()
  123. {
  124. $giftcard_id = input('giftcard_id', 0);
  125. $giftcard_model = new GiftCardModel();
  126. if (request()->isAjax()) {
  127. $goods_sku_list = input('goods_sku_list', '');
  128. $goods_sku_list = empty($goods_sku_list) ? [] : json_decode($goods_sku_list, true);
  129. $cdk_type_array = input()[ 'cdk_type' ] ?? [];
  130. $data = [
  131. 'card_name' => input('card_name', ''),
  132. 'card_cover' => input('card_cover', ''),
  133. 'media_ids' => input('media_ids', ''),
  134. 'cdk_length' => input('cdk_length', 0),
  135. 'cdk_type' => implode(',', $cdk_type_array),
  136. 'card_prefix' => input('card_prefix', ''),
  137. 'card_suffix' => input('card_suffix', ''),
  138. 'card_right_type' => input('card_right_type', ''),
  139. 'card_right_goods_type' => input('card_right_goods_type', ''),
  140. 'card_right_goods_count' => input('card_right_goods_count', ''),
  141. 'card_price' => input('card_price', 0),
  142. 'balance' => input('balance', 0),
  143. 'sort' => input('sort', 0),
  144. 'validity_type' => input('validity_type', ''),
  145. 'validity_time' => input('validity_time', 0),
  146. 'validity_day' => input('validity_day', 0),
  147. 'status' => input('status', 0),
  148. 'category_id' => input('category_id', 0),
  149. 'card_type' => input('card_type', ''),
  150. 'is_allow_transfer' => input('is_allow_transfer', 0),
  151. 'site_id' => $this->site_id,
  152. 'goods_sku_list' => $goods_sku_list,
  153. 'giftcard_id' => $giftcard_id,
  154. 'desc' => input('desc', ''),
  155. 'instruction' => input('instruction', ''),
  156. ];
  157. $result = $giftcard_model->editGiftCard($data);
  158. return $result;
  159. } else {
  160. // 分组列表
  161. $this->assign('category_list', ( new GiftCardCategoryModel() )->getList([ [ 'site_id', '=', $this->site_id ] ])[ 'data' ] ?? []);
  162. // 详情
  163. $giftcard_info = $giftcard_model->getGiftcardDetail([ 'giftcard_id' => $giftcard_id, 'site_id' => $this->site_id ])[ 'data' ] ?? [];
  164. if (empty($giftcard_info))
  165. $this->error('找不到礼品卡活动');
  166. $this->assign('giftcard_info', $giftcard_info);
  167. $this->assign('card_right_type_list', ( new GiftCardModel )->card_right_type_list ?? []);
  168. return $this->fetch('giftcard/edit', [], $this->replace);
  169. }
  170. }
  171. /**
  172. * 详情
  173. */
  174. public function detail()
  175. {
  176. $giftcard_id = input('giftcard_id', 0);
  177. $giftcard_model = new GiftCardModel();
  178. $detail = $giftcard_model->getGiftcardDetail([ 'giftcard_id' => $giftcard_id, 'site_id' => $this->site_id ])[ 'data' ] ?? [];
  179. if (empty($detail)) {
  180. $this->error('找不到礼品卡活动');
  181. }
  182. $this->assign('category_list', ( new GiftCardCategoryModel() )->getList([ [ 'site_id', '=', $this->site_id ] ])[ 'data' ] ?? []);
  183. $this->assign('card_right_type_list', ( new GiftCardModel )->card_right_type_list ?? []);
  184. $this->assign('detail', $detail);
  185. $this->assign('status_list', ( new Card() )->getStatusList($detail[ 'card_type' ]));
  186. return $this->fetch('giftcard/detail', [], $this->replace);
  187. }
  188. /**
  189. * 删除
  190. * @return mixed
  191. */
  192. public function delete()
  193. {
  194. $giftcard_id = input('giftcard_id', 0);
  195. $giftcard_model = new GiftCardModel();
  196. $result = $giftcard_model->deleteGiftcard([ [ 'giftcard_id', '=', $giftcard_id ], [ 'site_id', '=', $this->site_id ] ]);
  197. return $result;
  198. }
  199. /**
  200. * 排序
  201. * @return array
  202. */
  203. public function sort()
  204. {
  205. $giftcard_id = input('giftcard_id', 0);
  206. $sort = input('sort', 0);
  207. $giftcard_model = new GiftCardModel();
  208. $result = $giftcard_model->modifyGiftcardSort($sort, [ [ 'giftcard_id', '=', $giftcard_id ], [ 'site_id', '=', $this->site_id ] ]);
  209. return $result;
  210. }
  211. public function getCategoryMedia()
  212. {
  213. if (request()->isAjax()) {
  214. $category_id = input('category_id', '');
  215. if (empty($category_id)) return error('-1', '参数不能为空', '');
  216. $condition = [
  217. [ 'category_id', '=', $category_id ]
  218. ];
  219. $category_model = new CategoryModel();
  220. $category_info = $category_model->getInfo($condition, 'media_ids')[ 'data' ];
  221. $res = success();
  222. if (isset($category_info[ 'media_ids' ]) && !empty($category_info[ 'media_ids' ])) {
  223. $condition = [
  224. [ 'media_id', 'in', $category_info[ 'media_ids' ] ]
  225. ];
  226. $media_model = new MediaModel();
  227. $res = $media_model->getList($condition);
  228. if (!empty($res[ 'data' ])) {
  229. foreach ($res[ 'data' ] as $k => $v) {
  230. $res[ 'data' ][ $k ][ 'media_path' ] = img($v[ 'media_path' ]);
  231. }
  232. }
  233. }
  234. return $res;
  235. }
  236. }
  237. /**
  238. * 电子卡上/下架
  239. * @return array
  240. */
  241. public function isuse()
  242. {
  243. if (request()->isAjax()) {
  244. $giftcard_id = input('id', '');
  245. $status = input('status', '');
  246. $giftcard_model = new GiftCardModel();
  247. $param = [
  248. 'giftcard_id' => $giftcard_id,
  249. 'status' => $status,
  250. 'site_id' => $this->site_id
  251. ];
  252. if ($status == 0) {
  253. $result = $giftcard_model->giftcardOff($param);
  254. } elseif ($status == 1) {
  255. $result = $giftcard_model->giftcardOn($param);
  256. }
  257. return $result;
  258. }
  259. }
  260. /**
  261. * 实体卡批量激活/作废
  262. * @return array
  263. */
  264. public function editstatus()
  265. {
  266. if (request()->isAjax()) {
  267. $giftcard_id = input('id', '');
  268. $status = input('status', '');
  269. $giftcard_model = new GiftCardModel();
  270. $param = [
  271. 'giftcard_id' => $giftcard_id,
  272. 'status' => $status,
  273. 'site_id' => $this->site_id
  274. ];
  275. if ($status == 2) {
  276. $result = $giftcard_model->giftcardOff($param);
  277. } elseif ($status == 1) {
  278. $result = $giftcard_model->giftcardOn($param);
  279. }
  280. return $result;
  281. }
  282. }
  283. }