<commit_before><?php
namespace app\modules\api\controllers\common;

use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
use yii\data\Pagination;


use app\modules\api\models\common\Cart;
use app\modules\api\models\common\Sku;
use app\modules\api\models\common\Order;
use yii\filters\Cors;
use yii\data\ActiveDataProvider;
/**
 * Site controller
 */
class OrderController extends Controller
{
	public $modelClass = 'app\modules\api\models\common\Order';

    public function behaviors()
    {
        return ArrayHelper::merge([
            [
                'class' => Cors::className(),
                'cors' => [
                    'Origin' => ['*'],
                    'Access-Control-Request-Method' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],
                    'Access-Control-Request-Headers' => ['*'],
                ]
            ],
        ], parent::behaviors());
    }

    public function actions() {  
        $actions = parent::actions();  
        // 禁用""index,delete" 和 "create" 操作  
        unset($actions['delete'], $actions['create'], $actions['view']);


        $actions['index']['prepareDataProvider'] = [$this, '_index'];
        return $actions;
    }

    public function _index()
    {
        $params = Yii::$app->request->queryParams;

        $modelClass = $this->modelClass;

        $query = $modelClass::find()->orderBy('id desc');

        if (!isset($params['user_id'])) {
            return ['errno'=>1, 'error'=>'不合法的用户id'];
        }


        $query->andWhere(['user_id'=>$params['user_id']]);

        if (isset($params['status'])) {
            $query->andWhere(['status'=>$params['status']]);
        } else {
            $query->andWhere(['<>', 'status', $modelClass::STATUS_DELETE]);
        }




        $pageSize = 10;
        if (isset($params['pageSize'])) {
            $pageSize = $params['pageSize'];
        }

        return new ActiveDataProvider([
            'query' => $query,
            'pagination' => new Pagination(['pageSize'=>$pageSize])
        ]);
    }

    public function actionDel()
    {
        $post = Yii::$app->request->post();
        $order_id = $post['order_id'];

        $order = Order::findOne($post['order_id']);
        $order->status = Order::STATUS_DELETE;
        return $order->save();
    }

    /**
     * @name 订单详情
     */
    public function actionView($id, $thumb="")
    {

        $order = Order::findOne($id);
        $rels = $order->rels;

        //支付方式
        $pays = $order->pays;
        $pay_type = '';
        foreach ($pays as $k => $v) {
            $pay_type .= $v->method . ' ';
        }


        $order_data = $order->toArray();
        $order_data['created_date'] = date('Y-m-d H:i', $order_data['created_at']);
        $order_data['pay_type'] = $pay_type;
        $order_data['pro'] = $order->pro;

        $rels_data = [];
        foreach ($rels as $k => $v) {
            $rels_data[$v->id] = $v->toArray();
            if (!$v->goods){
                continue;
            }
            $rels_data[$v->id]['cover'] = self::$base_url . $v->goods->getCover($thumb);<commit_msg>order<commit_after><?php
namespace app\modules\api\controllers\common;

use app\modules\order\models\OrderRel;
use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
use yii\data\Pagination;


use app\modules\api\models\common\Cart;
use app\modules\api\models\common\Sku;
use app\modules\api\models\common\Order;
use yii\filters\Cors;
use yii\data\ActiveDataProvider;
/**
 * Site controller
 */
class OrderController extends Controller
{
	public $modelClass = 'app\modules\api\models\common\Order';

    public function behaviors()
    {
        return ArrayHelper::merge([
            [
                'class' => Cors::className(),
                'cors' => [
                    'Origin' => ['*'],
                    'Access-Control-Request-Method' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],
                    'Access-Control-Request-Headers' => ['*'],
                ]
            ],
        ], parent::behaviors());
    }

    public function actions() {  
        $actions = parent::actions();  
        // 禁用""index,delete" 和 "create" 操作  
        unset($actions['delete'], $actions['create'], $actions['view']);


        $actions['index']['prepareDataProvider'] = [$this, '_index'];
        return $actions;
    }

    public function _index()
    {
        $params = Yii::$app->request->queryParams;

        $modelClass = $this->modelClass;

        $query = $modelClass::find()->orderBy('id desc');

        if (!isset($params['user_id'])) {
            return ['errno'=>1, 'error'=>'不合法的用户id'];
        }


        $query->andWhere(['user_id'=>$params['user_id']]);

        if (isset($params['status'])) {
            $query->andWhere(['status'=>$params['status']]);
        } else {
            $query->andWhere(['<>', 'status', $modelClass::STATUS_DELETE]);
        }




        $pageSize = 10;
        if (isset($params['pageSize'])) {
            $pageSize = $params['pageSize'];
        }

        return new ActiveDataProvider([
            'query' => $query,
            'pagination' => new Pagination(['pageSize'=>$pageSize])
        ]);
    }

    public function actionDel()
    {
        $post = Yii::$app->request->post();
        $order = Order::findOne($post['order_id']);
        $order->status = Order::STATUS_DELETE;
        if ($order->save() !== false) {
            return true;
        }

        return ['error'=>'删除失败', 'errno'=>1];
    }

    public function actionDelRelOrder()
    {
        $post = Yii::$app->request->post();
        $rel = OrderRel::findOne($post['rel_id']);
        $rel->status = Order::STATUS_DELETE;
        if ($rel->save() !== false) {
            $rel->order->updatePrice();
            return true;
        }

        return ['error'=>'删除失败', 'errno'=>1];
    }

    /**
     * @name 订单详情
     */
    public function actionView($id, $thumb="")
    {

        $order = Order::findOne($id);
        $rels = $order->rels;

        //支付方式
        $pays = $order->pays;
        $pay_type = '';
        foreach ($pays as $k => $v) {
            $pay_type .= $v->method . ' ';
        }


        $order_data = $order->toArray();
        $order_data['created_date'] = date('Y-m-d H:i', $order_data['created_at']);
        $order_data['pay_type'] = $pay_type;
        $order_data['pro'] = $order->pro;

        $rels_data = [];
        foreach ($rels as $k => $v) {
            $rels_data[$v->id] = $v->toArray();
            if (!$v->goods){
                continue;
            }
            $rels_data[$v->id]['cover'] = self::$base_url . $v->goods->getCover($thumb);
{'fraction_non_alphanumeric': 0.1908180050844923, 'fraction_numerical': 0.001196351129056378, 'mean_word_length': 2.0948634891254048, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 87, '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': '5520607', 'n_tokens_mistral': 2123, 'n_tokens_neox': 2073, 'n_words': 345}