thinkphp lists todo

这篇具有很好参考价值的文章主要介绍了thinkphp lists todo。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

来由:

thinkphp lists todo,前端,服务器,php

数据库的这个字段我想返回成:thinkphp lists todo,前端,服务器,php

新奇的写法如下:

逻辑层的代码:

  public function goodsDetail($goodId)
    {
        $detail = $this->good->where('id', $goodId)->hidden(['type_params','user_id'])->find();
        if (!$detail) {
            return $this->fail("获取数据失败!");
        }
        if ($detail->type === 1) {

            //特殊的写法
            $detail->award_lists = '';
        } else if ($detail->type === 2) {
            $number_group_buyer = Order::where('good_id', $goodId)->where('status',1)->count('id');
            $detail->number_group_buyers = $number_group_buyer;
        }

        return $this->success("获取数据成功", $detail);

    }

模型层的代码:

<?php

namespace app\daogou\model;

use app\common\model\TimeModel;

class Goods extends TimeModel
{
    protected $table = 'dg_goods';

    protected $type = [
        'type_params'=>'json',
    ];



    //type_params:
    //      type = 1 : [['coin_id'=>1,'award'=>"0.80000000"],……]
    //      type = 2 : ['max_number'=>10,'winner'=>1]
    //      type = 3 : null

    public function user()
    {
        return $this->hasOne('user','user_id','id')->bind(['username']);
    }

    public function getStatusTxtAttr($v,$data)
    {
        //状态(-1:下架,1:上架,2:交易中)
        $status = [-1=>"下架",1=>"上架",2=>"交易中"];
        if(array_key_exists('status',$data)){
            return array_key_exists($data['status'],$status) ? $status[$data['status']] : $data['status'];
        }
        return '';
    }


    public function getPriceAttr($v)
    {
        return delZero($v);
    }
    public function getTypeTxtAttr($v,$data){
        //(1:奖购2:团购,3:闪购)
        $status = [1=>"奖购",2=>"团购",3=>"闪购"];
        if(array_key_exists('type',$data)){
            return array_key_exists($data['type'],$status) ? $status[$data['type']] : $data['type'];
        }
        return '';
    }




// 不理解的代码
    public function getAwardListsAttr($v, $good)
    {
        $awardLists = [];
        if ($good['type'] === 1) {
            $type_params = json_decode($good['type_params'],true);
            foreach ($type_params as $propertyId => $properNumber) {
                $propertyName = Coin::where('id', $propertyId)->value('name');
                $award['asset_name'] = $propertyName;
                $award['asset_number'] = $properNumber;
                array_push($awardLists,$award);
            }
        }
        return $awardLists;
    }



}

可以通过  :

$ba = debug_backtrace();
var_dump($ba);
die();

来查看执行的流程,,流程如下(个人感觉看起来 【展示的效果】 不是很友好 很乱的感觉 ):

array(8) {
  [0]=>
  array(7) {
    ["file"]=>
    string(66) "D:\wwwroot\yyex\thinkphp\library\think\model\concern\Attribute.php"
    ["line"]=>
    int(500)
    ["function"]=>
    string(17) "getAwardListsAttr"
    ["class"]=>
    string(22) "app\daogou\model\Goods"
    ["object"]=>
    object(app\daogou\model\Goods)#58 (2) {
      ["data"]=>
      array(14) {
        ["id"]=>
        int(14)
        ["user_id"]=>
        int(2)
        ["type"]=>
        int(1)
        ["name"]=>
        string(14) "仙侠小说ss"
        ["photo"]=>
        string(20) "http://ff12.ffsky.cn"
        ["price"]=>
        string(6) "102.30"
        ["introduction"]=>
        string(5) "ccsss"
        ["phone"]=>
        string(11) "13246885231"
        ["type_params"]=>
        string(9) "{"20":22}"
        ["status"]=>
        int(1)
        ["create_time"]=>
        int(1701844614)
        ["update_time"]=>
        int(1701844614)
        ["remark"]=>
        NULL
        ["award_lists"]=>
        string(0) ""
      }
      ["relation"]=>
      array(0) {
      }
    }
    ["type"]=>
    string(2) "->"
    ["args"]=>
    array(2) {
      [0]=>
      string(0) ""
      [1]=>
      array(14) {
        ["id"]=>
        int(14)
        ["user_id"]=>
        int(2)
        ["type"]=>
        int(1)
        ["name"]=>
        string(14) "仙侠小说ss"
        ["photo"]=>
        string(20) "http://ff12.ffsky.cn"
        ["price"]=>
        string(6) "102.30"
        ["introduction"]=>
        string(5) "ccsss"
        ["phone"]=>
        string(11) "13246885231"
        ["type_params"]=>
        string(9) "{"20":22}"
        ["status"]=>
        int(1)
        ["create_time"]=>
        int(1701844614)
        ["update_time"]=>
        int(1701844614)
        ["remark"]=>
        NULL
        ["award_lists"]=>
        string(0) ""
      }
    }
  }
  [1]=>
  array(7) {
    ["file"]=>
    string(67) "D:\wwwroot\yyex\thinkphp\library\think\model\concern\Conversion.php"
    ["line"]=>
    int(179)
    ["function"]=>
    string(7) "getAttr"
    ["class"]=>
    string(11) "think\Model"
    ["object"]=>
    object(app\daogou\model\Goods)#58 (2) {
      ["data"]=>
      array(14) {
        ["id"]=>
        int(14)
        ["user_id"]=>
        int(2)
        ["type"]=>
        int(1)
        ["name"]=>
        string(14) "仙侠小说ss"
        ["photo"]=>
        string(20) "http://ff12.ffsky.cn"
        ["price"]=>
        string(6) "102.30"
        ["introduction"]=>
        string(5) "ccsss"
        ["phone"]=>
        string(11) "13246885231"
        ["type_params"]=>
        string(9) "{"20":22}"
        ["status"]=>
        int(1)
        ["create_time"]=>
        int(1701844614)
        ["update_time"]=>
        int(1701844614)
        ["remark"]=>
        NULL
        ["award_lists"]=>
        string(0) ""
      }
      ["relation"]=>
      array(0) {
      }
    }
    ["type"]=>
    string(2) "->"
    ["args"]=>
    array(1) {
      [0]=>
      string(11) "award_lists"
    }
  }
  [2]=>
  array(7) {
    ["file"]=>
    string(67) "D:\wwwroot\yyex\thinkphp\library\think\model\concern\Conversion.php"
    ["line"]=>
    int(250)
    ["function"]=>
    string(7) "toArray"
    ["class"]=>
    string(11) "think\Model"
    ["object"]=>
    object(app\daogou\model\Goods)#58 (2) {
      ["data"]=>
      array(14) {
        ["id"]=>
        int(14)
        ["user_id"]=>
        int(2)
        ["type"]=>
        int(1)
        ["name"]=>
        string(14) "仙侠小说ss"
        ["photo"]=>
        string(20) "http://ff12.ffsky.cn"
        ["price"]=>
        string(6) "102.30"
        ["introduction"]=>
        string(5) "ccsss"
        ["phone"]=>
        string(11) "13246885231"
        ["type_params"]=>
        string(9) "{"20":22}"
        ["status"]=>
        int(1)
        ["create_time"]=>
        int(1701844614)
        ["update_time"]=>
        int(1701844614)
        ["remark"]=>
        NULL
        ["award_lists"]=>
        string(0) ""
      }
      ["relation"]=>
      array(0) {
      }
    }
    ["type"]=>
    string(2) "->"
    ["args"]=>
    array(0) {
    }
  }
  [3]=>
  array(5) {
    ["function"]=>
    string(13) "jsonSerialize"
    ["class"]=>
    string(11) "think\Model"
    ["object"]=>
    object(app\daogou\model\Goods)#58 (2) {
      ["data"]=>
      array(14) {
        ["id"]=>
        int(14)
        ["user_id"]=>
        int(2)
        ["type"]=>
        int(1)
        ["name"]=>
        string(14) "仙侠小说ss"
        ["photo"]=>
        string(20) "http://ff12.ffsky.cn"
        ["price"]=>
        string(6) "102.30"
        ["introduction"]=>
        string(5) "ccsss"
        ["phone"]=>
        string(11) "13246885231"
        ["type_params"]=>
        string(9) "{"20":22}"
        ["status"]=>
        int(1)
        ["create_time"]=>
        int(1701844614)
        ["update_time"]=>
        int(1701844614)
        ["remark"]=>
        NULL
        ["award_lists"]=>
        string(0) ""
      }
      ["relation"]=>
      array(0) {
      }
    }
    ["type"]=>
    string(2) "->"
    ["args"]=>
    array(0) {
    }
  }
  [4]=>
  array(4) {
    ["file"]=>
    string(56) "D:\wwwroot\yyex\thinkphp\library\think\response\Json.php"
    ["line"]=>
    int(36)
    ["function"]=>
    string(11) "json_encode"
    ["args"]=>
    array(2) {
      [0]=>
      *RECURSION*
      [1]=>
      int(256)
    }
  }
  [5]=>
  array(7) {
    ["file"]=>
    string(51) "D:\wwwroot\yyex\thinkphp\library\think\Response.php"
    ["line"]=>
    int(396)
    ["function"]=>
    string(6) "output"
    ["class"]=>
    string(19) "think\response\Json"
    ["object"]=>
    object(think\response\Json)#57 (8) {
      ["options"]=>
      array(1) {
        ["json_encode_param"]=>
        int(256)
      }
      ["contentType"]=>
      string(16) "application/json"
      ["data"]=>
      *RECURSION*
      ["charset"]=>
      string(5) "utf-8"
      ["code"]=>
      int(200)
      ["allowCache"]=>
      bool(true)
      ["header"]=>
      array(1) {
        ["Content-Type"]=>
        string(31) "application/json; charset=utf-8"
      }
      ["content"]=>
      NULL
    }
    ["type"]=>
    string(2) "->"
    ["args"]=>
    array(1) {
      [0]=>
      *RECURSION*
    }
  }
  [6]=>
  array(7) {
    ["file"]=>
    string(51) "D:\wwwroot\yyex\thinkphp\library\think\Response.php"
    ["line"]=>
    int(128)
    ["function"]=>
    string(10) "getContent"
    ["class"]=>
    string(14) "think\Response"
    ["object"]=>
    object(think\response\Json)#57 (8) {
      ["options"]=>
      array(1) {
        ["json_encode_param"]=>
        int(256)
      }
      ["contentType"]=>
      string(16) "application/json"
      ["data"]=>
      *RECURSION*
      ["charset"]=>
      string(5) "utf-8"
      ["code"]=>
      int(200)
      ["allowCache"]=>
      bool(true)
      ["header"]=>
      array(1) {
        ["Content-Type"]=>
        string(31) "application/json; charset=utf-8"
      }
      ["content"]=>
      NULL
    }
    ["type"]=>
    string(2) "->"
    ["args"]=>
    array(0) {
    }
  }
  [7]=>
  array(7) {
    ["file"]=>
    string(32) "D:\wwwroot\yyex\public\index.php"
    ["line"]=>
    int(18)
    ["function"]=>
    string(4) "send"
    ["class"]=>
    string(14) "think\Response"
    ["object"]=>
    object(think\response\Json)#57 (8) {
      ["options"]=>
      array(1) {
        ["json_encode_param"]=>
        int(256)
      }
      ["contentType"]=>
      string(16) "application/json"
      ["data"]=>
      *RECURSION*
      ["charset"]=>
      string(5) "utf-8"
      ["code"]=>
      int(200)
      ["allowCache"]=>
      bool(true)
      ["header"]=>
      array(1) {
        ["Content-Type"]=>
        string(31) "application/json; charset=utf-8"
      }
      ["content"]=>
      NULL
    }
    ["type"]=>
    string(2) "->"
    ["args"]=>
    array(0) {
    }
  }
}
2:异步消息队列:
tp6+异步任务队列+发送邮件+模型监听_tp6异步下载_Upordo的博客-CSDN博客

3:thinkphp6  + workman 实现即使聊天 通讯:

https://www.cnblogs.com/codehaoran/p/16817231.html

PHP聊天室框架workerman-chat

GitHub - walkor/workerman-chat: Websocket chat room written in PHP based on workerman.

前端聊天模板:lemon imui(gitee)

thinkphp :

 文章来源地址https://www.toymoban.com/news/detail-755738.html

think PHP libary  Bootstrap类型

到了这里,关于thinkphp lists todo的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • 前后端服务器分离时,前端如何上传图片到前端服务器?

    当前后端服务器分离时,前端上传图片到前端服务器可以采用以下几种方式: 1. 直接上传到前端服务器:可以通过使用HTML的`input type=\\\"file\\\"`元素,让用户选择图片文件并直接上传到前端服务器。前端服务器可以使用后端提供的API接口处理上传请求,然后将图片保存到前端服务

    2024年04月27日
    浏览(32)
  • 服务器发版(前端如何自己连接服务器发版)

    服务器发版(前端如何自己连接服务器发版)

    1.下载FinalShell远程连接工具 http://www.hostbuf.com/downloads/finalshell_windows_x64.exe 2.打开exe 3.创建连接,SSH连接 4.新建完连接后,快速连接后列表中多了一条数据 5. 6.指令 which nginx 查找nginx文件夹所在位置 找到后cd到nginx 位置 进入nginx下的conf文件夹,找到nginx.conf配置转发 7.cd 到sbin文

    2024年01月17日
    浏览(6)
  • 前端项目部署到服务器

    前端项目部署到服务器

    1.准备工具 服务器:阿里云 腾讯云 华为云都可以 我这里使用的是阿里云ECS共享型(推荐) xshell:用于远程连接服务器,修改配置文件 xftp:用于连接远程服务器,将本地资源上传到远程服务器 2.服务器设置 1.第一次需重置实例密码 2.配置安全组规则 开启常用的端口 22必须要开

    2024年02月04日
    浏览(8)
  • 前端项目部署,阿里云服务器部署前端项目,超详细

    前端项目部署,阿里云服务器部署前端项目,超详细

    需求背景 :作为一个前端,特别身处于中小公司时,对于部署也需要有所了解。本次就介绍前端基础的项目部署。本次使用的是阿里云服务器进行的部署 1.准备打包好的前端代码(dist包)或者是一个html文件 2.购买阿里云服务器,并且连接 3.为阿里云服务器安装ngnix开启web服务

    2024年02月04日
    浏览(28)
  • 腾讯云服务器+宝塔+后端+前端发布

    腾讯云服务器+宝塔+后端+前端发布

    1、申请云服务器。登陆。 https://cloud.tencent.com/   创建实例 最好重置密码,并记住。  配置安全组,当我们是学习的时候,全部开放好了。   有些版本是去“防火墙”那里配置。 轻量应用服务器(试用的)     2、安装Docker。在安装云服务时,我选了Centos7.8+Docker。这里就不

    2024年02月13日
    浏览(9)
  • 前端部署(包括node服务端部署)--手动部署到服务器

    前端部署(包括node服务端部署)--手动部署到服务器

    在阿里云(或者其他厂商)购买域名,有些域名需要备案 接着购买服务器,镜像选择Ubuntu/CentOS的(Linux) 公网带宽的就按使用量来收费:10Mbps(自己使用的话) 系统配置:配置密码 之后购买成功,获得公网ip 初次先进行远程连接,在终端里面:ssh root@公网ip(powershell可以填写ssh了)

    2024年03月25日
    浏览(1)
  • docker在服务器中部署多个前端

    docker在服务器中部署多个前端

            因为要做毕设买了个云服务器玩玩,刚好设做到一半,用用户端和后台两个vue的前端项目部署到服务器上做个测试~         现在阿里云的域名备案有点麻烦,现在就用IP端口号就为访问网址。 在线独立课程题库管理与考试系统 http://8.134.135.177:9528/ exam-user http://8.13

    2024年04月27日
    浏览(4)
  • 使用宝塔面板部署前端项目到服务器

    使用宝塔面板部署前端项目到服务器

    目录 文章目录 前言 一、第一步:创建文件夹 二、第二步:部署前端项目 三、第三步:打开防火墙 前言 第一步:创建文件夹 第二步:部署前端项目 第三步:打开防火墙 总结 在此之前,我们已经创建了宝塔面板账号、拥有了一台服务器。现在,我们想让我们的前端能够像

    2024年02月03日
    浏览(14)
  • SRE之前端服务器的负载均衡

    SRE之前端服务器的负载均衡

    今天和小伙伴们分享一些 前端服务器 的 负载均衡 技术 内容为结合 《 SRE Google运维解密》 整理: 涉及DNS 负载均衡 VIP 负载均衡 反向代理负载均衡 理解不足小伙伴帮忙指正 傍晚时分,你坐在屋檐下,看着天慢慢地黑下去,心里寂寞而凄凉,感到自己的生命被剥夺了。当时我

    2024年02月13日
    浏览(7)
  • 前端如何将项目打包部署到服务器

    前端如何将项目打包部署到服务器

      本篇文章从前端项目打包开始,逐步完成项目部署到服务器的操作,这次咱们采取的部署方案是通过vscode中Remote-SSH和SFTP两个插件实现项目部署到服务器,并在服务器上通过nginx代理将请求转发到对应的端口。   先将自己开发完成的本地项目进行打包,打包之后会产生一个

    2024年03月14日
    浏览(14)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包