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. <el-radio v-model="integral.give_score_type" :label="1">固定值
  197. </el-radio>
  198. <el-radio v-model="integral.give_score_type" :label="2">百分比
  199. </el-radio>
  200. </template>
  201. </el-input>
  202. </div>
  203. </div>
  204. </el-form-item>
  205. <el-form-item label="积分抵扣">
  206. <div flex="dir:left">
  207. <div>
  208. <el-tooltip effect="dark"
  209. placement="top">
  210. <div slot="content">如果设置0,则不支持积分抵扣 如果带%则为按成交价格的比例计算抵扣多少元</div>
  211. <i class="el-icon-info"></i>
  212. </el-tooltip>
  213. </div>
  214. <div style="margin-left: 5px;width: 100%;">
  215. <el-input type="number"
  216. size="small"
  217. placeholder="请输入赠送积分数量"
  218. oninput="this.value = this.value.replace(/[^0-9]/, '');"
  219. min="0"
  220. v-model="integral.forehead_score">
  221. <template slot="prepend">最多抵扣</template>
  222. <template slot="append">
  223. <el-radio v-model="integral.forehead_score_type" :label="1">固定值
  224. </el-radio>
  225. <el-radio v-model="integral.forehead_score_type" :label="2">百分比
  226. </el-radio>
  227. </template>
  228. </el-input>
  229. <el-checkbox
  230. :true-label="1"
  231. :false-label="0"
  232. v-model="integral.accumulative">
  233. 允许多件累计抵扣
  234. </el-checkbox>
  235. </div>
  236. </div>
  237. </el-form-item>
  238. </div>
  239. <div v-if="currentBatch === 'is-vip'">
  240. <el-form-item label="是否享受超级会员卡权益">
  241. <el-switch v-model="isSvip"></el-switch>
  242. </el-form-item>
  243. </div>
  244. <slot name="batch" :item="currentBatch"></slot>
  245. </el-form>
  246. </div>
  247. </div>
  248. <div slot="footer">
  249. <el-button size="small" @click="dialogVisible = false">取 消</el-button>
  250. <el-button size="small" :loading="btnLoading" type="primary" @click="dialogSubmit">确 定
  251. </el-button>
  252. </div>
  253. </el-dialog>
  254. <el-dialog
  255. class="express-dialog"
  256. title="选择运费"
  257. :visible.sync="freight.dialog"
  258. width="25%">
  259. <el-card shadow="never" flex="dir:left" style="flex-wrap: wrap"
  260. v-loading="freight.loading">
  261. <el-radio-group flex="dir:top" v-model="freight.checked">
  262. <el-radio style="padding: 10px;" v-for="item in freight.list"
  263. :label="item" :key="item.id">{{item.name}}
  264. </el-radio>
  265. </el-radio-group>
  266. </el-card>
  267. <div slot="footer">
  268. <el-button size="small" @click="freight.dialog = false">取 消</el-button>
  269. <el-button size="small" type="primary" @click="expressSubmit">确 定</el-button>
  270. </div>
  271. </el-dialog>
  272. </div>
  273. </template>
  274. <script>
  275. Vue.component('com-batch', {
  276. template: '#com-batch',
  277. props: {
  278. // 列表选中的数据
  279. chooseList: {
  280. type: Array,
  281. default: function () {
  282. return [];
  283. }
  284. },
  285. batchUpdateStatusUrl: {
  286. type: String,
  287. default: 'mall/goods/batch-update-status',
  288. },
  289. batchDestroyUrl: {
  290. type: String,
  291. default: 'mall/goods/batch-destroy',
  292. },
  293. batchConfineUrl: {
  294. type: String,
  295. default: 'mall/goods/batch-update-confine-count',
  296. },
  297. batchFreightUrl: {
  298. type: String,
  299. default: 'mall/goods/batch-update-freight',
  300. },
  301. // 上架弹框提示文字
  302. statusChangeText: {
  303. type: String,
  304. default: '',
  305. },
  306. /**
  307. * 批量设置参数
  308. * 参数例子:baseBatchList
  309. */
  310. batchList: {
  311. type: Array,
  312. default: function () {
  313. return [];
  314. }
  315. },
  316. // 是否开启批量超级会员卡设置
  317. isShowSvip: {
  318. type: Boolean,
  319. default: true
  320. },
  321. // 是否开启批量运费设置
  322. isShowExpress: {
  323. type: Boolean,
  324. default: true
  325. },
  326. // 是否开启批量运费设置
  327. isShowIntegral: {
  328. type: Boolean,
  329. default: true
  330. },
  331. // 是否开启批量设置按钮
  332. isShowBatchButton: {
  333. type: Boolean,
  334. default: true
  335. },
  336. // 是否显示批量上下架按钮
  337. isShowUpDown: {
  338. type: Boolean,
  339. default: true
  340. },
  341. // 是否显示批量删除按钮
  342. isShowDelete: {
  343. type: Boolean,
  344. default: true
  345. },
  346. // 批量操作额外参数
  347. batchExtraParams: {
  348. type: Array,
  349. default: function () {
  350. return []
  351. }
  352. }
  353. },
  354. data() {
  355. return {
  356. isAllChecked: false,
  357. freight: {
  358. dialog: false,
  359. list: [],
  360. checked: {},
  361. loading: false,
  362. },
  363. btnLoading: false,
  364. dialogVisible: false,
  365. currentBatch: '',
  366. isSvip: false,
  367. is_show_svip: false,
  368. goodsPrice: {
  369. type: 1,
  370. select_type: 1,
  371. price: 0,
  372. },
  373. expressRule: {
  374. id: 0,
  375. name: '默认运费',
  376. },
  377. confine: {
  378. goodsCount: 0,
  379. orderCount: 0,
  380. isGoodsConfine: true,
  381. isOrderConfine: true,
  382. },
  383. integral: {
  384. give_score_type: 1,
  385. give_score: 0,
  386. forehead_score: 0,
  387. forehead_score_type: 1,
  388. accumulative: 0
  389. },
  390. dialogTitle: '',
  391. newBatchList: [],
  392. baseBatchList: [
  393. // {
  394. // name: '价格',
  395. // key: 'goods-price',// 唯一
  396. // },
  397. {
  398. name: '运费',
  399. key: 'express-price',// 唯一
  400. },
  401. {
  402. name: '限购',
  403. key: 'confine',
  404. },
  405. {
  406. name: '积分',
  407. key: 'integral',
  408. },
  409. {
  410. name: '超级会员卡',
  411. key: 'is-vip',
  412. },
  413. ]
  414. }
  415. },
  416. methods: {
  417. checkChooseList() {
  418. if (this.isAllChecked) {
  419. this.dialogTitle = '已选所有商品';
  420. return true;
  421. }
  422. if (this.chooseList.length > 0) {
  423. this.dialogTitle = '已选商品' + this.chooseList.length + '种';
  424. return true;
  425. }
  426. this.$message.warning('请先勾选要设置的商品');
  427. return false;
  428. },
  429. upDown(command) {
  430. let self = this;
  431. if (!self.checkChooseList()) {
  432. return false;
  433. }
  434. if (command === 1) {
  435. this.statusChange(1)
  436. }
  437. let text = this.isAllChecked ? '警告:批量' + (command === 1 ? '上架' : '下架') + '所有商品?' : '批量' + (command === 1 ? '上架' : '下架') + ',是否继续';
  438. this.batchAction({
  439. url: self.batchUpdateStatusUrl,
  440. content: text,
  441. params: {
  442. batch_ids: this.chooseList,
  443. is_all: this.isAllChecked ? 1 : 0,
  444. status: command,
  445. plugin_sign: '<?= $sign ?>',
  446. }
  447. });
  448. },
  449. // 上架状态开关,弹框文字提示
  450. statusChange(res) {
  451. let text = this.statusChangeText;
  452. if (res && text) {
  453. this.$alert(text, '提示', {
  454. confirmButtonText: '确定',
  455. callback: action => {
  456. }
  457. });
  458. }
  459. },
  460. allDelete() {
  461. let self = this;
  462. if (!self.checkChooseList()) {
  463. return false;
  464. }
  465. let text = this.isAllChecked ? '警告:是否确认删除所有商品?' : '是否确认删除选中的商品?';
  466. this.batchAction({
  467. url: self.batchDestroyUrl,
  468. content: text,
  469. params: {
  470. batch_ids: this.chooseList,
  471. is_all: this.isAllChecked ? 1 : 0,
  472. plugin_sign: '<?= $sign ?>',
  473. }
  474. });
  475. },
  476. batchAction(data) {
  477. let self = this;
  478. self.batchExtraParams.forEach(function (item) {
  479. data.params[item.key] = item.value;
  480. });
  481. self.$confirm(data.content, '提示', {
  482. confirmButtonText: '确定',
  483. cancelButtonText: '取消',
  484. type: 'warning'
  485. }).then(() => {
  486. self.btnLoading = true
  487. request({
  488. params: {
  489. r: data.url
  490. },
  491. data: data.params,
  492. method: 'post'
  493. }).then(e => {
  494. self.btnLoading = false;
  495. if (e.data.code === 0) {
  496. self.dialogVisible = false;
  497. self.$message.success(e.data.msg);
  498. self.getList();
  499. } else {
  500. self.$message.error(e.data.msg);
  501. }
  502. }).catch(e => {
  503. self.$message.error(e.data.msg);
  504. self.btnLoading = false;
  505. });
  506. }).catch(() => {
  507. });
  508. },
  509. // 获取运费规则选项
  510. getFreight() {
  511. let self = this;
  512. this.freight.loading = true;
  513. request({
  514. params: {
  515. r: 'mall/postage-rules/all-list'
  516. },
  517. method: 'get',
  518. data: {}
  519. }).then(e => {
  520. this.freight.loading = false;
  521. if (e.data.code === 0) {
  522. self.freight.list = e.data.data.list;
  523. // 添加商品时使用默认运费
  524. let obj = {
  525. id: 0,
  526. name: '默认运费',
  527. status: 1
  528. };
  529. self.freight.list.unshift(obj);
  530. self.freight.checked = obj;
  531. } else {
  532. self.$message.error(e.data.msg);
  533. }
  534. }).catch(e => {
  535. console.log(e);
  536. });
  537. },
  538. getList() {
  539. this.isAllChecked = false;
  540. this.$emit('to-search')
  541. },
  542. dialogSubmit() {
  543. let self = this;
  544. let params = {
  545. batch_ids: this.chooseList,
  546. is_all: this.isAllChecked ? 1 : 0,
  547. plugin_sign: '<?= $sign ?>'
  548. };
  549. switch (this.currentBatch) {
  550. case 'express-price':
  551. if (!this.expressRule) {
  552. self.$message.warning('请选择运费规则');
  553. return false;
  554. }
  555. params.freight_id = this.expressRule.id;
  556. var text = this.isAllChecked ? '警告:批量设置所有商品运费规则,是否继续' : '批量设置运费规则,是否继续';
  557. this.batchAction({
  558. url: self.batchFreightUrl,
  559. content: text,
  560. params: params
  561. });
  562. break;
  563. case 'confine':
  564. var text = this.isAllChecked ? '警告:批量设置所有商品限购,是否继续' : '批量设置限购,是否继续';
  565. params.continue_goods_count = this.confine.goodsCount;
  566. params.continue_order_count = this.confine.orderCount;
  567. params.is_goods_confine = this.confine.isGoodsConfine ? 1 : 0;
  568. params.is_order_confine = this.confine.isOrderConfine ? 1 : 0;
  569. this.batchAction({
  570. url: self.batchConfineUrl,
  571. content: text,
  572. params: params
  573. });
  574. break;
  575. case 'integral':
  576. var text = this.isAllChecked ? '警告:批量设置所有商品积分,是否继续' : '批量设置积分,是否继续';
  577. params.give_score_type = this.integral.give_score_type;
  578. params.give_score = this.integral.give_score;
  579. params.forehead_score = this.integral.forehead_score;
  580. params.forehead_score_type = this.integral.forehead_score_type;
  581. params.accumulative = this.integral.accumulative;
  582. this.batchAction({
  583. url: 'mall/goods/batch-update-integral',
  584. content: text,
  585. params: params
  586. });
  587. break;
  588. case 'is-vip':
  589. console.log(params.status)
  590. params.status = this.isSvip ? 1 : 0;
  591. var text = this.isAllChecked ? '警告:批量设置所有商品' + (params.status ? '享受' : '取消') + '超级会员卡权益,是否继续' : '批量' + (params.status ? '享受' : '取消') + '超级会员卡权益,是否继续';
  592. this.batchAction({
  593. url: 'plugin/vip_card/mall/setting/batch-update-appoint',
  594. content: text,
  595. params: params
  596. });
  597. break;
  598. // 修改商品价格
  599. case 'goods-price':
  600. var text = this.isAllChecked ? '警告:批量设置所有商品售价,是否继续' : '批量设置商品售价,是否继续';
  601. params.goods_price = this.goodsPrice.price;
  602. params.goods_price_type = this.goodsPrice.type;
  603. params.goods_price_update_type = this.goodsPrice.select_type;
  604. this.batchAction({
  605. url: 'mall/goods/batch-update-goods-price',
  606. content: '批量设置商品售价,是否继续',
  607. params: params
  608. });
  609. break;
  610. // 插件自定义批量设置
  611. default:
  612. self.batchList.forEach(function (item) {
  613. if (self.currentBatch === item.key) {
  614. Object.assign(params, item.params);
  615. self.batchAction({
  616. url: item.url,
  617. content: item.content,
  618. params: params
  619. });
  620. }
  621. });
  622. break;
  623. }
  624. },
  625. selectExpressRule() {
  626. this.freight.dialog = true;
  627. this.getFreight();
  628. },
  629. expressSubmit() {
  630. this.expressRule = this.freight.checked;
  631. this.freight.dialog = false;
  632. },
  633. // 打开批量设置框
  634. batchSetting() {
  635. let self = this;
  636. if (!self.checkChooseList()) {
  637. return false;
  638. }
  639. self.newBatchList = [];
  640. self.baseBatchList.forEach(function (item) {
  641. if (item.key === 'is-vip') {
  642. if (self.isShowSvip) {
  643. self.newBatchList.push(item);
  644. }
  645. } else if (item.key === 'express-price') {
  646. if (self.isShowExpress) {
  647. self.newBatchList.push(item);
  648. }
  649. } else if (item.key === 'integral') {
  650. if (self.isShowIntegral) {
  651. self.newBatchList.push(item);
  652. }
  653. } else {
  654. self.newBatchList.push(item);
  655. }
  656. });
  657. self.batchList.forEach(function (item) {
  658. self.newBatchList.push(item)
  659. });
  660. self.currentBatch = self.newBatchList[0].key;
  661. self.dialogVisible = true;
  662. self.checkedChange(self.isAllChecked);
  663. },
  664. getSvip() {
  665. request({
  666. params: {
  667. r: 'mall/member-level/vip-card-permission',
  668. },
  669. }).then(e => {
  670. if (e.data.code === 0) {
  671. this.is_show_svip = true;
  672. } else {
  673. this.is_show_svip = false;
  674. }
  675. })
  676. },
  677. checkedChange(e) {
  678. this.$emit('get-all-checked', e)
  679. }
  680. },
  681. created() {
  682. this.getSvip();
  683. }
  684. })
  685. </script>