PHP code example of tiderjian / qscmf

1. Go to this page and download the library: Download tiderjian/qscmf library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tiderjian / qscmf example snippets


composer create-project tiderjian/qscmf qscmf

php index.php Qscmf/UpgradeFix/v300FixSchedule/queue/default maintenance

   // ChapterModel类必须继承接口
   class ChapterModel  extends \Gy_Library\GyListModel implements \Qscmf\Lib\Elasticsearch\ElasticsearchModelContract{
   
      // ElasticsearchHelper已经实现了一些帮助函数
      use \Qscmf\Lib\Elasticsearch\ElasticsearchHelper;
   
      // 初始化全文索引时需要指定该Model要添加的索引记录
      public function elasticsearchIndexList()
      {
           // 如这里chapter表与course表关联,只有当course及chapter状态都为可用,且非描述类chapter(pid = 0为描述类chapter)才会添加全文索引
          return $this->alias('ch')->join('__COURSE__ c ON c.id=ch.course_id and c.status = ' . DBCont::NORMAL_STATUS)->where(['ch.status' => DBCont::NORMAL_STATUS, 'ch.pid' => ['neq', 0]])->field('ch.*')->select();
      }
   
      // chapter进行增删查改时同时会更新索引内容,该方法是指定什么状态的记录才会进行索引更改
      // 返回false为无需索引的记录,true则会进行索引更新
      public function isElasticsearchIndex($ent){
          if($ent['status'] != DBCont::NORMAL_STATUS || $ent['pid'] == 0){
              return false;
          }
   
          $course_ent = D('Course')->find($ent['course_id']);
          if($course_ent['status'] == DBCont::NORMAL_STATUS){
              return true;
          }
          else{
              return false;
          }
      }
   
      // 程序会自动生成索引的配置参数,此处是定义生成参数的规则
      // 以:开头的字母表示该处会自动替换成相应字段的实际值
      // {}表示里面的字符会与替换后的:字段值进行连接,如:id{_chapter}, id实际值为 12,则该处会替换成 12_chapter
      // | 表示可以将字段的实际值传递给指定的函数进行处理,转换成想要的值。如,description字段是富文本内容,我们将html标签进行索引,可以在model方法里自定义一个叫deleteHtmlTag的方法进行处理,当然也可以定义为全局函数,程序会先查找全局是否存在该函数,如果没有再去对象里查找有无该方法
     // index和type的值在建立初始化全文索引时指定,具体查看全文索引初始化说明
      public function elasticsearchAddDataParams()
      {
          return [
              'index' => 'global_search',
              'type' => 'content',
              'id' => ':id{_chapter}',
              'body' => [
                  'title' => ':title',
                  'desc' => ':description|html_entity_decode'
              ]
          ];
      }
   }
   

class CreateTestTable extends Migration
{

    public function beforeCmmUp()
    {
        echo "执行前置命令" . PHP_EOL;
    }

    public function beforeCmmDown()
    {
        echo "执行前置回滚命令" . PHP_EOL;
    }

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('test', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('test');
    }

    public function afterCmmUp()
    {
        echo "执行后置命令" . PHP_EOL;
    }

    public function afterCmmDown()
    {
        echo "执行后置回滚命令" . PHP_EOL;
    }
}

php artisan migrate --no-cmd

php artisan migrate:rollback --no-cmd

php artisan migrate:fresh --no-cmd

php artisan migrate:refresh --no-cmd

php artisan migrate:reset --no-cmd

  > $process = new \Larafortp\CmmMigrate\CmmProcess();
  > //timeout为程序的超时退出时间,默认60秒
  > $process->setTimeOut(100)->callTp('/var/www/move/www/index.php', '/home/index/test');
  > 

    <script src="__PUBLIC__/libs/log.js"></script>
    <script>
      frontLog({
        url:'/api/jsLog/index'
      });
    </script>

    $wx_info=Qscmf\Lib\WeixinLogin::getInstance()->getInfoForMobile();
  

  $wx_info=json_decode(session('wx_info'),true);
  // 若用户表为member表
  $member=D('Member')->where(['openid'=>$wx_info['id']])->find();
  if ($member){
    //登录
    session('mid',$member['id']);
  }else{
    //注册
    $ent=[
        'openid'=>$wx_info['id'],
        'nickname'=>$wx_info['nickname']
    ];
    $r=D('Member')->createAdd($ent);
    if ($r===false){
        E(D('Member')->getError());    
    }
    session('mid',$r);
  }
  redirect(U('home/user/index'));
  

    $wx_info=Qscmf\Lib\WeixinLogin::getInstance()->getInfoForMobile();
    if ($wx_info){
        redirect(U('/home/index/wxLogin'));    
    }   
   

   // 与PC端扫码后登录/注册业务处理一致
   

<input type="hidden" id="hidden_position" name="city_id" value="{$city_id}">

<block name="script">
<script type="text/javascript" src="__PUBLIC__/libs/addrSelect/selectAddr.js"></script>
<script>
    jQuery(document).ready(function() {
        $('#hidden_position').selectAddr({
            addressLevel: ['省','市','区'],
            level: 3,
            onSelected: function (val,changeEle){
                log(val);
            }
        });

        function log(str) {
            console.log(str+"-111");
        }    
    });
</script>
</block>

// config.php文件加入以下配置
// 只需要配置自定义的 layout 路径
'QS_INJECT_LAYOUT_PATH' => [
    T('Admin@default/common/letter/layout')
]

        class HeicToJpgBehavior{
  
        public function run(&$params)
        {
            // $params为qs_file_pic的一条数据
            // 具体逻辑
            $params['url'] = 'your new url';           
        }
    
        }
      

      \Think\Hook::add('heic_to_jpg', 'xxx\\HeicToJpgBehavior');
      

php artisan migrate

   //进入app目录,下面有个makeIndex.php文件
   php makeIndex.php
   
blade
select框的地址选择器

参数 
addressLevel: array 省/市/县的select框默认值,默认为:['选择省','选择市','选择区']
level: int 1|2|3 地址的等级:省/市/区,默认为:3
url: array 分别获取地址的接口url,默认为:['/api/area/getProvince.html','/api/area/getCityByProvince.html','/api/area/getDistrictByCity.html']
onSelected: function (val,changeEle){}  每个select框选择地址后执行自定义function,val: 隐藏域的值 changeEle: 触发事件的select