<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                在表對應的模型文件中,有2個可以設置的固定字段,就是說提交的字段不用設置,只要表中有這兩個同名的字段就可以自動插入時間, 創建時間、更新時間;格式可以指定 系統支持自動寫入創建和更新的[時間戳](https://so.csdn.net/so/search?q=%E6%97%B6%E9%97%B4%E6%88%B3&spm=1001.2101.3001.7020)字段(默認關閉),有兩種方式配置支持。 第一種方式是全局開啟,在數據庫配置文件中進行設置: ~~~javascript // 開啟自動寫入時間戳字段 'auto_timestamp' => true, ~~~ 第二種是在需要的模型類里面單獨開啟: ``` <?php namespace app\model; use think\Model; class User extends Model { protected $autoWriteTimestamp = true; ``` 支持動態關閉時間戳寫入功能,例如你希望更新閱讀數的時候不修改更新時間,可以使用`isAutoWriteTimestamp`方法: ``` $user = User::find(1); $user->read +=1; $user->isAutoWriteTimestamp(false)->save(); ``` # 例子: ``` protected $autoWriteTimestamp = 'int';//指定數字格式 protected $createTime = 'time';//創建時間 // protected $updateTime = 'utime';//更新時間 ``` 字段名稱也可換成自己的設置 # 實際例子: ### 1.分布式數據庫插入多表數據,有事務需要回滾 調用: ``` //引用 use app\services\table\model\Guestbook; //靜態調用 $returnData = Guestbook::saveGuestbook($postdata); ``` 表對應模型文件代碼: ``` <?php namespace app\services\table\model; use think\Model; use think\facade\Db; use app\services\table\validate\GuestbookValidate; class Guestbook extends Model { protected $name = 'guestbook'; //表名 protected $connection = 'enterprise_cold';//數據庫的連接 protected $autoWriteTimestamp = 'int'; protected $createTime = 'time'; // protected $updateTime = 'utime'; // 設置字段信息 protected $schema = [ 'id' => 'int', 'uid' => 'bigint',//(唯一:前端用戶取得電腦MAC轉為十制進數字) 'enterprise_id' => 'int', 'phone' => 'string', 'username' => 'string', 'content' => 'string', 'gid' => 'int', 'sid' => 'int', 'wx' => 'string', 'email' => 'string', 'qq' => 'int', 'url' => 'string', 'ip' => 'string', 'type' => 'int', 'hide' => 'int', 'deleted' => 'int', 'deleted_time' => 'int', 'deleted_userid' => 'int', 'time' => 'int', ]; /** * @name 保存訪客提交過來的留言 * @method Model * @date 2021-11-19 * @param 1 $postdata arr/必填 提交數組 * @ruturn array */ static public function saveGuestbook(array $postdata) { Db::connect('enterprise_cold')->startTrans(); Db::connect('enterprise_heat')->startTrans(); try { $postdata['enterprise_id'] = !empty($postdata['eid'])?$postdata['eid']:0; validate(GuestbookValidate::class)->scene('onlineserviceApi_tel')->check($postdata); // $eid = !empty($postdata['enterprise_id'])?$postdata['enterprise_id']:0; $enterpriseData = numberEncodeDecodeHashids('enterprise',$postdata['enterprise_id'],1);//解密 if($enterpriseData['code']!=200){ throw new \Exception("非法提交,互聯網不是法外之地,請慎重!"); } //客服分組ID if(!empty($postdata['gid'])){ $enterpriseData = numberEncodeDecodeHashids('onlineservice_group',$postdata['gid'],1);//解密 if($enterpriseData['code']!=200){ throw new \Exception("非法提交,互聯網不是法外之地,請慎重!"); } } //客服ID if(!empty($postdata['sid'])){ $enterpriseData = numberEncodeDecodeHashids('enterprise_userid',$postdata['sid'],1);//解密 if($enterpriseData['code']!=200){ throw new \Exception("非法提交,互聯網不是法外之地,請慎重!"); } } $postdata['enterprise_id'] = $enterpriseData['data'][0]; //1.7天表、1個月表 self::connect('enterprise_heat')->setSuffix('_7d')->save($postdata);//7天表 self::connect('enterprise_heat')->setSuffix('_1m')->save($postdata);//1個月表 //2.今年表 以前表 (new static())->setSuffix('_1y')->save($postdata);//今年表 (new static())->save($postdata);//以前表(所有數據表) $code=200;$msg="成功"; Db::connect('enterprise_cold')->commit(); Db::connect('enterprise_heat')->commit(); } catch (\Exception $e) { Db::connect('enterprise_cold')->rollback(); Db::connect('enterprise_heat')->rollback(); $code=-200;$msg=$e->getMessage(); } return ['code' => $code,'msg' =>$msg]; } } ``` # 取得自增ID ``` //引用 use app\services\table\model\Guestbook; //動態調用 要實例化 $TaskLog =new TaskLog(); $returnData = $TaskLog ->saveGuestbook($postdata); ``` 表對應模型文件代碼: ``` <?php namespace app\services\table\model; use think\Model; use think\facade\Db; use app\services\table\validate\TaskLogValidate; /** * @name 任務日志 * @method Model/POST/GET/ * @date 2021-12-01 */ class TaskLog extends Model { protected $name = 'task_log'; //表名 protected $connection = 'log';//數據庫的連接 protected $autoWriteTimestamp = 'int'; protected $createTime = 'time'; // protected $updateTime = 'utime'; // 設置字段信息 protected $schema = [ 'id' => 'int', 'user_id' => 'int', 'enterprise_id' => 'int', 'title' => 'string', 'data' => 'string', 'content' => 'string', 'starttime' => 'int', 'endtime' => 'int', 'url' => 'string', 'state' => 'int', 'url' => 'string', 'type' => 'int', 'mold' => 'int', 'delay' => 'int', 'time' => 'int', ]; /** * @name 保存訪客提交過來的留言 * @method Model * @date 2021-11-19 * @param 1 $postdata arr/必填 提交數組 * @ruturn array */ public function DataSave(array $postdata) { // Db::connect($this->connection)->startTrans();//有回滾就啟用 try { // if(empty($postdata)){ // throw new \Exception("提交數據為空!"); // } $postdata['enterprise_id'] = !empty($postdata['eid'])?$postdata['eid']:0; validate(TaskLogValidate::class)->check($postdata); if(!empty($postdata['enterprise_id'])){ $enterpriseData = numberEncodeDecodeHashids('enterprise',$postdata['enterprise_id'],1);//解密 if($enterpriseData['code']!=200){ throw new \Exception("非法提交,互聯網不是法外之地,請慎重!"); } $postdata['enterprise_id'] = $enterpriseData['data'][0]; } $this->save($postdata);//以前表(所有數據表) $code=200;$msg="成功"; // Db::connect($this->connection)->commit(); } catch (\Exception $e) { // Db::connect($this->connection)->rollback(); $code=-200;$msg=$e->getMessage(); } return ['code' => $code,'msg' =>$msg]; } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看