/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Goods::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'type_id' => $this->type_id, 'color_id' => $this->color_id, 'sex_id' => $this->sex_id]); $query->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Goods::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); 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; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'goods_type_type', $this->goods_type_type]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Goods::find(); $query->with('chargeCity'); $query->joinWith('chargeCity'); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); 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; } $query->andFilterWhere(['goods_id' => $this->goods_id, 'charge_city_id' => $this->charge_city_id, 'discharge_city_id' => $this->discharge_city_id, 'goods_weight' => $this->goods_weight, 'goods_size' => $this->goods_size, 'capacity' => $this->capacity, 'size' => $this->size, 'charge_start' => $this->charge_start, 'charge_end' => $this->charge_end, 'city_rate' => $this->city_rate, 'intercity_rate' => $this->intercity_rate, 'passage_rate' => $this->passage_rate, 'term' => $this->term, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'user_id' => $this->user_id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'tare', $this->tare])->andFilterWhere(['like', 'carcase', $this->carcase])->andFilterWhere(['like', 'carcase_charge', $this->carcase_charge])->andFilterWhere(['like', 'work_preferences', $this->work_preferences])->andFilterWhere(['like', 'status_charge', $this->status_charge])->andFilterWhere(['like', 'info', $this->info]); return $dataProvider; }
/** * -------------------------------------------------------- * ajax属性列表 * -------------------------------------------------------- */ public function ajaxList(Request $request, $typeId, $goodsId = 0) { if ($request->ajax()) { if ($goodsId && Goods::find($goodsId)) { $type = GoodsType::find($typeId); $attrs = Attribute::where('type_id', $type->id)->get(); $goods = Goods::find($goodsId); $goodsAttrs = $goods->goodsAttrs; foreach ($attrs as $v) { $v->attr_value = unserialize($v->attr_value); $v->list = GoodsAttr::where(['attr_id' => $v['id'], 'goods_id' => $goodsId])->select('attr_value', 'attr_price')->get(); //[['attr_value'=>'', 'attr_price'=>''],...]; if (!$v->list->first()) { $v->list = [['attr_value' => '', 'attr_price' => 0]]; } } //dump($attrs); /************************ $goods = Goods::find($goodsId); $goodsAttrs = $goods->goodsAttrs; foreach($goodsAttrs as $v){ $attr = Attribute::find($v['attr_id']); $v->attr_value_list = unserialize($attr->attr_value); $v->attr_name = $attr->attr_name; $v->attr_type = $attr->attr_type; $v->attr_input_type = $attr->attr_input_type; } //$goodsAttrs = GoodsAttr::where(['goods_id'=>$goodsId])->select('id', 'attr_id', 'attr_value as _value', 'attr_price')->get()->toArray(); ******************************/ return response()->json($attrs); } else { $attrs = []; $type = GoodsType::find($typeId); $attrs = Attribute::where('type_id', $type->id)->get(); //属性值去序列化 foreach ($attrs as $attr) { $attr->attr_value = unserialize($attr->attr_value); } return response()->json($attrs); } } else { $attrs = ['error']; return response()->json($attrs); } }
/** * ------------------------------------------------- * 获取正确的评论对象 * ------------------------------------------------- */ public static function tableObj($post_id, $type) { //方法一,让客户端控制 //Comment::addTableObj('\App\Models\Article'); //Comment::addTableObj('\App\Models\Goods'); /** foreach(self::$tableObjs as $tobj){ if($type == $tobj::commentType() && $post_id)return $tobj::find($post_id); } */ //方法二,服务器控制 if ($type == 1) { return Goods::find($post_id); } elseif ($type == 2) { return Article::find($post_id); } elseif ($type == 3) { return Page::find($post_id); } return null; }
/** * @return GoodsQuery */ public function getActiveQueryFilterGoods() { /** * @var GoodsQuery $query */ $query = Goods::find()->alias('gds'); if ($this->sex) { $query->andFilterWhere(['gds.sex_id' => $this->sex]); } if ($this->type) { $query->andFilterWhere(['gds.type_id' => $this->type]); } if ($this->color) { $query->andFilterWhere(['gds.color_id' => $this->color]); } if ($this->size) { $query->rightJoin(SizeGoodsRelation::tableName() . ' `sgr`', 'sgr.goods_id=gds.id'); $query->andFilterWhere(['sgr.size_id' => $this->size]); } return $query; }
/** * 多态关联 * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View * A model relation B model and A model relation C model * demo:ImagesModel User Goods * 从 B OR C 读取 A model 的字段值 */ public function morph() { $obj = new User(); //$rows = $obj->find(1)->images->toarray(); $rows = $obj->where('id', 1)->iamges->select('id')->toarray(); print_r($rows); $obj = new Goods(); $rows = $obj->find(1)->images->toarray(); print_r($rows); return view('index'); }
public function actionSaveFull($k, $saveAccord = 'y') { $post = $_POST; $goodTypeId = $post['type']; $cach = Yii::$app->cache->get($post['key']); $priceArr = $cach['arrToAccord'][$k]; //Поиск в таблице Goods $code = \app\components\Goods::requiredParameters($post, $goodTypeId); $goods = \app\models\Goods::find()->where(['name' => $code])->one(); if ($goods instanceof \app\models\Goods) { //Если нашли возвращаем id товара $goodId = $goods->id; } else { //Если не нашли записываем в Goods и возвращаем id товара $goodId = \app\components\Goods::save($goodTypeId, $post); } //Добавить запись в таблицу Accords if ($saveAccord == 'y') { $accord = new \app\models\Accords(); $identifier = isset($priceArr['identifier']) && strlen($priceArr['identifier']) > 0 ? $priceArr['identifier'] : $priceArr['name']; $accord->identifier = $identifier; $accord->goods_id = $goodId; $accord->providers_id = $cach['providerId']; $accord->save(); } //Добавить запись в таблицу Offers $offer = new \app\models\Offers(); $offer->quantity = $priceArr['quantity']; $offer->price = $priceArr['price']; $offer->goods_id = $goodId; $offer->providers_id = $cach['providerId']; $offer->save(); // Удалить строку из кеша unset($cach['arrToAccord'][$k]); Yii::$app->cache->set($post['key'], $cach); //Вренуть результат print json_encode(['res' => 'ok', 'k' => $k]); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { //同时删除所有评论 $goods = Goods::find($id); $goods->delete(); return Redirect::to('admin/goods'); }