'blobt\grid\CheckboxColumn', 'width' => '2%', 'align' => 'center' ], ['attribute' => 'image', 'contentOptions' => [ 'align' => 'center', ], 'width'=>'10%', 'format' => 'raw', 'value' => function ($model) { return $model->imageFile ? Html::img(['/'.$model->imageFile->path], ['style' => 'width:80px']) : '
未设置
'; } ], 'id', 'name', [ 'attribute' => 'market_price', 'value' => function ($model) { return sprintf("%1\$.2f",$model->market_price / ShopManager::proportionalConversion(ShopManager::UNIT_TYPE_MONEY)); } ], [ 'attribute' => 'price', 'value' => function ($model) { return sprintf("%1\$.2f",$model->price / ShopManager::proportionalConversion(ShopManager::UNIT_TYPE_MONEY)); } ], [ 'attribute' => 'stock', 'width' => '5%', 'value' => function ($model) { if ($model->stock == -1) { return '未开启'; } else { return $model->stock; } }, ], ['attribute' => 'is_sale', 'width' => '5%', 'value' => function ($model) { return $model->is_sale==Goods::IS_SALE_YES ? '在售' : '不在售'; }, ], 'sort_order', [ 'class' => 'iron\grid\ActionColumn', 'align' => 'center', 'config' => [ [ 'name' => 'update', 'icon' => 'pencil', 'title' => '修改' ], [ 'name' => 'edit-sku', 'icon' => 'hard-drive', 'title' => '商品sku' ], [ 'name' => 'delete', 'icon' => 'trash', 'title' => '删除', 'contents' => '确定删除?' ] ], ], ]; } /** * @param $params * @return ActiveDataProvider * 不分页的所有数据 */ public function allData($params) { $query = Goods::find(); $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => false, 'sort' => false ]); $this->load($params); return $this->filter($query, $dataProvider); } /** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Goods::find()->where(['is_delete' => Goods::IS_DELETE_NO]); // add conditions that should always apply here $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'pageSizeLimit' => [1, 200] ], 'sort' => [ 'defaultOrder' => [ 'id' => SORT_DESC, ] ], ]); $this->load($params); return $this->filter($query, $dataProvider); } /** * @param $query * @param $dataProvider * @return ActiveDataProvider * 条件筛选 */ private function filter($query, $dataProvider){ $query->andFilterWhere(['is_delete' => Goods::IS_DELETE_NO]); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, 'pid' => $this->pid, 'cat_id' => $this->cat_id, 'brand_id' => $this->brand_id, 'shop_cat_id' => $this->shop_cat_id, 'supplier_id' => $this->supplier_id, 'weight' => $this->weight, 'length' => $this->length, 'width' => $this->width, 'height' => $this->height, 'diameter' => $this->diameter, 'sold_count' => $this->sold_count, 'limit_count' => $this->limit_count, 'stock' => $this->stock, 'stock_warn' => $this->stock_warn, 'market_price' => $this->market_price, 'price' => $this->price, 'image' => $this->image, 'model_id' => $this->model_id, 'is_sale' => $this->is_sale, 'sort_order' => $this->sort_order, 'bouns_points' => $this->bouns_points, 'experience_points' => $this->experience_points, 'is_delete' => $this->is_delete, 'express_template' => $this->express_template, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]); $query->andFilterWhere(['like', 'name', $this->name]) ->andFilterWhere(['like', 'sn', $this->sn]) ->andFilterWhere(['like', 'code', $this->code]) ->andFilterWhere(['like', 'unit', $this->unit]) ->andFilterWhere(['like', 'brief', $this->brief]) ->andFilterWhere(['like', 'description', $this->description]); if ($this->created_at_range) { $arr = explode(' ~ ', $this->created_at_range); $start = strtotime($arr[0]); $end = strtotime($arr[1]) + 3600 * 24; $query->andFilterWhere(['between', 'created_at', $start, $end]); } return $dataProvider; } }