当前位置: 首页>>代码示例>>PHP>>正文


PHP Query::addOrderBy方法代码示例

本文整理汇总了PHP中yii\db\Query::addOrderBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::addOrderBy方法的具体用法?PHP Query::addOrderBy怎么用?PHP Query::addOrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\db\Query的用法示例。


在下文中一共展示了Query::addOrderBy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getPOLineRelatedQuery


//.........这里部分代码省略.........
     //     if(is_array($params['pricelist'])){
     //         $pricelist=implode(",", $params['pricelist']);
     //     }else{
     //         $pricelist=$params['pricelist'];
     //     }
     // }else{
     //     $pricelist='0';
     // }
     if ($groupBy) {
         if (is_array($params['pricelist'])) {
             $pricelist = implode(",", $params['pricelist']);
         } else {
             $pricelist = $params['pricelist'];
         }
     }
     if ($groupBy) {
         if ($groupBy == 'partner') {
             $query->select(['CONCAT("pol"."partner_id", \'/\',"pid"."id",\'/\',\'' . $product . '\',\'/\',\'' . $state . '\',\'/\',\'' . $dattefrom . '\',\'/\',\'' . $dateto . '\') as id,
                 rp.name as partner,
                 SUM(pol.price_unit*pol.product_qty) as total,
                 pid.name as pricelist']);
         }
     } else {
         $query->select('
                         pol.id as id,
                         pol.partner_id as partner_id,
                         po.date_order as date_order,
                         po.name as no_po,
                         pol.name as pol_desc,
                         rp.name as partner,
                         pol.product_id as product_id,
                         pp.name_template as product,
                         pol.price_unit as price_unit,
                         pol.state as state,
                         pol.product_qty as product_qty,
                         pu.name as uom,
                         pid.name as pricelist,
                         (pol.product_qty*pol.price_unit) as total,
                     ');
     }
     $query->from('purchase_order_line as pol')->join('LEFT JOIN', 'purchase_order as po', 'po.id=pol.order_id')->join('LEFT JOIN', 'product_pricelist as pid', 'pid.id=po.pricelist_id')->join('LEFT JOIN', 'product_product as pp', 'pp.id=pol.product_id')->join('LEFT JOIN', 'product_uom as pu', 'pu.id=pol.product_uom')->join('LEFT JOIN', 'res_partner as rp', 'rp.id=pol.partner_id');
     if ($groupBy) {
         if ($groupBy == 'partner') {
             $query->groupBy(['pol.partner_id', 'rp.name', 'pid.id']);
             $query->orderBy('rp.name ASC');
         }
     }
     if (isset($params['partner_id']) && $params['partner_id']) {
         if ($params['partner_id'] != '0') {
             $query->andWhere(['pol.partner_id' => explode(',', $params['partner_id'])]);
         }
     }
     if (isset($modelline['name']) && $modelline['name']) {
         $query->andWhere(['ilike', 'pol.name', $modelline['name']]);
         // die();
     }
     if (isset($modelline['product_id']) && $modelline['product_id']) {
         if ($modelline['product_id'] != '0') {
             $query->andWhere(['pol.product_id' => explode(',', $modelline['product_id'])]);
         }
     }
     if (isset($params['state']) && $params['state']) {
         if ($params['state'] == "purchased") {
             $cekstate = 'confirmed, approved, done';
             if ($params['state'] != '0') {
                 $query->andWhere(['pol.state' => explode(',', $cekstate)]);
             }
         } else {
             if ($params['state'] != '0') {
                 $to_state = [];
                 $exps = explode(',', urldecode($params['state']));
                 foreach ($exps as $exp) {
                     if ($exp == 'purchased') {
                         $to_state[] = 'confirmed';
                         $to_state[] = 'approved';
                         $to_state[] = 'done';
                     } else {
                         $to_state[] = $exp;
                     }
                 }
                 $query->andWhere(['pol.state' => $to_state]);
             }
         }
     } else {
         $query->andWhere(['in', 'pol.state', ['confirmed', 'approved', 'done']]);
     }
     if (isset($params['date_order']) && $params['date_order']) {
         if ($params['date_order'] != '0') {
             $query->andWhere(['>=', 'po.date_order', $params['date_order']]);
             $query->andWhere(['<=', 'po.date_order', $params['duedate']]);
         }
     }
     if (isset($params['pricelist'])) {
         $query->andWhere(['po.pricelist_id' => $params['pricelist']]);
     }
     if (!$groupBy) {
         $query->addOrderBy(['po.date_order' => SORT_DESC]);
     }
     return $query;
 }
开发者ID:hendri30,项目名称:OpenPrint,代码行数:101,代码来源:PurchaseOrderController.php

示例2: testOrder

 public function testOrder()
 {
     $query = new Query();
     $query->orderBy('team');
     $this->assertEquals(['team' => SORT_ASC], $query->orderBy);
     $query->addOrderBy('company');
     $this->assertEquals(['team' => SORT_ASC, 'company' => SORT_ASC], $query->orderBy);
     $query->addOrderBy('age');
     $this->assertEquals(['team' => SORT_ASC, 'company' => SORT_ASC, 'age' => SORT_ASC], $query->orderBy);
     $query->addOrderBy(['age' => SORT_DESC]);
     $this->assertEquals(['team' => SORT_ASC, 'company' => SORT_ASC, 'age' => SORT_DESC], $query->orderBy);
     $query->addOrderBy('age ASC, company DESC');
     $this->assertEquals(['team' => SORT_ASC, 'company' => SORT_DESC, 'age' => SORT_ASC], $query->orderBy);
 }
开发者ID:glcode,项目名称:yii2-2.0.3-annotated,代码行数:14,代码来源:QueryTest.php

示例3: getSOLineRelatedQuery


//.........这里部分代码省略.........
            $dateto = '0';
        }
        if ($params['pricelist']) {
            if (is_array($params['pricelist'])) {
                $pricelist = implode(",", $params['pricelist']);
            } else {
                $pricelist = $params['pricelist'];
            }
        } else {
            $pricelist = '0';
        }
        // jika group
        if ($groupBy) {
            $query->select(['CONCAT("pc"."id", \'/\', "pid"."id", \'/\', "pc"."name", \'/\', "pid"."name",\'/\',\'' . $category . '\',\'/\',\'' . $partner . '\',\'/\',\'' . $product . '\',\'/\',\'' . $pricelist . '\',\'/\',\'' . $state . '\',\'/\',\'' . $dattefrom . '\',\'/\',\'' . $dateto . '\') as id,
					pc.name as category,
					SUM(sol.price_unit*sol.product_uom_qty) as total,
					pid.name as pricelist']);
        } else {
            $query->select('
					sol.id as id,
					so.partner_id as partner_id,
					so.date_order as date_order,
					so.name as no_po,
					rp.name as partner,
					sol.product_id as product_id,
					pp.name as product,
					sol.price_unit as price_unit,
					sol.state as state,
					pc.name as category,
					pid.name as pricelist,
					sol.product_uom_qty as qty,
					sol.name as product_desc,
					(sol.product_uom_qty*sol.price_unit) as total,
					so.name as so_no
				');
        }
        $query->from('sale_order_line as sol')->join('LEFT JOIN', 'sale_order as so', 'so.id=sol.order_id')->join('LEFT JOIN', 'product_template as pp', 'pp.id=sol.product_id')->join('LEFT JOIN', 'res_partner as rp', 'rp.id=so.partner_id')->join('LEFT JOIN', 'product_category as pc', 'pc.id=pp.categ_id')->join('LEFT JOIN', 'product_pricelist as pid', 'pid.id=so.pricelist_id');
        if ($groupBy) {
            $query->groupBy(['pc.id', 'pid.id']);
        }
        if (isset($params['partner']) && $params['partner']) {
            if ($params['partner'] != '0') {
                $query->andWhere(['so.partner_id' => explode(',', $params['partner'])]);
            }
        }
        if (isset($params['productcategory']) && $params['productcategory']) {
            if ($params['productcategory'] != '0') {
                if (is_array($params['productcategory'])) {
                    $query->andWhere(['pp.categ_id' => explode(',', implode(",", $params['productcategory']))]);
                } else {
                    $query->andWhere(['pp.categ_id' => explode(',', $params['productcategory'])]);
                }
            }
        }
        if (isset($params['product']) && $params['product']) {
            if ($params['product'] != '0') {
                $query->andWhere(['sol.product_id' => explode(',', $params['product'])]);
            }
        }
        if (isset($params['pricelist']) && $params['pricelist']) {
            if ($params['pricelist'] != '0') {
                if (is_array($params['pricelist'])) {
                    $query->andWhere(['so.pricelist_id' => explode(',', implode(",", $params['pricelist']))]);
                } else {
                    $query->andWhere(['so.pricelist_id' => explode(',', $params['pricelist'])]);
                }
            }
        }
        // if(isset($params['state']) && $params['state']){
        // 	if($params['state']!='0')
        // 		{
        // 			$query->andWhere(['sol.state'=>explode(',',$params['state'])]);
        // 		}
        // }
        if (isset($params['state']) && $params['state']) {
            if ($params['state'] == "order") {
                $cekstate = 'confirmed, approved, done';
                if ($params['state'] != '0') {
                    $query->andWhere(['sol.state' => explode(',', $cekstate)]);
                }
            } else {
                if ($params['state'] != '0') {
                    $query->andWhere(['sol.state' => explode(',', $params['state'])]);
                }
            }
        } else {
            $query->andWhere(['in', 'sol.state', ['confirmed', 'approved', 'done']]);
        }
        if (isset($params['date_from']) && $params['date_from']) {
            if ($params['date_from'] != '0') {
                $query->andWhere(['>=', 'so.date_order', $params['date_from']]);
                $query->andWhere(['<=', 'so.date_order', $params['date_to']]);
            }
        }
        $query->andWhere(['not', ['sol.product_id' => null]]);
        if (!$groupBy) {
            $query->addOrderBy(['so.date_order' => SORT_DESC]);
        }
        return $query;
    }
开发者ID:hendri30,项目名称:OpenPrint,代码行数:101,代码来源:SaleOrderController.php


注:本文中的yii\db\Query::addOrderBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。