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.

121 lines
3.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 backend\modules\shop\models\ars\WxPayConfig;
  6. use common\models\User;
  7. use Yii;
  8. use yii\console\Controller;
  9. use yii\db\Exception;
  10. use yii\helpers\Console;
  11. /**
  12. * Description of RbacsetController
  13. *
  14. * @author blobt
  15. */
  16. class TestController extends Controller {
  17. public function actionIndex() {
  18. //Yii::$aa->security->generateRandomString(8);
  19. $security = Yii::createObject("yii\base\Security");
  20. $n = 0;
  21. for ($i = 1; $i < 1000; $i++) {
  22. //$key = $security->generateRandomString(8);
  23. $key = rand(10000000, 99999999);
  24. //$key = strtolower($key);
  25. //$key = str_replace(['_', '-'], 'a', $key);
  26. $ret[$key] += 1;
  27. }
  28. $this->stdout("duplicate data:\n", Console::FG_RED);
  29. foreach ($ret as $k => $v) {
  30. if ($v > 1) {
  31. echo "$k $v\n";
  32. }
  33. }
  34. }
  35. /**
  36. * 增加订单商品测试数据
  37. */
  38. public function actionOrderGoods()
  39. {
  40. $transaction = Yii::$app->db->beginTransaction();
  41. try {
  42. $order = new Order();
  43. $order->user_id = 1;
  44. $order->status = Order::STATUS_TO_BE_SHIPPING;
  45. $order->type = Order::TYPE_SHOPPING;
  46. $order->order_sn = date('Ymd', time()) . rand(0, 100);
  47. $order->invoice_id = date('Ymd', time()) . rand(0, 100);
  48. $order->consignee = '温xx';
  49. $order->phone = '17727716697';
  50. $order->goods_count = rand(10, 33);
  51. $order->goods_amount = rand(10, 100);
  52. $order->shipping_type = 0;
  53. $order->shipping_amount = rand(10, 100);
  54. $order->address = '地址地址测试地址';
  55. if (!$order->save()) {
  56. throw new Exception('save order false');
  57. }
  58. for ($i = 1; $i <= 3; $i++) {
  59. $orderGoods = new OrderGoods();
  60. $orderGoods->order_id = $order->id;
  61. $orderGoods->goods_id = $i;
  62. $orderGoods->goods_name = '测试商品' . $i;
  63. $orderGoods->goods_count = rand(1, 10);
  64. $orderGoods->sku_value = 'sku值1';
  65. $orderGoods->price = rand(100, 999);
  66. $orderGoods->market_price = $orderGoods->price + 166;
  67. $orderGoods->weight = rand(1, 10);
  68. $orderGoods->sku_id = 0;
  69. if (!$orderGoods->save()) {
  70. throw new Exception('orderGoods save false');
  71. }
  72. }
  73. $transaction->commit();
  74. echo "ok\n";
  75. } catch (Exception $e) {
  76. $transaction->rollBack();
  77. print_r($e->getMessage());
  78. }
  79. }
  80. public function actionUser()
  81. {
  82. $user = new User();
  83. $user->auth_key = '111';
  84. $user->password_hash = '111';
  85. if ($user->save()) {
  86. echo 'ok'."\n";
  87. } else {
  88. print_r($user->errors);
  89. echo 'fail'."\n";
  90. }
  91. }
  92. public function actionWxPayConfig()
  93. {
  94. $wxPayConfig = WxPayConfig::find()->one();
  95. if (!$wxPayConfig) {
  96. $wxPayConfig = new WxPayConfig();
  97. }
  98. $wxPayConfig->user_id = 1;
  99. $wxPayConfig->mch_id = 1395812402;
  100. $wxPayConfig->key = '51CF5EE3B2E35B9843E17E6099325A65';
  101. $wxPayConfig->key_path = '';
  102. $wxPayConfig->cert_path = '';
  103. if ($wxPayConfig->save()) {
  104. echo "ok\n";
  105. } else {
  106. echo "fail\n";
  107. }
  108. }
  109. }