<commit_before><?php

namespace frontend\controllers;

use frontend\models\forms\AddProductForm;
use Yii;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use common\models\UserProductAddress;
use common\models\Product;
use common\models\Account;
use yii\helpers\Url;
use \PDO;

class ProductController extends \yii\web\Controller {

    /**
     * 商品列表
     * @return type
     */
    public function actionIndex() {
        return $this->render('index');
    }

    /**
     * 添加商品
     */
    public function actionAddproduct() {
        $model = new AddProductForm();
        $p_param = Yii::$app->request->get();
        $oneProduct = '';
        if (isset($p_param['id'])) {
            $oneProduct = Product::find()->where("product_id=:id", [':id' => $p_param['id']])->one();
            if ($oneProduct) {
                $model->setAttributes($oneProduct->attributes);
            }
        }
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
            if ($oneProduct) {
                $oneProduct->setAttributes($model->attributes);
                if ($oneProduct->update()) {
                    $error = '更新成功';
                    $notices = array('type' => 2, 'msgtitle' => '操作成功', 'message' => $error, 'backurl' => Url::toRoute('/product/addproduct/' . $oneProduct->product_id), 'backtitle' => '返回');
                    Yii::$app->getSession()->setFlash('wechat_fail', array($notices));
                    $this->redirect(Url::toRoute('/public/notices'));
                } else {
                    return $this->render('product_add', [
                                'model' => $model,
                    ]);
                }
            } else if ($model->save()) {
                $error = '添加成功,请继续添加商品图片';
                $pid = Yii::$app->db->getLastInsertID();
                $notices = array('type' => 2, 'msgtitle' => '操作成功', 'message' => $error, 'backurl' => Url::toRoute('/member/product/selectimg' . $pid), 'backtitle' => '选择商品图片');
                Yii::$app->getSession()->setFlash('wechat_fail', array($notices));
                $this->redirect(Url::toRoute('/public/notices'));
            } else {
                return $this->render('product_add', [
                            'model' => $model,
                ]);
            }
        } else {
            return $this->render('product_add', [
                        'model' => $model,
            ]);
        }
    }

    public function actionBuy() {

        $this->view->title = "购买商品";
        $error = "";
        $backUrl = \Yii::$app->request->referrer;
        if (isset($_GET['id'])) {
            $pid = $_GET['id'];
            $product = Product::find()->where("product_id=:id", [':id' => $pid])->one();
            if ($product) {
                #获得用户的可用资金
                $user_id = \Yii::$app->user->getId();
                if ($user_id == $product->product_user_id) {
                    $error = "不允许购买自己的商品。";
                    $notices = array('type' => 2, 'msgtitle' => '错误信息', 'message' => $error, 'backurl' => $backUrl, 'backtitle' => '返回');
                } else {<commit_msg>首页动态加商品<commit_after><?php

namespace frontend\controllers;

use frontend\models\forms\AddProductForm;
use Yii;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use common\models\UserProductAddress;
use common\models\Product;
use common\models\Account;
use yii\helpers\Url;
use \PDO;

class ProductController extends \yii\web\Controller {

    /**
     * 商品列表
     * @return type
     */
    public function actionIndex() {
        return $this->render('index');
    }

    /**
     * 添加商品
     */
    public function actionAddproduct() {
        $model = new AddProductForm();
        $p_param = Yii::$app->request->get();
        $oneProduct = '';
        if (isset($p_param['id'])) {
            $oneProduct = Product::find()->where("product_id=:id", [':id' => $p_param['id']])->one();
            if ($oneProduct) {
                $model->setAttributes($oneProduct->attributes);
            }
        }
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
            if ($oneProduct) {
                $oneProduct->setAttributes($model->attributes);
                if ($oneProduct->update()) {
                    $error = '更新成功';
                    $notices = array('type' => 2, 'msgtitle' => '操作成功', 'message' => $error, 'backurl' => Url::toRoute('/product/addproduct/' . $oneProduct->product_id), 'backtitle' => '返回');
                    Yii::$app->getSession()->setFlash('wechat_fail', array($notices));
                    $this->redirect(Url::toRoute('/public/notices'));
                } else {
                    return $this->render('product_add', [
                                'model' => $model,
                    ]);
                }
            } else if ($model->save()) {
                $error = '添加成功,请继续添加商品图片';
                $pid = Yii::$app->db->getLastInsertID();
                $notices = array('type' => 2, 'msgtitle' => '操作成功', 'message' => $error, 'backurl' => Url::toRoute('/member/product/selectimg/' . $pid), 'backtitle' => '选择商品图片');
                Yii::$app->getSession()->setFlash('wechat_fail', array($notices));
                $this->redirect(Url::toRoute('/public/notices'));
            } else {
                return $this->render('product_add', [
                            'model' => $model,
                ]);
            }
        } else {
            return $this->render('product_add', [
                        'model' => $model,
            ]);
        }
    }

    public function actionBuy() {

        $this->view->title = "购买商品";
        $error = "";
        $backUrl = \Yii::$app->request->referrer;
        if (isset($_GET['id'])) {
            $pid = $_GET['id'];
            $product = Product::find()->where("product_id=:id", [':id' => $pid])->one();
            if ($product) {
                #获得用户的可用资金
                $user_id = \Yii::$app->user->getId();
                if ($user_id == $product->product_user_id) {
                    $error = "不允许购买自己的商品。";
                    $notices = array('type' => 2, 'msgtitle' => '错误信息', 'message' => $error, 'backurl' => $backUrl, 'backtitle' => '返回');
                } else {
{'fraction_non_alphanumeric': 0.18536197295147175, 'fraction_numerical': 0.0009546539379474941, 'mean_word_length': 1.80875781948168, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 115, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2546554', 'n_tokens_mistral': 1957, 'n_tokens_neox': 1968, 'n_words': 304}