コード例 #1
0
 public function actionDelete($id)
 {
     Entrance::findOne($id)->delete();
     $this->redirect('/entrance/index');
 }
コード例 #2
0
ファイル: create.php プロジェクト: vilison/yii2-order
                    <div class="help-block help-block-error "></div>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
<div style="border-top: 1px solid #e5e5e5;margin-top: 10px;">&nbsp;</div>
    <style>
        .gv-table{text-align:center;}
        .gv-table th{text-align:center;}
    </style>
<?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'summary' => false, 'emptyText' => '无关键词', 'tableOptions' => ['class' => 'table table-striped table-bordered gv-table'], 'columns' => [['class' => 'yii\\grid\\Column', 'header' => '关键词', 'content' => function ($data) {
    return Html::textInput('CommodityOrderDetail[keyword][]', $data->keyword, ['class' => 'form-control']);
}], ['class' => 'yii\\grid\\Column', 'header' => '浏览入口', 'content' => function ($data) {
    $entrances = \app\models\Entrance::find()->all();
    return Html::dropDownList('CommodityOrderDetail[eid][]', $data->eid, ArrayHelper::map($entrances, 'id', 'name'), ['class' => 'form-control']);
}], ['class' => 'yii\\grid\\Column', 'header' => '卡位条件', 'content' => function ($data) {
    return Html::textInput('CommodityOrderDetail[condition][]', $data->condition, ['class' => 'form-control']);
}], ['class' => 'yii\\grid\\Column', 'header' => '笔数', 'content' => function ($data) {
    return Html::textInput('CommodityOrderDetail[num][]', $data->num, ['class' => 'form-control']);
}], ['class' => 'yii\\grid\\Column', 'header' => '单价', 'content' => function ($data) {
    return Html::textInput('CommodityOrderDetail[price][]', $data->price, ['class' => 'form-control']);
}], ['class' => 'yii\\grid\\Column', 'header' => '佣金', 'content' => function ($data) {
    return Html::textInput('CommodityOrderDetail[fee][]', $data->fee, ['class' => 'form-control']);
}]]]);
?>

    <div class="modal-footer">
        <?php 
echo Html::submitButton('提交', ['class' => 'btn btn-primary']);
コード例 #3
0
 public function actionAuditView($id)
 {
     $model = Commodity::findOne($id);
     $commodityOrderTemplet = new CommodityOrderTemplet();
     if ($commodityOrderTemplet->load(Yii::$app->request->post())) {
         $commodityOrderTemplet->cid = $model->id;
         $entrance = Entrance::findOne($commodityOrderTemplet->eid);
         if (!empty($entrance)) {
             $commodityOrderTemplet->entrance = $entrance->name;
         }
         $commodityOrderTemplet->save();
         //$commodityOrderTemplet->dirtyAttributes;
     }
     $dataProvider = new ActiveDataProvider(['query' => CommodityOrderTemplet::find()->where('cid = :cid', [':cid' => $id])->orderBy('keyword'), 'pagination' => false]);
     $entrances = Entrance::find()->all();
     $entrances_json = array();
     foreach ($entrances as $entrance) {
         $enarray = ['value' => $entrance->id, 'text' => $entrance->name];
         array_push($entrances_json, $enarray);
     }
     $entrances_json = json_encode($entrances_json);
     return $this->render('audit-view', array('model' => $model, 'dataProvider' => $dataProvider, 'commodityOrderTemplet' => $commodityOrderTemplet, 'entrances' => $entrances, 'entrances_json' => $entrances_json));
 }
コード例 #4
0
 public function actionUpdateOrderDetail()
 {
     $id = Yii::$app->request->post('pk');
     $name = Yii::$app->request->post('name');
     $value = Yii::$app->request->post('value');
     $commodityOrderDetail = CommodityOrderDetail::findOne($id);
     $commodityOrderDetail->{$name} = $value;
     if ($name == 'eid') {
         $entrance = Entrance::findOne($value);
         if (!empty($entrance)) {
             $commodityOrderDetail->entrance = $entrance->name;
         }
     }
     if ($name == 'recommends') {
         if ($value == '0') {
             $commodityOrderDetail->recommends = '';
         } else {
             if ($value == '1') {
                 $commodityOrder = CommodityOrder::findOne($commodityOrderDetail->coid);
                 $sql = 'SELECT t.id FROM (SELECT `tbl_buyer`.`id`,COUNT(*) AS num FROM `tbl_buyer` RIGHT JOIN `tbl_order` ON `tbl_buyer`.`account` = `tbl_order`.`buyer` WHERE `tbl_buyer`.`platform` = :platform AND `tbl_buyer`.`credit_temp` >= :credit_temp  AND date_sub(curdate(), INTERVAL 30 DAY) <= date(`tbl_buyer`.`buy_time`) ORDER BY `tbl_buyer`.`weight` DESC,RAND()) AS t WHERE t.num >= :trade_num LIMIT :num';
                 $db = Yii::$app->db;
                 $command = $db->createCommand($sql);
                 $command->bindValue(":platform", $commodityOrder->platform);
                 $command->bindValue(":credit_temp", $commodityOrder->credit);
                 $command->bindValue(":trade_num", $commodityOrder->trade_num);
                 $command->bindValue(":num", $commodityOrderDetail->num);
                 $buyerArray = $command->queryColumn();
                 //                $buyers = Buyer::find()->where('platform = :platform and  and date_sub(curdate(), INTERVAL 30 DAY) <= date(buy_time)',[':platform'=>$commodityOrder->platform])->orderBy('weight desc,rand()')->limit($commodityOrderDetail->num)->all();
                 //                $buyerArray = array();
                 //                foreach($buyers as $buyer){
                 //                    $buyerArray[] = $buyer->id;
                 //                }
                 $ids = '';
                 if (!empty($buyerArray)) {
                     $ids = implode(',', $buyerArray);
                 }
                 if (empty($ids)) {
                     $result = ['status' => 'error', 'msg' => '系统推荐失败,系统没找到符合要求的买家帐号'];
                     echo json_encode($result);
                     return;
                 }
                 $commodityOrderDetail->recommends = $ids;
             }
         }
     }
     if ($name == 'uid') {
         $commodityOrderDetail->recommend_time = date('Y-m-d H:i:s');
     }
     if ($commodityOrderDetail->save()) {
         $commodityOrderDetails = CommodityOrderDetail::find()->where('coid = :coid', [':coid' => $commodityOrderDetail->coid])->all();
         $corpus = 0;
         $total_fee = 0;
         $budget_num = 0;
         foreach ($commodityOrderDetails as $cod) {
             $num = intval($cod->num);
             $price = floatval($cod->price);
             $fee = floatval($cod->fee);
             $total_price = $num * $price;
             $sum_fee = $num * $fee;
             $corpus += $total_price;
             $total_fee += $sum_fee;
             $budget_num += $num;
         }
         $statistics = Statistics::find()->where('coid = :coid', [':coid' => $commodityOrderDetail->coid])->one();
         $statistics->corpus = $corpus;
         $statistics->total_fee = $total_fee;
         $statistics->budget_num = $budget_num;
         $statistics->save();
     }
     $result = ['status' => 'sucess'];
     echo json_encode($result);
 }