You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

85 lines
2.6 KiB

<?php
namespace console\controllers;
use backend\modules\shop\models\ars\Order;
use backend\modules\shop\models\ars\OrderGoods;
use Yii;
use yii\console\Controller;
use yii\db\Exception;
use yii\helpers\Console;
/**
* Description of RbacsetController
*
* @author blobt
*/
class TestController extends Controller {
public function actionIndex() {
//Yii::$aa->security->generateRandomString(8);
$security = Yii::createObject("yii\base\Security");
$n = 0;
for ($i = 1; $i < 1000; $i++) {
//$key = $security->generateRandomString(8);
$key = rand(10000000, 99999999);
//$key = strtolower($key);
//$key = str_replace(['_', '-'], 'a', $key);
$ret[$key] += 1;
}
$this->stdout("duplicate data:\n", Console::FG_RED);
foreach ($ret as $k => $v) {
if ($v > 1) {
echo "$k $v\n";
}
}
}
public function actionOrderGoods()
{
$transaction = Yii::$app->db->beginTransaction();
try {
$order = new Order();
$order->user_id = 1;
$order->type = Order::TYPE_SHOPPING;
$order->order_sn = date('Ymd', time()) . rand(0, 100);
$order->invoice_id = date('Ymd', time()) . rand(0, 100);
$order->consignee = '温xx';
$order->phone = '17727716697';
$order->goods_count = rand(10, 33);
$order->goods_amount = rand(10, 100);
$order->shipping_type = 0;
$order->shipping_amount = rand(10, 100);
$order->address = '地址地址测试地址';
if (!$order->save()) {
throw new Exception('save order false');
}
for ($i = 1; $i <= 3; $i++) {
$orderGoods = new OrderGoods();
$orderGoods->order_id = $order->id;
$orderGoods->goods_id = $i;
$orderGoods->goods_name = '测试商品' . $i;
$orderGoods->goods_count = rand(1, 10);
$orderGoods->sku_value = 'sku值1';
$orderGoods->price = rand(100, 999);
$orderGoods->market_price = $orderGoods->price + 166;
$orderGoods->weight = rand(1, 10);
$orderGoods->sku_id = 0;
if (!$orderGoods->save()) {
throw new Exception('orderGoods save false');
}
}
$transaction->commit();
echo "ok\n";
} catch (Exception $e) {
$transaction->rollBack();
print_r($e->getMessage());
}
}
}