微擎学习随记_常用功能实现

微擎学习随记_常用功能实现

消息通知:

代码位置:

addons/项目名/core/model/notice.php(设置微信信息通知和微信模板消息通知)

需求:

店铺得到收益之后以消息的形式通知店铺

步骤:

1、在notice.php中,加入我们通知方法

2、在用户支付的时候调用该代码,通知商户

代码:

// notice 中 
public function league_get_income($order){
        //查询门店信息
        $store = pdo_get('ccnb_shop_store',['id'=> $order['storeid']]);
        $sql =  "select SUM(price*(100-payrate)/100) from ".tablename('ccnb_shop_order')."  where uniacid = {$store['uniacid']} and is_league = 1 and storeid = {$store['id']} and status = 3";
        $sumMoney = pdo_fetchcolumn($sql);
        // 拼接消息信息
        $sumMoney = round($sumMoney,2); // 保留两位小数
        $getMoney = round($order['price'] *(100 - $order['payrate'])/100,2);
        $datas = [];
        $text = "【{$store['storename']}】 您有新的款项入账:成功支付{$order['price']}元,到账{$getMoney}元,累计收益{$sumMoney}元";
        $message = array(
            'first'    => array('value' => '您的有新的款项入账' . "\n", 'color' => '#ff0000')
        );
        // 发送消息信息
        $this->sendNotice(array('openid' => $store['openid'], 'tag' => 'getIncom', 'default' => $message, 'cusdefault' => $text, 'url' => '', 'datas' => $datas, 'appurl' => ''));
        com_run('sms::callsms', array('tag' => 'enterExpire', 'datas' => $datas, 'openid' => $store['openid']));
    }

注意:

// 具体底层调用方式还不太清楚

通知是通过openid来进行对应用用户的通知,通知底层有两种方式:

1、模板消息 :模板消息需要的内容比较多

2、微信消息:微信消息只需要配置消息内容就好了。

底层首先调用微信消息,在微信消息调用不成功的情况下调用模板消息。(微信消息在用户登录48小时内,用户可以收到)

权限设置:

代码位置:

addons/ccnb_shopv3/core/com/perm.php

需求:

为后台商家管理/动态消息管理添加管理权限;

步骤:

1、找到权限的最外层模块(这个对路径要求很严格)

2、在模块内对应的位置添加管理字段

代码:

// .....(代码省略)
$perms = array(...'shop' => $this->perm_shop(), 'store' => $this->perm_store(), 'finance' => $this->perm_finance()...);
// .....(代码省略)
// 权限添加代码
$perm = array(
            'text' => '门店管理',
            'main' => '浏览列表',
            'view' => '查看详情',
            'add' => '添加-log',
            'edit' => '修改-log',
            'delete' => '删除-log',
            // 'set' => '关键词设置-log',
            'set' => array(...
            'saler' => array('text' => '店员管理', 'main' => '查看列表', 'add' => '添加-log', 'edit' => '修改-log', 'view' => '查看', 'delete' => '删除-log'),
            'integral_role' => array('text' => '积分规则设置', 'main' => '查看列表', 'add' => '添加-log', 'edit' => '修改-log', 'view' => '查看', 'delete' => '删除-log'),
            'audit' => array('text' => '商家审核', 'main' => '查看列表', 'add' => '添加-log', 'edit' => '修改-log', 'view' => '查看', 'delete' => '删除-log'),
            'message' => array('text' => '消息', 'main' => '查看列表','delete' => '删除-log'),
            'trends' => array('text' => '动态消息管理', 'main' => '查看列表','delete' => '删除-log'...),
        );
// html 中根据删除权限显示删除按钮
 {ifp 'store.message.delete'}
      <a class='btn btn-default btn-sm btn-op btn-operation'  data-toggle='ajaxRemove' href="{php echo webUrl('store/message/delete', array('id' => $row['id']))}" data-confirm="确认删除此分类吗?">
           <span data-toggle="tooltip" data-placement="top" title="" data-original-title="删除">
                <i class='icow icow-shanchu1'></i>
           </span>
       </a>
  {/if}

注意:

{ifp 'store.message.delete'} 这里的路径很严格,要好好看路径

后台添加模块

代码位置

addons/项目名/core/model/system.php/initRightMenu

需求:

在后台添加动态消息管理模块

步骤:

1、在后台管理模块的配置代码里面添加对应模块(路径很严格)

2、根据路径在对应的文件夹下写php和html代码

代码

// ...代码省略
'store' => array(
                'title' => '商家联盟', //cc_zhong
                'subtitle' => '新零售', //cc_zhong
                'icon' => 'store',
                'pos'=>2,
                'class'=>"three",
                'items' => array(
                    array(
                        'title' => '商家管理',
                        'items' => array(
                            array(
                                'title' => '商家管理',
                                'route' => '',
                                'extends' => array('store.diypage.settings', 'store.diypage.page', 'store.goods', 'store.goods.goodsoption')
                            ),
                            array('title' => '店员管理', 'route' => 'saler'),
                            array('title' => '关键词设置', 'route' => 'set'),
                            array('title' => '合作设置', 'route' => 'set.cooperation'),
                            array('title' => '积分规则设置', 'route' => 'integral_role'),
                            array('title' => '商家审核', 'route' => 'audit'),
                            array('title' => '消息', 'route' => 'message'),
                            array('title' => '动态消息管理', 'route' => 'trends'),
                        )
                    )
// ...代码省略                    
                    
// 对应模块下添加对应的功能
....
                    

图片上传和加载

代码位置:

html:addons/项目名/template/mobile/default/store_admin/trends/add_trends.html

js:addons/项目名/template/mobile/default/static/js/cjh/store_admin/trends.js

php:addons/ccnb_shopv3/core/mobile/store_admin/trends.php

需求:

上传图片到服务器,并将图片链接保存至数据库

步骤:

1、在html中加入图片上传的input控件,配置对应的属性和id

2、js中配置图片上传的方法,调用底层上传图片的基础方法

3、通过ajax将上传的图片通过后台保存至服务器

代码

// html中上传图片方法
<div class="shop_photos">
<input type="hidden" name="thumbs" value="" id="thumbs">
<div class="shop_photos_title">动态消息图片(1)</div>
<div class="img-box full z_photo"
    style="width: 100%;padding-bottom: 10%;overflow: hidden;">
        <section class=" img-section"
            style="float: left;margin-left: 2%;margin-top: 8px;">
        <div class=" upimg-div clear">
        <section class="z_file fl">
            <img src="{php echo IMG_PATH}icon_imgadd.png" class="add-img">
            <input type="file" name="thumbsimg" id="thumbs_img"
            class="file thumbs_img" accept="image/*" multiple>
        </section>
    </div>
</section>
</div>
<aside class="mask works-mask">
    <div class="mask-content">
        <p class="del-p">确定删除图片</p>
        <p class="check-p"><span class="del-com wsdel-ok">确定</span><span
        class="wsdel-no">取消</span></p>
    </div>
</aside>
</div>
//js中上传图片的方法
$(".thumbs_img").change(function(){     uploadimg($(this),".z_photo","thumbs_div",1,defaults,"thumbs","thumbsinput") });
​
// js中ajax提交数据至后台方法
 $("#submit").click(function () {
     var thumbs = $('#thumbs').val();
     var content = $('#content').val();
     var storeid = $('#sid').val();
     var data = {
         'thumbs':thumbs,
         'describe':content,
         'storeid':storeid,
     };
​
     //提交
     $.ajax({
         type: 'post',
         url: "./index.php?i=1&c=entry&m=ccnb_shopv3&do=mobile&r=store_admin.trends.add_trends",
         data: data,
         dataType:"json",
         success: function (result){
             if (result.status == 1){
                 $.toast('提交成功');
                 setTimeout(function () {
                     history.back();
                 },2000)
             }else {
                 $.toast(result.result.message);
             }
         }
     })
 })
// 后台存储数据方法
public function add_trends(){
    global $_W;
    global $_GPC;
    $storeid = $_GPC['sid'];
    if($_W['ispost']){
        if(empty($_GPC['describe'])){
            show_json(0,'动态描述不能为空');
        }
        if(strlen($_GPC['describe']) > 60){
            show_json(0,'动态描述不能超过60个字');
        }
        if (empty($_GPC['thumbs'])){
            show_json(0,'列表图不能为空');
        }
        $data = [
            'thumb'=>$_GPC['thumbs'],
            'describe' =>$_GPC['describe'],
            'storeid' =>$_GPC['storeid'],
            'createtime' =>TIMESTAMP,
        ];
        $up = $result = pdo_insert('ccnb_shop_store_trends', $data);
​
        if ($up){
            show_json(1);
        }else{
            show_json(0,'提交失败');
        }
    }
​
    include $this->template();
}

注意:

上传图片在底层代码通过ajax上传至服务器之后,自动填充了我们的图片标签

列表加载和分页

代码位置:

html:addons/项目名/template/mobile/default/store_admin/trends/index.html

js:addons/项目名/template/mobile/default/static/js/cjh/zpc.js

php:addons/项目名/core/mobile/store_admin/trends.php

需求:

请求动态消息列表并展示

步骤:

1、在html中加入列表展示标签

2、在html中加入要渲染的每条item样式

3、在js中通过ajax去拉取列表信息

4、后台提供拉取接口

代码:

// 列表
<div class="page" id="get_trend">
    <div class="content infinite-scroll" data-distance="100" >
        <input type="hidden" id="storeid" value="{$store['id']}">
        <div class="dynamics_top">
            <span class="dongtai">店铺动态</span>
            <a href="{php echo mobileUrl('store_admin/trends/add_trends').'&sid='.$store['id']}">
                <span class="add">添加</span>
            </a>
        </div>
​
        <div class="list-block media-list" id="content">
            <ul v-for="li in list">
                <li class="dynamics_wp" >
                    <div class="item-content">
                        <div class="item-media">
                            <img :src="li.thumb" style='width:7rem;'></div>
                        <div class="item-inner">
                            <div class="item-title-row">
                                <div class="dynamics_title">
                                    {{li.describe}}
                                </div>
                            </div>
                            <div class="dynamics_time"> {{li.createtime}}</div>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
        <div ></div>
    </div>
</div>

 

​
// 店铺动态列表拉取
$(document).on("pageInit", "#get_trend", function(e,id,page){
    var pages = 1;
    var loading = false;
    var pagesize = 10;
    var tab = 1;
    //获取数据
    function list(page) {
        var storeid = $("#storeid").val();
        $.ajax({
            type:'post',
            url:'./index.php?i=1&c=entry&m=ccnb_shopv3&do=mobile&r=store_admin.trends.store_trend_list',
            data:{'storeid':storeid,'page':page,'pagesize':pagesize},
            dataType:'json',
            success:function (res) {
                console.log(res);
                if (res.status == 1){
                    loading =false;
​
                    var list = res.result.list;
                    if (list.length > 0){
                        for (var i = 0; i <list.length; i++){
                            zpc.list.push(list[i]);
                        }
                    }
​
                    if (list.length < pagesize){
                        $(".infinite-scroll-preloader").remove();
                        $(".line").remove();
                        var tem = '<div class="line" style="margin: 0 auto;width: 150px;text-align: center;padding-top: 20px;"><span slot="no-more">我们是有底线的</span></div>';
                        $('.busine_ul1').append(tem);
                    }
                }else {
                    loading = true;
                    $(".infinite-scroll-preloader").remove();
                    $(".line").remove();
                    var tem = '<div class="line" style="margin: 0 auto;width: 150px;text-align: center;padding-top: 20px;"><span slot="no-more">我们是有底线的</span></div>';
                    $('.busine_ul1').append(tem);
                }
            }
        })
    }
    var zpc = new Vue({
        el:'#content',
        data:{
            list:[]
        },
        created:function () {
            list(pages);
        },
        methods:{
        }
    })
​
    //上拉刷新
    $(document).on('infinite', '.infinite-scroll',function() {
        if (loading) return;
        loading = true;
        pages++;
        list(pages);
    });
})
​
/**
* 添加动态
*/
public function add_trends(){
    global $_W;
    global $_GPC;
    $storeid = $_GPC['sid'];
    if($_W['ispost']){
        if(empty($_GPC['describe'])){
            show_json(0,'动态描述不能为空');
        }
        if(strlen($_GPC['describe']) > 60){
            show_json(0,'动态描述不能超过60个字');
        }
        if (empty($_GPC['thumbs'])){
            show_json(0,'列表图不能为空');
        }
        $data = [
            'thumb'=>$_GPC['thumbs'],
            'describe' =>$_GPC['describe'],
            'storeid' =>$_GPC['storeid'],
            'createtime' =>TIMESTAMP,
        ];
        $up = $result = pdo_insert('ccnb_shop_store_trends', $data);
​
        if ($up){
            show_json(1);
        }else{
            show_json(0,'提交失败');
        }
    }
    include $this->template();
}

 

 

 

 

 

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值