<|start_filename|>linjiashop-mobile/src/view/order/payment/callback/callback.js<|end_filename|>
import payApi from '@/api/pay'
import {Button, NavBar, Toast,Icon} from 'vant'
export default {
    components: {
        [NavBar.name]: NavBar,
        [Button.name]: Button,
        [Toast.name]: Toast,
        [Icon.name]: Icon
    },
    data() {
        return {
            result:'查询中',
            isSuccess:false,
            orderSn:''
        };
    },
    mounted() {
        this.init()
    },
    methods: {
        init() {
            const orderSn = this.$route.params.orderSn
            this.orderSn = orderSn
            payApi.queryResult(orderSn).then(res => {
                if(res.data === true){
                    this.result="支付成功"
                    this.isSuccess = true
                }else{
                    this.isSuccess = false
                    this.result="支付失败"
                }
            })
        },
        toIndex(){
            this.$router.push('/index')
        },
        toOrder(){
            this.$router.push('/order/detail/'+this.orderSn)
        }
    }
};


<|start_filename|>linjiashop-mobile/src/view/order/payment/payment.js<|end_filename|>
import payApi from '@/api/pay'
import {Button, Cell, CellGroup, NavBar, Radio, RadioGroup, Toast} from 'vant'
import wx from 'weixin-js-sdk'

export default {
    components: {
        [NavBar.name]: NavBar,
        [Cell.name]: Cell,
        [CellGroup.name]: CellGroup,
        [RadioGroup.name]: RadioGroup,
        [Radio.name]: Radio,
        [Button.name]: Button,
        [Toast.name]: Toast
    },

    data() {
        return {
            order: {},
            payType: 'wxpay'
        };
    },
    mounted() {
        this.init()
    },
    computed: {},
    methods: {
        init() {
            let orderSn = this.$route.query.orderSn
            let totalPrice = this.$route.query.totalPrice
            this.order ={orderSn:orderSn,totalPrice:totalPrice}
        },
        pay() {
            if(this.payType === 'wxpay'){
                this.wxPrepare()
            }else{
                Toast('支付宝支付对接中...')
            }
        },
        formatPrice(price) {
            return (price / 100).toFixed(2);
        },
        wxPrepare () {
            payApi.wxPrepare({orderSn:this.order.orderSn}).then(res => {
                // 存储微信支付数据data
                let data = res.data
                //函数为分装过得  (就是调用微信支付)
                this.wxPay(
                    {
                        appId: data.appId,
                        nonceStr: data.nonceStr,
                        package: data.packageValue,
                        paySign: data.paySign,
                        signType: data.signType,
                        timeStamp: data.timeStamp
                    }

                )
            }).catch(err =>{
                Toast(err)
            })

        },
        wxPay: function (data ) {
            //获取后台传入的数据
            let appId = data.appId
            let timestamp = data.timeStamp
            let nonceStr = data.nonceStr
            let signature = data.signature
            let packageValue = data.package
            let paySign = data.paySign
            let signType = data.signType
            const that = this
            //下面要发起微信支付了
            wx.config({
                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                appId: appId, // 必填，公众号的唯一标识
                timestamp: timestamp, // 必填，生成签名的时间戳
                nonceStr: nonceStr, // 必填，生成签名的随机串
                signature: signature, // 必填，签名，见附录1
                jsApiList: ['chooseWXPay'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
            })
            wx.ready(function () {
                wx.chooseWXPay({
                    timestamp: timestamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
                    nonceStr: nonceStr, // 支付签名随机串，不长于 32 位
                    package: packageValue, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=***）
                    signType: signType, // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
                    paySign: paySign, // 支付签名
                    success: function (res) {
                        // 支付成功后的回调函数
                        that.$router.push('/payment/callback/'+that.order.orderSn)
                    },
                    fail: function (res) {
                        //失败回调函数
                        Toast('支付失败')
                    }
                })
            })
            wx.error(function (res) {
                console.log('微信支付失败',res)
                Toast('支付失败')
                // config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名。
                /*alert("config信息验证失败")*/
            })
        }

    }
};


<|start_filename|>linjiashop-admin/src/api/shop/category.js<|end_filename|>
import request from '@/utils/request'

export default {

  getList: function (params) {
    return request({
      url: '/shop/category/list',
      method: 'get',
      params
    })
  },

  getCategories: function () {
    return request({
      url: '/shop/category/getAll',
      method: 'get'
    })
  },

  getBanners: function (id) {
    return request({
      url: '/shop/category/getBanners/' + id,
      method: 'get'
    })
  },
  getAttrKeys: function (id) {
    return request({
      url: '/shop/category/getAttrKeys/' + id,
      method: 'get'
    })
  },
  save: function (params) {
    return request({
      url: '/shop/category',
      method: 'post',
      params
    })
  },
  remove: function (id) {
    return request({
      url: '/shop/category',
      method: 'delete',
      params: {
        id: id
      }
    })
  },
  removeBanner: function (id, idBanner) {
    return request({
      url: '/shop/category/removeBanner/' + id + '/' + idBanner,
      method: 'delete'
    })
  },
  setCategoryBanner: function (id, idBanner) {
    return request({
      url: '/shop/category/setBanner/' + id + '/' + idBanner,
      method: 'post'
    })
  }
}


<|start_filename|>linjiashop-admin/src/views/cms/banner/banner.js<|end_filename|>
import { remove, getList, save } from '@/api/cms/banner'
import categoryApi from '@/api/shop/category'
import { getToken } from '@/utils/auth'
import { Loading } from 'element-ui'
import { getApiUrl } from '@/utils/utils'
import permission from '@/directive/permission/index.js'
export default {
  directives: { permission },
  data() {
    return {
      uploadUrl: '',
      uploadFileId: '',
      uploadHeaders: {
        'Authorization': ''
      },
      loadingInstance: {},
      formVisible: false,
      formTitle: '添加banner',
      deptList: [],
      isAdd: true,
      options: [
        { label: '首页', value: 'index' },
        { label: '新闻', value: 'news' },
        { label: '产品', value: 'product' },
        { label: '解决方案', value: 'solution' },
        { label: '案例', value: 'case' }
      ],
      form: {
        id: '',
        title: '',
        page: '',
        param: '',
        img: '',
        idFile: '',
        type: 'index'
      },
      listQuery: {
        title: undefined
      },
      list: null,
      listLoading: true,
      selRow: {},
      shopCategory:{
        id:undefined,
        show:false,
        disabled:true
      }
    }
  },
  computed: {
    rules() {
      return {
        title: [
          { required: true, message: '标题不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.shopCategory.id = this.$route.query.idCategory
    this.init()
  },
  methods: {
    init() {
      this.uploadUrl = getApiUrl() + '/file'
      this.uploadHeaders['Authorization'] = getToken()
      this.fetchData()
      if(this.shopCategory.id){
        this.shopCategory.show = true
      }
    },
    fetchData() {
      this.listLoading = true
      getList(this.listQuery).then(response => {
        this.list = response.data
        for (var index in this.list) {
          let item = this.list[index]
          item.img = getApiUrl() + '/file/getImgStream?idFile=' + item.idFile
        }

        this.listLoading = false
      })
    },
    search() {
      this.listQuery.page = 1
      this.fetchData()
    },
    reset() {
      this.listQuery.title = ''
      this.listQuery.page = 1
      this.fetchData()
    },
    handleFilter() {
      this.getList()
    },
    handleCurrentChange(currentRow, oldCurrentRow) {
      this.selRow = currentRow
    },
    resetForm() {
      this.form = {
        id: '',
        title: '',
        page: '',
        param: '',
        idFile: this.uploadFileId,
        type: ''
      }
    },
    add() {
      this.resetForm()
      this.formTitle = '添加banner'
      this.formVisible = true
      this.isAdd = true
    },
    save() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          save({
            id: this.form.id,
            title: this.form.title,
            page: this.form.page,
            param: this.form.param,
            idFile: this.uploadFileId,
            type: this.form.type
          }).then(response => {
            this.$message({
              message: this.$t('common.optionSuccess'),
              type: 'success'
            })
            this.fetchData()
            this.formVisible = false
          })
        } else {
          return false
        }
      })
    },
    checkSel() {
      if (this.selRow && this.selRow.id) {
        return true
      }
      this.$message({
        message: this.$t('common.mustSelectOne'),
        type: 'warning'
      })
      return false
    },
    clickRow(row){
      this.shopCategory.disabled=false
      this.shopCategory.idBanner = row.id
    },
    setBanner(){
      if( this.shopCategory.idBanner) {
        categoryApi.setCategoryBanner(this.shopCategory.id, this.shopCategory.idBanner).then(response => {
          this.$message({
            message: '设置成功',
            type: 'success'
          })
          this.shopCategory.disabled = true
        })
      }else{
        this.$message({
          message: '请先选中要设置的banner',
          type: 'warning'
        })
      }
    },
    remove() {
      if (this.checkSel()) {
        var id = this.selRow.id
        this.$confirm(this.$t('common.deleteConfirm'), this.$t('common.tooltip'), {
          confirmButtonText: this.$t('button.submit'),
          cancelButtonText: this.$t('button.cancel'),
          type: 'warning'
        }).then(() => {
          remove(id).then(response => {
            this.$message({
              message: this.$t('common.optionSuccess'),
              type: 'success'
            })
            this.fetchData()
          })
        }).catch(() => {
        })
      }
    },
    handleBeforeUpload() {
      if (this.uploadFileId !== '') {
        this.$message({
          message: this.$t('common.mustSelectOne'),
          type: 'warning'
        })
        return false
      }
      this.loadingInstance = Loading.service({
        lock: true,
        text: this.$t('common.uploading'),
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
    },
    handleUploadSuccess(response, raw) {
      this.loadingInstance.close()
      if (response.code === 20000) {
        this.uploadFileId = response.data.realFileName
        this.form.fileName = response.data.originalFileName
      } else {
        this.$message({
          message: this.$t('common.uploadError'),
          type: 'error'
        })
      }
    }
  }
}
