public function validateBuyer($attribute, $params) { echo 'validateBuyer'; $buyer = Buyer::find()->where('account = :account', [':account' => $this->{$attribute}])->one(); if (is_null($buyer)) { return $this->addError($attribute, '买家不存在'); } $buyer->isBuy = 1; $buyer->buy_time = $this->order_time; $buyer->save(); $check = false; if ($this->scenario == 'create') { $check = true; } if ($this->scenario == 'update') { $order = Order::find($this->id); if (!is_null($order) && $order->buyer != $this->{$attribute}) { $check = true; } } if ($check) { $count = (new Query())->from(Order::tableName())->where('buyer = :buyer AND commodity = :commodity AND DATE(create_time) = DATE (now())', [':buyer' => $this->{$attribute}, ':commodity' => $this->commodity])->count(); if ($count > 0) { return $this->addError($attribute, '该买家今天已提交该商品订单'); } } }
public function actionImport() { //$this->redirect('/buyer/index'); $model = new Buyer(); if (Yii::$app->request->isPost) { $model->file = UploadedFile::getInstance($model, 'file'); if ($model->file->extension == 'xls') { $model->file->saveAs('uploads/up.xls'); //require('/vendor/excel_reader2.php'); require_once '../vendor/excel_reader2.php'; $data = new Spreadsheet_Excel_Reader(); //设置文本输出编码 $data->setOutputEncoding('UTF-8'); $data->read('uploads/up.xls'); //读取excel $arr1 = array(); $arr2 = array(); $arr3 = array(); $arr4 = array(); $arr5 = array(); $arr6 = array(); $arr7 = array(); $arr8 = array(); for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) { //显示每个单元格内容 $arr1[$data->sheets[0]['cells'][$i][1]] = $data->sheets[0]['cells'][$i][1]; $arr2[$data->sheets[0]['cells'][$i][1]] = $data->sheets[0]['cells'][$i][2]; $arr3[$data->sheets[0]['cells'][$i][1]] = $data->sheets[0]['cells'][$i][3]; $arr4[$data->sheets[0]['cells'][$i][1]] = $data->sheets[0]['cells'][$i][4]; $arr5[$data->sheets[0]['cells'][$i][1]] = $data->sheets[0]['cells'][$i][5]; $arr6[$data->sheets[0]['cells'][$i][1]] = empty($data->sheets[0]['cells'][$i][6]) ? '' : $data->sheets[0]['cells'][$i][6]; $arr7[$data->sheets[0]['cells'][$i][1]] = $data->sheets[0]['cells'][$i][7]; $arr8[$data->sheets[0]['cells'][$i][1]] = $data->sheets[0]['cells'][$i][8]; $buyer = new Buyer(); $buyer->platform = $arr1[$data->sheets[0]['cells'][$i][1]]; $buyer->account = $arr2[$data->sheets[0]['cells'][$i][1]]; $buyer->pass = $arr3[$data->sheets[0]['cells'][$i][1]]; $buyer->pay_account = $arr4[$data->sheets[0]['cells'][$i][1]]; $buyer->pay_pass = $arr5[$data->sheets[0]['cells'][$i][1]]; $buyer->regarea = $arr6[$data->sheets[0]['cells'][$i][1]]; $buyer->regphone = $arr7[$data->sheets[0]['cells'][$i][1]]; $buyer->remark = $arr8[$data->sheets[0]['cells'][$i][1]]; $buyer->create_time = date('Y-m-d H:i:s'); $exists = Buyer::find()->where('account = :account', [':account' => $buyer->account])->one(); if (is_null($exists)) { $buyer->save(); } } $i = $i - 2; echo "\t<meta charset='utf-8'>"; echo "<script>alert('成功导入" . $i . "个小号')</script>"; //echo "<script>history.go(-1);</script>"; } else { echo "\t<meta charset='utf-8'>"; echo "<script>alert('上传失败')</script>"; echo "<script>history.go(-1);</script>"; } return; } return $this->renderAjax('import', ['model' => $model]); }
return $data['keyword']; }], ['attribute' => '浏览入口', 'value' => function ($data) { return $data['entrance']; }], ['attribute' => '卡位条件', 'value' => function ($data) { if (empty($data['condition'])) { $data['condition'] = ''; } return $data['condition']; }], ['attribute' => '笔数', 'value' => function ($data) { return $data['num']; }], ['attribute' => '单价', 'value' => function ($data) { return $data['price']; }], ['class' => 'yii\\grid\\Column', 'header' => '推荐', 'content' => function ($data) { $result = ''; if (!empty($data['recommends'])) { $buyers = Buyer::find()->where('id in (:id)', [':id' => $data['recommends']])->all(); foreach ($buyers as $buyer) { $result .= '[' . $buyer->account . ',' . $buyer->pass . ']<br/>'; } } return $result; }], ['class' => 'yii\\grid\\ActionColumn', 'header' => '操作', 'template' => '{view}', 'buttons' => ['view' => function ($url, $data, $key) { $icon = '<span class="glyphicon glyphicon-eye-open"></span>'; $html = '<a href="view?id=' . $data['id'] . '" title="查看">' . $icon . '</a>'; return $html; }]]]]); echo LinkPager::widget(['pagination' => $pages]); echo Html::endForm(); Yii::$app->view->registerJs(' $("ul.pagination li a").click(function () { var page = $(this).attr(\'href\');