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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace console\controllers;
  3. use backend\modules\shop\models\ars\Order;
  4. use backend\modules\shop\models\ars\OrderGoods;
  5. use Yii;
  6. use yii\console\Controller;
  7. use yii\db\Exception;
  8. use yii\helpers\Console;
  9. /**
  10. * Description of RbacsetController
  11. *
  12. * @author blobt
  13. */
  14. class TestController extends Controller {
  15. public function actionIndex() {
  16. //Yii::$aa->security->generateRandomString(8);
  17. $security = Yii::createObject("yii\base\Security");
  18. $n = 0;
  19. for ($i = 1; $i < 1000; $i++) {
  20. //$key = $security->generateRandomString(8);
  21. $key = rand(10000000, 99999999);
  22. //$key = strtolower($key);
  23. //$key = str_replace(['_', '-'], 'a', $key);
  24. $ret[$key] += 1;
  25. }
  26. $this->stdout("duplicate data:\n", Console::FG_RED);
  27. foreach ($ret as $k => $v) {
  28. if ($v > 1) {
  29. echo "$k $v\n";
  30. }
  31. }
  32. }
  33. public function actionOrderGoods()
  34. {
  35. $transaction = Yii::$app->db->beginTransaction();
  36. try {
  37. $order = new Order();
  38. $order->user_id = 1;
  39. $order->type = Order::TYPE_SHOPPING;
  40. $order->order_sn = date('Ymd', time()) . rand(0, 100);
  41. $order->invoice_id = date('Ymd', time()) . rand(0, 100);
  42. $order->consignee = '温xx';
  43. $order->phone = '17727716697';
  44. $order->goods_count = rand(10, 33);
  45. $order->goods_amount = rand(10, 100);
  46. $order->shipping_type = 0;
  47. $order->shipping_amount = rand(10, 100);
  48. $order->address = '地址地址测试地址';
  49. if (!$order->save()) {
  50. throw new Exception('save order false');
  51. }
  52. for ($i = 1; $i <= 3; $i++) {
  53. $orderGoods = new OrderGoods();
  54. $orderGoods->order_id = $order->id;
  55. $orderGoods->goods_id = $i;
  56. $orderGoods->goods_name = '测试商品' . $i;
  57. $orderGoods->goods_count = rand(1, 10);
  58. $orderGoods->sku_value = 'sku值1';
  59. $orderGoods->price = rand(100, 999);
  60. $orderGoods->market_price = $orderGoods->price + 166;
  61. $orderGoods->weight = rand(1, 10);
  62. $orderGoods->sku_id = 0;
  63. if (!$orderGoods->save()) {
  64. throw new Exception('orderGoods save false');
  65. }
  66. }
  67. $transaction->commit();
  68. echo "ok\n";
  69. } catch (Exception $e) {
  70. $transaction->rollBack();
  71. print_r($e->getMessage());
  72. }
  73. }
  74. }