1.删除不等于当前ID,并且是这个openid,适用于2条同样的openid,需要删除一条没用的。
Yii::$app->db->createCommand()->delete('{{%ybwm_member}}', ['AND','openId = :openId',['!=','id',$result['oldid']]],[':openId' => $openId])
    ->execute();
2.打印sql语句

 $res=Yii::$app->db->createCommand()->update('{{%ybo2ov2_store}}', $array, 'id=:id', ['id' =>$result['id']])->execute();

echo Yii::$app->db->createCommand()->update('{{%ybo2ov2_store}}', $array, 'id=:id', ['id' =>$result['id']])->getRawSql();die;
3.打印sql,写在查询前面。
 $table=(new \yii\db\Query())
     ->select(['a.id', 'a.name','a.icon','a.outSales','a.lat','a.lng','a.address','b.name as typePName','c.name as typeName','ROUND(6378.137 * 2 * ASIN(SQRT(POW(SIN(('.$lat.' * PI() / 180 - lat * PI() / 180) / 2),2) + COS('.$lat.' * PI() / 180) * COS(lat * PI() / 180) * POW(SIN(('.$lng.' * PI() / 180 - lng * PI() / 180) / 2),2))) * 1000) AS distance,d.name as labelName,d.data'])
     ->from('{{%ybo2ov2_store}} as a')
     ->join('LEFT JOIN', '{{%ybo2ov2_core_category}} as b', 'b.id = a.orderTypePid')
     ->join('LEFT JOIN', '{{%ybo2ov2_core_category}} as c', 'c.id = a.orderTypeId')
     ->join('LEFT JOIN', '{{%ybo2ov2_core_category}} as d', 'd.id = a.label')
     ->where('a.uniacid=:uniacid AND a.deleteAt=0 AND a.display=1 AND a.endTime>:endTime',[':uniacid'=>$uniacid,':endTime'=>time()]);
 $table->offset(($page - 1) * $size)->limit($size);


echo  ddSql($table);die;

4.in查询$categoryIdS = (new \yii\db\Query())
->select('id')
->from('{{%ybo2ov2_core_category}}')
->where(['in','vid',$vidIdsArr])
->one();
5.批量插入,更新,删除
if ($categoryIdS) {
file_put_contents(__DIR__ . '/categoryIdS.txt', var_export($categoryIdS, true), FILE_APPEND);
$categoryIdS=array_column($categoryIdS,'id');
Yii::$app->db->createCommand()->update('{{%ybo2ov2_core_goods}}', ['deleteAt' => time()], ['AND','storeId = :storeId',['in','typePid',$categoryIdS]],[':storeId' => $info['id']])->execute();
file_put_contents(__DIR__ . '/update.txt', var_export( Yii::$app->db->createCommand()->update('{{%ybo2ov2_core_goods}}', ['deleteAt' => time()], ['AND','storeId = :storeId',['in','typePid',$categoryIdS]],[':storeId' => $info['id']])->getRawSql(), true), FILE_APPEND);
}else{
YII::$app->db->createCommand()->delete('{{%ybo2ov2_core_goods}}', ['storeId' => $info['id'], 'typePid' => ['in',$categoryIdS]])->execute();
}
Yii::$app->db->createCommand()
->batchInsert(
'{{%ybo2ov2_core_goods}}', $field,
$newGoodsInserData
)
->execute();
6.获取一列
(new Query())
    ->select('id')
    ->from('{{%ybo2ov2_core_goods}}')
    ->where(['storeId' => $storeId])
    ->column(); 7.query分页查询
$query =        (new Query())->select(['*'])
->from(['v'=>'{{%user_voucher}}'])
->leftJoin(['u' =>  '{{%user}}'], 'v.user_id = u.id');


$count = $query->count();
$pagination = new Pagination(['totalCount' => $count]);
$list = $query->limit($pagination->limit)->offset($pagination->offset)->orderBy('v.id DESC')->all();


点赞(68)

评论列表 共有 0 条评论

暂无评论
立即
投稿
发表
评论
返回
顶部
{__SCRIPT__}