Beispiel #1
0
 public function readfile()
 {
     $filename = 'GoodsFile/GoodsPrice.txt';
     $readfile = fopen($filename, 'r');
     while ($str = fgets($readfile)) {
         $items = explode(';', $str);
         echo iconv('UTF-8', 'CP1251', $items[2]) . '<br>';
         $tp = Typeprice::find()->where(['type_price_name' => $items[5]])->one();
         if (!isset($tp)) {
             continue;
         }
         $good = Goods::findOne(['good_1c_id' => $items[1]]);
         if (isset($good)) {
             echo $good->good_id . '<br>';
         } else {
             echo iconv('UTF-8', 'CP1251', 'создаем новый объект ') . $items[1] . '<br>';
             $good = new Goods();
         }
         $good->good_1c_id = $items[1];
         $good->good_name = $items[2];
         $good->good_description = $items[4];
         $good->good_price = $items[6] * 100;
         $good->typeprices_id = $tp->type_price_id;
         $good->save();
     }
     fclose($readfile);
 }
Beispiel #2
0
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>

    <? //echo $form->field($model, 'user_id')->textInput() ?>

    <?php 
if ($upload) {
    echo $form->field($model, 'file')->fileInput();
} else {
    if (Yii::$app->user->can('admin')) {
        echo $form->field($model, 'user_id')->dropDownList(ArrayHelper::map(User::find()->all(), 'id', 'fullname'), ['prompt' => 'Выберите пользователя']);
    }
    echo $form->field($model, 'customer_1c_id')->textInput();
    echo $form->field($model, 'customer_name')->textInput(['maxlength' => 200]);
    echo $form->field($model, 'customer_email')->textInput(['maxlength' => 200]);
    echo $form->field($model, 'typeprices_id')->dropDownList(ArrayHelper::map(Typeprice::find()->all(), 'type_price_id', 'type_price_name'), ['prompt' => 'Выберите тип цен']);
}
?>

    <div class="form-group">
        <?php 
if ($upload) {
    echo Html::submitButton('Загрузить', ['class' => 'btn btn-success']);
} else {
    echo Html::submitButton($model->isNewRecord ? 'Создать' : 'Редактировать', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
}
?>
    </div>

    <?php 
ActiveForm::end();
Beispiel #3
0
 public function getTypePrices()
 {
     return $this->hasOne(Typeprice::className(), ['type_price_id' => 'typeprices_id']);
 }
Beispiel #4
0
 public function readfile()
 {
     $filename = 'CustomersFile/Customers.txt';
     $readfile = fopen($filename, 'r');
     while ($str = fgets($readfile, 1024)) {
         $items = explode(';', $str);
         //print_r($items);
         $usr = User::findByFullname(iconv('CP1251', 'UTF-8', $items[1]));
         //print_r($usr);
         if (!isset($usr)) {
             continue;
         }
         echo '-->' . $usr->id . '<br>';
         //echo $usr->username . '<br>';
         echo trim($items[1]) . '<br>';
         echo $items[0] . '<br>';
         echo $items[2] . '<br>';
         echo $items[3] . '<br>';
         $tp = Typeprice::findOne(['type_price_name' => iconv('CP1251', 'UTF-8', $items[3])]);
         if (isset($tp)) {
             //print_r($tp);
             echo $tp->type_price_id;
         } else {
             echo '???';
             $tp = new Typeprice();
             $tp->type_price_name = iconv('CP1251', 'UTF-8', $items[3]);
             $tp->save();
         }
         $customer = Customers::findOne(['customer_1c_id' => $items[0]]);
         if (isset($customer)) {
             echo $customer->customer_id;
         } else {
             echo '???';
             $customer = new Customers();
             $customer->customer_1c_id = $items[0];
             $customer->user_id = $usr->id;
             $customer->customer_name = iconv('CP1251', 'UTF-8', $items[2]);
             $customer->typeprices_id = $tp->type_price_id;
             $customer->save();
         }
         unset($customer);
         unset($tp);
     }
     fclose($readfile);
 }