/** * Возвращает массив идентификаторов одежды. * * @return yii\db\ActiveRecord[] | null */ public function getGoods() { $ids = $this->getGoodsIds(); if (is_array($ids) && count($ids)) { $result = Goods::findAll($ids); return $result; } return []; }
/** * Updates an existing Prints model. * If update is successful, the browser will be redirected to the 'view' page. * * @param integer $id * * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $goods = Goods::getAll(true, false); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'goods' => $goods]); } }
/** * 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; }
/** * * @param type $id * @return type */ public static function getName($id, $mode = 'name') { $good = \app\models\Goods::findOne($id); \app\models\GoodsT::$tabName = self::$goodTablePefix . $good->goods_type_type; $goodT = \app\models\GoodsT::findOne($id); // $arGoodsParamsNames = self::getGoodTypeParams($good->goods_type_type); $goodType = \app\models\GoodsType::findOne($good->goods_type_type); $arGoodsParamsNames = $goodType->getGoodsParamsNames()->orderBy('sort')->all(); $arParams = ['goodType' => $goodType->name]; foreach ($arGoodsParamsNames as $oParam) { $idParamVal = $goodT->{$oParam->id}; $oParamValue = \app\models\GoodsParams::findOne($idParamVal); $arParams[$oParam->id] = $oParamValue->public_value ? $oParamValue->public_value == \Yii::$app->params['emptyStringParam'] ? '' : $oParamValue->public_value : $oParamValue->value; } $tpl = $goodType->template_view; if ($mode == 'array') { return ['name' => self::fullName($arParams, $tpl), 'goodTipe' => $goodType, 'good' => $good, 'params' => $arGoodsParamsNames, 'values' => $arParams]; } return self::fullName($arParams, $tpl); }
/** * @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; }
public static function calc($goods_id, $providers_id, $priceType) { //Получить список наценок if (!isset(self::$arDisconts)) { $arODisconts = \app\models\Discounts::find()->where('price_type_id = :price_type_id', [':price_type_id' => $priceType])->asArray()->all(); self::$arDisconts = []; foreach ($arODisconts as $arDiscont) { $arP = explode(';', $arDiscont['params']); $arV = explode(';', $arDiscont['values']); $arW = []; foreach ($arP as $key => $value) { if ($value) { $arW[$value] = $arV[$key]; } } $arDiscont['arPV'] = $arW; self::$arDisconts[$arDiscont['providers_id']][$arDiscont['goods_type_type']][] = $arDiscont; } } //Получить свойства товара $good = \app\models\Goods::findOne($goods_id); $goodT = \yii\helpers\ArrayHelper::toArray($good->getGoodsT()); //Для каждой наценки проверить - подходит ли товар под нее $dds = self::$arDisconts[$providers_id][$good->goods_type_type]; $k = 1; $arK = []; if (!is_array($dds)) { return 1; } foreach ($dds as $arDiscount) { if (count(array_intersect_assoc($arDiscount['arPV'], $goodT)) == count($arDiscount['arPV'])) { $k = $k * $arDiscount['coef']; $arK[] = $arDiscount['coef']; } } return $k > 1 ? $k : 1; }
/** * Finds the Goods model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Goods the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Goods::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
?> <?php echo $form->field($model, 'discharge_city_id')->hiddenInput(['id' => 'city_input2'])->label(false); ?> <br> <h4><?php echo Yii::t('app', 'Goods'); ?> </h4> <?php echo $form->field($model, 'name')->textInput(); ?> <?php echo $form->field($model, 'tare')->dropDownList(Goods::getTare(), ['prompt' => Yii::t('app', 'Select the tare')]); ?> <?php echo $form->field($model, 'goods_weight')->textInput(); ?> <?php echo $form->field($model, 'goods_size')->textInput(); ?> <br> <h4><?php echo Yii::t('app', 'Transport'); ?> </h4> <?php
/** * Deletes an existing GoodsParams model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionTech() { exit; $GoodsParamsName = \app\models\GoodsParamsName::find()->all(); foreach ($GoodsParamsName as $gpn) { print '============================== <br>'; print $gpn->id . '<br>'; $oGP = \app\models\GoodsParams::find()->where('goods_params_name_id=:goods_params_name_id', [':goods_params_name_id' => $gpn->id])->all(); // print ('<pre>');print_r($oGP);print('</pre>'); $arGP = \yii\helpers\ArrayHelper::map($oGP, 'id', 'id'); print implode(',', $arGP) . '<br>'; if (count($arGP) == 0) { continue; } // $goods = \app\components\Goods::find($gpn->goods_type_type, $gpn->id . ' not in (:ids)', [':ids' => implode(',',$arGP)])->all(); $goods = \app\components\Goods::find($gpn->goods_type_type, $gpn->id . ' not in (' . implode(',', $arGP) . ')', [])->all(); foreach ($goods as $good) { $ar = \yii\helpers\ArrayHelper::toArray($good); print '<pre>'; print_r($ar); print '</pre>'; \app\models\Goods::deleteAll('id=:goods_id', [':goods_id' => $good->goods_id]); } } }
public function getGoods() { return $this->hasOne(Goods::className(), ['goods_id' => 'goods_id'])->asArray(); }
/** * 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'); }
/** * @return \yii\db\ActiveQuery */ public function getGoods() { return $this->hasMany(Goods::className(), ['sex_id' => 'id']); }
/** * 多态关联 * @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'); }
/** * @return \yii\db\ActiveQuery */ public function getGoods() { return $this->hasMany(Goods::className(), ['goods_type_type' => 'type']); }
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]); }