yii2 小笔记

网友投稿 932 2022-11-27

yii2 小笔记

yii2 小笔记

yii笔记linux监测日志tail -f runtime/logs/app.logerror_log("*******host*******\n".print_r($host, 1)."\n********************\n",3, 'aass.log');congfig配置 'mqtt' => [ 'address' => 'tcp://47.106.178.36', 'port' => '61613', 'username'=> '', 'password'=> '', ],调用$jpush = \Yii::$app->params['mqtt']['address'];域名\Yii::$app->request->hostInfo自定义路径defined('ROOT_DIR') or define('ROOT_DIR', __DIR__);直接使用ROOT_DIR."/sss/sss"即可获取配置param.php "equ_model" =>[ 'model_1' => "ME638", ],$weixin=\Yii::$app->params['equ_model']['model_1']; //获取配置里面的系列号打印最后一条数据$query = Salesorder::find() ->where(['order_id'=>[1,2,3,4]]) ->select(['order_id']) ; sql调试$commandQuery = clone $query; echo $commandQuery->createCommand()->getRawSql(); exit; $ReSwitchTimer = \app\models\SwitchTimer::find()->andWhere(['in','switch_id',array_column($switch_ids,'id')]); $temp = clone $ReSwitchTimer; var_dump($temp->createCommand()->getRawSql()); $sid = \Yii::$app->db->getLastInsertID();//获取自增id $SelfExamination = new \app\models\SelfExamination(); $SelfExamination->self_id = $utime; $SelfExamination->equipment_id = $ids; $SelfExamination->box_name = $equ_name; $SelfExamination->status = $mon['status']; $SelfExamination->self_time = time(); $SelfExamination->save(); var_dump($SelfExamination->id);die;//取自增id调试新增 //插入自检单条记录 $SelfExamination = new \app\models\SelfExamination(); $SelfExamination->self_id = "$SelfAll->id"; $SelfExamination->equipment_id = $ids; $SelfExamination->box_name = $equ_name; $SelfExamination->status = $mon['status']; $SelfExamination->self_time = time(); if (!$SelfExamination->validate()) { var_dump( $SelfExamination->firstErrors); } else { $SelfExamination->save(); }循环新增多条数据$model = new User();foreach($data as $attributes){ $_model = clone $model; $_model->setAttributes($attributes); $_model->save();}判断字段中存在0的是否为空$l['type'] !== null ? $l['type'] : "";mongodb 调试{created:{$gte: new Date('2018-07-05 19:20:00')}}mongodb 查询存在loadmax字段的数据 'payload.desired.arrays.0.status.loadmax' => ['$exists' => true]联表查询 $query = new \yii\db\Query(); $query = $query->select("t1.*,t2.*,t3.group_name,t3.is_del") ->from(['t1' => 'ss_equipment_group_link']) ->leftJoin(['t2' => 'ss_equipment'], "t2.id = t1.equipment_id") ->leftJoin(['t3' => 'ss_user_group'], "t3.id = t1.group_id") ->where(1); if ($name != null) { $query = $query->andWhere(['like','t1.equipment_id',$name])->orFilterWhere(['like','t2.serial_number',$name])->orFilterWhere(['like','t3.group_name',$name]); } $total = $query->count(); $result = $query->offset(($page - 1) * $rows)->limit($rows)->all();$lists = \app\services\EquipmentSwitch::find()->andWhere(['ss_equipment_switch.id'=>$switchId])->joinWith('equipment')->asArray()->all(); public function getEquipment(){ // 第一个参数为要关联的子表模型类名, // 第二个参数指定 通过子表的equipment_id,关联主表的id字段 return $this->hasOne(\app\services\Equipment::className(), ['id' => 'equipment_id'])->select('*'); }// 关联goods表public function getGoods(){ // 一关联一 hasOne return $this->hasOne(Status::className(), ['id' => 'jihuo']);}// 关联user表 并传值 进一步判断public function getUser($status = 1){ // 一关联多 hasMany ; p_id 被关联表字段, id 关联表字段(当前表字段) return $this->hasMany(User::className(), ['p_id' => 'id']) ->where('status = :status', [':status' => $status]);}关联查询$list = static::find() ->leftJoin('book', 'book.RID = prices.RID')->select('prices.*,book.WCONTENT,book.WIMGURL,book.WURL') ->andFilterWhere(['prices.WMODEL'=> $where_condition['WMODEL']]) ->andFilterWhere(['prices.WTYPE'=> $where_condition['WTYPE']]) ->offset($params['offset']) ->orderBy(['prices.WCREATETIME' => SORT_DESC])->limit($params['limit'])->asArray()->all();讲数组作为条件查询 $switch_ids = \app\models\EquipmentSwitch::find()->select('id')->where(['equipment_id' => $equipment_id])->asArray()->all(); $ReSwitchTimer = \app\models\SwitchTimer::find()->andWhere(['in','switch_id',array_column($switch_ids,'id')]);删除try{ \app\models\EquipmentGroupLink::deleteAll(['group_id' => $group_id]); \app\models\UserGroup::findOne(['id' => $group_id])->delete(); return $this->returnData('', 1, '删除成功'); }catch (\Exception $e) { print $e->getMessage(); exit(); }修改 $switch_id = $timer->switch_id; \Yii::$app->db->createCommand()->update('ss_switch_timer', ['status' => 0], "switch_id = $switch_id and status = 1")->execute(); // 修改定时状态 $timer->status = $status; $timer->save();讲校验修改为非必传参数 // 判断是否要修改密码 if ($attributes['password']) { $attributes['password'] = \Yii::$app->security->generatePasswordHash($attributes['password']); } else { unset($attributes['password']); }定时任务参数windows D:\wamp\crontab/copy-db,你需要配置你的php环境变量linux*/1 * * * * /usr/local/php/bin/php /home/crontab/copy-db/usr/local/php/bin/php /home/crontab/copy-dbmongodb 新增$collection = \Yii::$app->mongodb->getCollection('timed_task'); $collection->insert(['end_time' => $end_time]);查询$last_result = $query->select(['end_time'])->from('timed_task')->orderBy('_id desc')->limit(1)->one();前端部分if判断adminid != 1): ?> 删除 orderby排序type //查询新的表 $query = new \yii\db\Query(); $query = $query->select("t1.*,t2.alias,t3.alias as equ_alias") ->from(['t1' => 'ss_fault_message']) ->leftJoin(['t2' => 'ss_alias'], "t2.extend_id = t1.switch_alias") ->leftJoin(['t3' => 'ss_alias'], "t3.extend_id = t1.equipment_id") ->where(1) ->andWhere(['t1.user_id' => $this->uid]) ->groupBy('t1.id') ->orderBy(["FIELD(`status`,0,1)"=>true, 'id'=>'desc']); $total= $query->count(); $default = $query->all(); $list = \app\models\SystemMessage::find() ->select('*') ->where(['or',['user_id'=>$this->uid],'user_id=0']) ->offset(($page - 1) * $rows) ->limit($rows) ->orderBy( [ 'is_read' => SORT_ASC, //是否报满正序 'id' => SORT_DESC, //编号排序倒序 ] ) ->asArray()->all();根据类型type统计$fault_message = \app\models\FaultMessage::find(); $activeRecord = $fault_message->select(['count(event) as event','sum(event=1) as event_1', 'sum(event=2) as event_2', 'sum(event=3) as event_3', 'sum(event=4) as event_4', 'sum(event=5) as event_5','sum(event=6) as event_6', 'sum(event=7) as event_7','sum(event=8) as event_8','sum(event=9) as event_9']) ->andWhere(['between', 'create_time', $ts_data, $te_data])->andWhere(['>', 'event', 0])->asArray()->one();

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:fsockopen 来模拟生成 HTTP 连接
下一篇:PHP从数组中删除元素的四种方法实例
相关文章

 发表评论

暂时没有评论,来抢沙发吧~