經銷商後臺管理加入統計功能模塊php
|view:statistics/goods_statistics.html order_statistics.htmlhtml
|controller: Statisics.phpmysql
常常報錯:重定向循環……緣由有apache vhosts路徑配置,action名字錯誤,找不到controller……不過這框架的路由設計也太不穩定了……。jquery
新加了統計頁面,然而菜單一直取不出來,同事發現了是靜態頁面是直接複製過來的,取值取不出來,而菜單是底部用js生成,代碼沒有執行到那兒。git
還有就是$this->theme=sysdefault,沒有看到制定主題的代碼,因此暫時直接在action裏賦值,不然又是重定向循環……github
首先要取得的數據:銷量,總銷量等。
sql
分析一下商品管理的後臺據邏輯:shell
//搜索條件 $search = IFilter::act(IReq::get('search'),'strict'); $page = IReq::get('page') ? IFilter::act(IReq::get('page'),'int') : 1; //條件篩選處理 list($join,$where) = goods_class::getSearchCondition($search); //拼接sql $goodsHandle = new IQuery('goods as go'); $goodsHandle->order = "go.sort asc,go.id desc"; $goodsHandle->distinct = "go.id"; $goodsHandle->fields = "go.*,seller.true_name,br.name as brname"; $goodsHandle->page = $page; $goodsHandle->where = $where; $goodsHandle->join = $join; $this->search = $search; $this->goodsHandle = $goodsHandle; $this->host = HOST_URL; $this->redirect("goods_list");
後臺作得是sql拼接,而後數據是前臺取的。apache
新生成IQuery的實例,在IQuery中看到註釋是爲了處理複雜的查詢問題。json
前臺查詢是:
$this->goodsHandle->find();
find方法(中間省去一些paging代碼):
$sql = "select $this->distinct $this->fields from $this->table $this->join $this->where $this->group $this->having $this->order"; $result = $this->dbo->query($sql); return $result;
繼續MySQL學習之路……
查詢選擇全部 date_col 值在最後 30 天內的記錄。
mysql> SELECT something FROM tbl_name
WHERE TO_DAYS(NOW()) - TO_DAYS(date_col) <= 30;
例如查詢商品上一個月的銷量:
{set: $salesHandle = new IQuery('order_goods as sa'); $salesHandle->fields = "count(*)"; $salesHandle->join = "LEFT JOIN order as o ON sa.order_id =o.id"; $salesHandle->where = "sa.goods_id=$item[id] AND TO_DAYS(NOW()) - TO_DAYS(o.create_time) <= 30"; $result=$salesHandle->find(); } {echo:$result[0]['count(*)']}
的錯誤寫法………………
不可能每次只買一件,因此不能用count(*)而應該是用SUM。
{set: $salesHandle = new IQuery('order_goods as sa'); $salesHandle->fields = "SUM(goods_nums)"; $salesHandle->join = "LEFT JOIN order as o ON sa.order_id =o.id"; salesHandle->where = "sa.goods_id=$item[id] AND TO_DAYS(NOW()) - TO_DAYS(o.create_time) <= 30"; $result=$salesHandle->find(); } {echo:(int)$result[0]['SUM(goods_nums)']}
:
framework:yii (Yes It Is!
官網:http://www.yiiframework.com/
doc:http://www.yiiframework.com/doc-2.0/index.html
幾乎都推薦用composer安裝yii,還在慶幸以前就裝好了,更新composer:
composer self-update
而後:
composer global require "fxp/composer-asset-plugin:~1.1.1" composer create-project --prefer-dist yiisoft/yii2-app-basic basic
結果有點問題:
Reading bower.json of bower-asset/jquery.inputmask (3.1.36) Could not fetch https://api.github.com/repos… Head to https://github.com/settings/tokens/new…… to retrieve a token. It will be stored in "……" for future use by Composer. Token (hidden):
由於沒有開啓php的OpenSSL支持,因此去修改php的配置文件php.ini
或者直接去官網生成密鑰
ps用composer時老是說 running composer with xdebug enabled. 無論怎麼註釋php.ini都無用……暫時算了。
,好吧下好了yii 2.0,可是api要yii 1.0……
直接去github git clone……
yii1 doc:http://vdisk.weibo.com/s/zvcWC2S917wDf?from=page_100505_profile&wvr=6