com-batch.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. <?php
  2. try {
  3. if (Yii::$app->plugin->currentPlugin) {
  4. $sign = Yii::$app->plugin->currentPlugin->getName();
  5. } else {
  6. if (Yii::$app->admin->identity->mch_id > 0) {
  7. $sign = 'mch';
  8. } else {
  9. $sign = '';
  10. }
  11. }
  12. } catch (Exception $exception) {
  13. $sign = '';
  14. }
  15. ?>
  16. <style>
  17. .com-batch {
  18. height: 50px;
  19. background-color: #f9f9f9;
  20. padding: 0 22px;
  21. }
  22. .com-batch .batch-box {
  23. margin-left: 10px;
  24. }
  25. .com-batch .batch-remark {
  26. margin-top: 5px;
  27. color: #999999;
  28. font-size: 14px;
  29. }
  30. .com-batch .select-count {
  31. font-size: 14px;
  32. margin-left: 10px;
  33. }
  34. .com-batch .batch-title {
  35. font-size: 18px;
  36. }
  37. .com-batch .batch-box-left {
  38. width: 120px;
  39. border-right: 1px solid #e2e2e2;
  40. padding: 0 20px;
  41. }
  42. .com-batch .batch-box-left div {
  43. padding: 5px 0;
  44. margin: 5px 0;
  45. cursor: pointer;
  46. -webkit-border-radius: 5px;
  47. -moz-border-radius: 5px;
  48. border-radius: 5px;
  49. }
  50. .com-batch .batch-div-active {
  51. background-color: #e2e2e2;
  52. }
  53. .com-batch .el-dialog__body {
  54. padding: 15px 20px;
  55. }
  56. .com-batch .batch-box-right {
  57. padding: 5px 20px;
  58. }
  59. .com-batch .express-dialog .el-dialog {
  60. min-width: 250px;
  61. }
  62. .com-batch .add-express-rule {
  63. margin-left: 20px;
  64. cursor: pointer;
  65. color: #419EFB;
  66. }
  67. .com-batch .confine-box .label {
  68. margin-right: 10px;
  69. }
  70. .com-batch .goods-price .el-input-group__prepend {
  71. width: 80px;
  72. }
  73. </style>
  74. <template id="com-batch">
  75. <div class="com-batch" flex="dir:left cross:center">
  76. <!-- <el-checkbox @change="checkedChange" v-model="isAllChecked" style="margin-right: 10px;">修改全部</el-checkbox>-->
  77. <template v-if="isShowUpDown">
  78. <el-button @click="upDown(1)" size="mini">上架</el-button>
  79. <el-button @click="upDown(0)" size="mini">下架</el-button>
  80. </template>
  81. <el-button v-if="isShowDelete" @click="allDelete" size="mini">删除</el-button>
  82. <el-button v-if="isShowBatchButton" @click="batchSetting" size="mini">批量设置</el-button>
  83. <el-dialog
  84. :visible.sync="dialogVisible"
  85. width="50%">
  86. <div slot="title">
  87. <div flex="dir:left">
  88. <div class="batch-title">批量修改</div>
  89. <div flex="cross:center" class="select-count">{{dialogTitle}}</div>
  90. </div>
  91. <div class="batch-remark">注:每次只能修改一项,修改后点击确定即可生效。如需修改多项,需多次操作。</div>
  92. </div>
  93. <div flex="dir:left box:first">
  94. <div class="batch-box-left" flex="dir:top">
  95. <div v-for="(item, index) in newBatchList"
  96. :key='item.key'
  97. :class="{'batch-div-active': currentBatch === item.key ? true : false}"
  98. @click="currentBatch = item.key"
  99. flex="main:center">
  100. {{item.name}}
  101. </div>
  102. </div>
  103. <div class="batch-box-right">
  104. <el-form>
  105. <div v-if="currentBatch === 'goods-price'">
  106. <el-form-item label-width="80px" label="调整类型">
  107. <div>
  108. <el-radio v-model="goodsPrice.type" :label="1">固定金额</el-radio>
  109. <el-radio v-model="goodsPrice.type" :label="2">百分比</el-radio>
  110. </div>
  111. </el-form-item>
  112. <el-form-item class="goods-price" label-width="80px" label="售价">
  113. <el-input size="small" oninput="this.value = this.value.replace(/[^0-9.]/, '');"
  114. type="number" placeholder="请输入价格" v-model="goodsPrice.price">
  115. <el-select v-model="goodsPrice.select_type" slot="prepend" placeholder="请选择">
  116. <el-option label="提高" :value="1"></el-option>
  117. <el-option label="降低" :value="2"></el-option>
  118. </el-select>
  119. <el-button slot="append">{{goodsPrice.type == 1 ? '元' : '%'}}</el-button>
  120. </el-input>
  121. </el-form-item>
  122. </div>
  123. <div v-if="currentBatch === 'express-price'">
  124. <el-form-item label="运费设置">
  125. <div style="display: inline-block">
  126. <el-tag v-if="expressRule" :disable-transitions="true" closable
  127. @close="expressRule = null">{{expressRule.name}}
  128. </el-tag>
  129. <el-button size="small" @click="selectExpressRule">选择运费</el-button>
  130. <span @click="$navigate({r:'mall/setting/rule'}, true)"
  131. class="add-express-rule">新建</span>
  132. </div>
  133. </el-form-item>
  134. </div>
  135. <div v-if="currentBatch === 'confine'">
  136. <el-form-item label="每人限购">
  137. <div flex="dir:top" class="confine-box">
  138. <div flex="dir:left">
  139. <span class="label">商品</span>
  140. <div flex="dir:left">
  141. <div>
  142. <el-input type="number" min="0" size="small" placeholder="请输入限购数量"
  143. oninput="this.value = this.value.replace(/[^0-9]/, '');"
  144. :disabled="confine.isGoodsConfine"
  145. v-model="confine.goodsCount">
  146. <template slot="append">件</template>
  147. </el-input>
  148. </div>
  149. <el-checkbox style="margin-left: 10px;" v-model="confine.isGoodsConfine">
  150. 不限制
  151. </el-checkbox>
  152. </div>
  153. </div>
  154. <div flex="dir:left">
  155. <span class="label">订单</span>
  156. <div flex="dir:left">
  157. <div>
  158. <el-input type="number" size="small" placeholder="请输入限购单数"
  159. oninput="this.value = this.value.replace(/[^0-9]/, '');"
  160. min="0"
  161. :disabled="confine.isOrderConfine"
  162. v-model="confine.orderCount">
  163. <template slot="append">单</template>
  164. </el-input>
  165. </div>
  166. <el-checkbox style="margin-left: 10px;" v-model="confine.isOrderConfine">
  167. 不限制
  168. </el-checkbox>
  169. </div>
  170. </div>
  171. </div>
  172. </el-form-item>
  173. </div>
  174. <div v-if="currentBatch === 'integral'">
  175. <el-form-item label="积分赠送">
  176. <div flex="dir:left">
  177. <div>
  178. <el-tooltip effect="dark"
  179. placement="top">
  180. <div slot="content">用户购物赠送的积分, 如果不填写或填写0,则默认为不赠送积分,
  181. 如果为百分比则为按成交价格的比例计算积分"<br/>
  182. 如: 购买2件,设置10 积分, 不管成交价格是多少, 则购买后获得20积分</br>
  183. 如: 购买2件,设置10%积分, 成交价格2 * 200= 400, 则购买后获得 40 积分(400*10%)
  184. </div>
  185. <i class="el-icon-info"></i>
  186. </el-tooltip>
  187. </div>
  188. <div style="margin-left: 5px;width: 100%;">
  189. <el-input type="number"
  190. size="small"
  191. oninput="this.value = this.value.replace(/[^0-9]/, '');"
  192. min="0"
  193. placeholder="请输入赠送积分数量"
  194. v-model="integral.give_score">
  195. <template slot="append">
  196. 分
  197. <el-radio v-model="integral.give_score_type" :label="1">固定值
  198. </el-radio>
  199. <el-radio v-model="integral.give_score_type" :label="2">百分比
  200. </el-radio>
  201. </template>
  202. </el-input>
  203. </div>
  204. </div>
  205. </el-form-item>
  206. <el-form-item label="积分抵扣">
  207. <div flex="dir:left">
  208. <div>
  209. <el-tooltip effect="dark"
  210. placement="top">
  211. <div slot="content">如果设置0,则不支持积分抵扣 如果带%则为按成交价格的比例计算抵扣多少元</div>
  212. <i class="el-icon-info"></i>
  213. </el-tooltip>
  214. </div>
  215. <div style="margin-left: 5px;width: 100%;">
  216. <el-input type="number"
  217. size="small"
  218. placeholder="请输入赠送积分数量"
  219. oninput="this.value = this.value.replace(/[^0-9]/, '');"
  220. min="0"
  221. v-model="integral.forehead_score">
  222. <template slot="prepend">最多抵扣</template>
  223. <template slot="append">
  224. 元
  225. <el-radio v-model="integral.forehead_score_type" :label="1">固定值
  226. </el-radio>
  227. <el-radio v-model="integral.forehead_score_type" :label="2">百分比
  228. </el-radio>
  229. </template>
  230. </el-input>
  231. <el-checkbox
  232. :true-label="1"
  233. :false-label="0"
  234. v-model="integral.accumulative">
  235. 允许多件累计抵扣
  236. </el-checkbox>
  237. </div>
  238. </div>
  239. </el-form-item>
  240. </div>
  241. <div v-if="currentBatch === 'is-vip'">
  242. <el-form-item label="是否享受超级会员卡权益">
  243. <el-switch v-model="isSvip"></el-switch>
  244. </el-form-item>
  245. </div>
  246. <slot name="batch" :item="currentBatch"></slot>
  247. </el-form>
  248. </div>
  249. </div>
  250. <div slot="footer">
  251. <el-button size="small" @click="dialogVisible = false">取 消</el-button>
  252. <el-button size="small" :loading="btnLoading" type="primary" @click="dialogSubmit">确 定
  253. </el-button>
  254. </div>
  255. </el-dialog>
  256. <el-dialog
  257. class="express-dialog"
  258. title="选择运费"
  259. :visible.sync="freight.dialog"
  260. width="25%">
  261. <el-card shadow="never" flex="dir:left" style="flex-wrap: wrap"
  262. v-loading="freight.loading">
  263. <el-radio-group flex="dir:top" v-model="freight.checked">
  264. <el-radio style="padding: 10px;" v-for="item in freight.list"
  265. :label="item" :key="item.id">{{item.name}}
  266. </el-radio>
  267. </el-radio-group>
  268. </el-card>
  269. <div slot="footer">
  270. <el-button size="small" @click="freight.dialog = false">取 消</el-button>
  271. <el-button size="small" type="primary" @click="expressSubmit">确 定</el-button>
  272. </div>
  273. </el-dialog>
  274. </div>
  275. </template>
  276. <script>
  277. Vue.component('com-batch', {
  278. template: '#com-batch',
  279. props: {
  280. // 列表选中的数据
  281. chooseList: {
  282. type: Array,
  283. default: function () {
  284. return [];
  285. }
  286. },
  287. batchUpdateStatusUrl: {
  288. type: String,
  289. default: 'mall/goods/batch-update-status',
  290. },
  291. batchDestroyUrl: {
  292. type: String,
  293. default: 'mall/goods/batch-destroy',
  294. },
  295. batchConfineUrl: {
  296. type: String,
  297. default: 'mall/goods/batch-update-confine-count',
  298. },
  299. batchFreightUrl: {
  300. type: String,
  301. default: 'mall/goods/batch-update-freight',
  302. },
  303. // 上架弹框提示文字
  304. statusChangeText: {
  305. type: String,
  306. default: '',
  307. },
  308. /**
  309. * 批量设置参数
  310. * 参数例子:baseBatchList
  311. */
  312. batchList: {
  313. type: Array,
  314. default: function () {
  315. return [];
  316. }
  317. },
  318. // 是否开启批量超级会员卡设置
  319. isShowSvip: {
  320. type: Boolean,
  321. default: true
  322. },
  323. // 是否开启批量运费设置
  324. isShowExpress: {
  325. type: Boolean,
  326. default: true
  327. },
  328. // 是否开启批量运费设置
  329. isShowIntegral: {
  330. type: Boolean,
  331. default: true
  332. },
  333. // 是否开启批量设置按钮
  334. isShowBatchButton: {
  335. type: Boolean,
  336. default: true
  337. },
  338. // 是否显示批量上下架按钮
  339. isShowUpDown: {
  340. type: Boolean,
  341. default: true
  342. },
  343. // 是否显示批量删除按钮
  344. isShowDelete: {
  345. type: Boolean,
  346. default: true
  347. },
  348. // 批量操作额外参数
  349. batchExtraParams: {
  350. type: Array,
  351. default: function () {
  352. return []
  353. }
  354. }
  355. },
  356. data() {
  357. return {
  358. isAllChecked: false,
  359. freight: {
  360. dialog: false,
  361. list: [],
  362. checked: {},
  363. loading: false,
  364. },
  365. btnLoading: false,
  366. dialogVisible: false,
  367. currentBatch: '',
  368. isSvip: false,
  369. is_show_svip: false,
  370. goodsPrice: {
  371. type: 1,
  372. select_type: 1,
  373. price: 0,
  374. },
  375. expressRule: {
  376. id: 0,
  377. name: '默认运费',
  378. },
  379. confine: {
  380. goodsCount: 0,
  381. orderCount: 0,
  382. isGoodsConfine: true,
  383. isOrderConfine: true,
  384. },
  385. integral: {
  386. give_score_type: 1,
  387. give_score: 0,
  388. forehead_score: 0,
  389. forehead_score_type: 1,
  390. accumulative: 0
  391. },
  392. dialogTitle: '',
  393. newBatchList: [],
  394. baseBatchList: [
  395. // {
  396. // name: '价格',
  397. // key: 'goods-price',// 唯一
  398. // },
  399. {
  400. name: '运费',
  401. key: 'express-price',// 唯一
  402. },
  403. {
  404. name: '限购',
  405. key: 'confine',
  406. },
  407. {
  408. name: '积分',
  409. key: 'integral',
  410. },
  411. {
  412. name: '超级会员卡',
  413. key: 'is-vip',
  414. },
  415. ]
  416. }
  417. },
  418. methods: {
  419. checkChooseList() {
  420. if (this.isAllChecked) {
  421. this.dialogTitle = '已选所有商品';
  422. return true;
  423. }
  424. if (this.chooseList.length > 0) {
  425. this.dialogTitle = '已选商品' + this.chooseList.length + '种';
  426. return true;
  427. }
  428. this.$message.warning('请先勾选要设置的商品');
  429. return false;
  430. },
  431. upDown(command) {
  432. let self = this;
  433. if (!self.checkChooseList()) {
  434. return false;
  435. }
  436. if (command === 1) {
  437. this.statusChange(1)
  438. }
  439. let text = this.isAllChecked ? '警告:批量' + (command === 1 ? '上架' : '下架') + '所有商品?' : '批量' + (command === 1 ? '上架' : '下架') + ',是否继续';
  440. this.batchAction({
  441. url: self.batchUpdateStatusUrl,
  442. content: text,
  443. params: {
  444. batch_ids: this.chooseList,
  445. is_all: this.isAllChecked ? 1 : 0,
  446. status: command,
  447. plugin_sign: '<?= $sign ?>',
  448. }
  449. });
  450. },
  451. // 上架状态开关,弹框文字提示
  452. statusChange(res) {
  453. let text = this.statusChangeText;
  454. if (res && text) {
  455. this.$alert(text, '提示', {
  456. confirmButtonText: '确定',
  457. callback: action => {
  458. }
  459. });
  460. }
  461. },
  462. allDelete() {
  463. let self = this;
  464. if (!self.checkChooseList()) {
  465. return false;
  466. }
  467. let text = this.isAllChecked ? '警告:是否确认删除所有商品?' : '是否确认删除选中的商品?';
  468. this.batchAction({
  469. url: self.batchDestroyUrl,
  470. content: text,
  471. params: {
  472. batch_ids: this.chooseList,
  473. is_all: this.isAllChecked ? 1 : 0,
  474. plugin_sign: '<?= $sign ?>',
  475. }
  476. });
  477. },
  478. batchAction(data) {
  479. let self = this;
  480. self.batchExtraParams.forEach(function (item) {
  481. data.params[item.key] = item.value;
  482. });
  483. self.$confirm(data.content, '提示', {
  484. confirmButtonText: '确定',
  485. cancelButtonText: '取消',
  486. type: 'warning'
  487. }).then(() => {
  488. self.btnLoading = true
  489. request({
  490. params: {
  491. r: data.url
  492. },
  493. data: data.params,
  494. method: 'post'
  495. }).then(e => {
  496. self.btnLoading = false;
  497. if (e.data.code === 0) {
  498. self.dialogVisible = false;
  499. self.$message.success(e.data.msg);
  500. self.getList();
  501. } else {
  502. self.$message.error(e.data.msg);
  503. }
  504. }).catch(e => {
  505. self.$message.error(e.data.msg);
  506. self.btnLoading = false;
  507. });
  508. }).catch(() => {
  509. });
  510. },
  511. // 获取运费规则选项
  512. getFreight() {
  513. let self = this;
  514. this.freight.loading = true;
  515. request({
  516. params: {
  517. r: 'mall/postage-rules/all-list'
  518. },
  519. method: 'get',
  520. data: {}
  521. }).then(e => {
  522. this.freight.loading = false;
  523. if (e.data.code === 0) {
  524. self.freight.list = e.data.data.list;
  525. // 添加商品时使用默认运费
  526. let obj = {
  527. id: 0,
  528. name: '默认运费',
  529. status: 1
  530. };
  531. self.freight.list.unshift(obj);
  532. self.freight.checked = obj;
  533. } else {
  534. self.$message.error(e.data.msg);
  535. }
  536. }).catch(e => {
  537. console.log(e);
  538. });
  539. },
  540. getList() {
  541. this.isAllChecked = false;
  542. this.$emit('to-search')
  543. },
  544. dialogSubmit() {
  545. let self = this;
  546. let params = {
  547. batch_ids: this.chooseList,
  548. is_all: this.isAllChecked ? 1 : 0,
  549. plugin_sign: '<?= $sign ?>'
  550. };
  551. switch (this.currentBatch) {
  552. case 'express-price':
  553. if (!this.expressRule) {
  554. self.$message.warning('请选择运费规则');
  555. return false;
  556. }
  557. params.freight_id = this.expressRule.id;
  558. var text = this.isAllChecked ? '警告:批量设置所有商品运费规则,是否继续' : '批量设置运费规则,是否继续';
  559. this.batchAction({
  560. url: self.batchFreightUrl,
  561. content: text,
  562. params: params
  563. });
  564. break;
  565. case 'confine':
  566. var text = this.isAllChecked ? '警告:批量设置所有商品限购,是否继续' : '批量设置限购,是否继续';
  567. params.continue_goods_count = this.confine.goodsCount;
  568. params.continue_order_count = this.confine.orderCount;
  569. params.is_goods_confine = this.confine.isGoodsConfine ? 1 : 0;
  570. params.is_order_confine = this.confine.isOrderConfine ? 1 : 0;
  571. this.batchAction({
  572. url: self.batchConfineUrl,
  573. content: text,
  574. params: params
  575. });
  576. break;
  577. case 'integral':
  578. var text = this.isAllChecked ? '警告:批量设置所有商品积分,是否继续' : '批量设置积分,是否继续';
  579. params.give_score_type = this.integral.give_score_type;
  580. params.give_score = this.integral.give_score;
  581. params.forehead_score = this.integral.forehead_score;
  582. params.forehead_score_type = this.integral.forehead_score_type;
  583. params.accumulative = this.integral.accumulative;
  584. this.batchAction({
  585. url: 'mall/goods/batch-update-integral',
  586. content: text,
  587. params: params
  588. });
  589. break;
  590. case 'is-vip':
  591. console.log(params.status)
  592. params.status = this.isSvip ? 1 : 0;
  593. var text = this.isAllChecked ? '警告:批量设置所有商品' + (params.status ? '享受' : '取消') + '超级会员卡权益,是否继续' : '批量' + (params.status ? '享受' : '取消') + '超级会员卡权益,是否继续';
  594. this.batchAction({
  595. url: 'plugin/vip_card/mall/setting/batch-update-appoint',
  596. content: text,
  597. params: params
  598. });
  599. break;
  600. // 修改商品价格
  601. case 'goods-price':
  602. var text = this.isAllChecked ? '警告:批量设置所有商品售价,是否继续' : '批量设置商品售价,是否继续';
  603. params.goods_price = this.goodsPrice.price;
  604. params.goods_price_type = this.goodsPrice.type;
  605. params.goods_price_update_type = this.goodsPrice.select_type;
  606. this.batchAction({
  607. url: 'mall/goods/batch-update-goods-price',
  608. content: '批量设置商品售价,是否继续',
  609. params: params
  610. });
  611. break;
  612. // 插件自定义批量设置
  613. default:
  614. self.batchList.forEach(function (item) {
  615. if (self.currentBatch === item.key) {
  616. Object.assign(params, item.params);
  617. self.batchAction({
  618. url: item.url,
  619. content: item.content,
  620. params: params
  621. });
  622. }
  623. });
  624. break;
  625. }
  626. },
  627. selectExpressRule() {
  628. this.freight.dialog = true;
  629. this.getFreight();
  630. },
  631. expressSubmit() {
  632. this.expressRule = this.freight.checked;
  633. this.freight.dialog = false;
  634. },
  635. // 打开批量设置框
  636. batchSetting() {
  637. let self = this;
  638. if (!self.checkChooseList()) {
  639. return false;
  640. }
  641. self.newBatchList = [];
  642. self.baseBatchList.forEach(function (item) {
  643. if (item.key === 'is-vip') {
  644. if (self.isShowSvip) {
  645. self.newBatchList.push(item);
  646. }
  647. } else if (item.key === 'express-price') {
  648. if (self.isShowExpress) {
  649. self.newBatchList.push(item);
  650. }
  651. } else if (item.key === 'integral') {
  652. if (self.isShowIntegral) {
  653. self.newBatchList.push(item);
  654. }
  655. } else {
  656. self.newBatchList.push(item);
  657. }
  658. });
  659. self.batchList.forEach(function (item) {
  660. self.newBatchList.push(item)
  661. });
  662. self.currentBatch = self.newBatchList[0].key;
  663. self.dialogVisible = true;
  664. self.checkedChange(self.isAllChecked);
  665. },
  666. getSvip() {
  667. request({
  668. params: {
  669. r: 'mall/member-level/vip-card-permission',
  670. },
  671. }).then(e => {
  672. if (e.data.code === 0) {
  673. this.is_show_svip = true;
  674. } else {
  675. this.is_show_svip = false;
  676. }
  677. })
  678. },
  679. checkedChange(e) {
  680. this.$emit('get-all-checked', e)
  681. }
  682. },
  683. created() {
  684. this.getSvip();
  685. }
  686. })
  687. </script>