TestController.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. namespace addons\QiShangTong\console\controllers;
  3. use addons\QiDingDong\common\models\QiDingDongEvent;
  4. use addons\QiShangTong\common\expand\sdk\qishangtong\src\model\RegionModel;
  5. use addons\QiShangTong\common\expand\sdk\qishangtong\src\request\RegionRequest;
  6. use addons\QiShangTong\common\helper\RequestHelper;
  7. use addons\QiShangTong\common\listeners\OrderCreateListener;
  8. use addons\QiShangTong\common\listeners\OrderPaidListener;
  9. use addons\QiShangTong\common\listeners\OrderRefundBuyerExpressListener;
  10. use addons\QiShangTong\common\models\QiShangTongRegion;
  11. use addons\QiShangTong\common\models\QiShangTongRegionOld;
  12. use common\enums\StatusEnum;
  13. use common\models\common\Region;
  14. use GuzzleHttp\Exception\GuzzleException;
  15. use yii\console\Controller;
  16. use yii\helpers\Json;
  17. class TestController extends Controller
  18. {
  19. public function actionReq()
  20. {
  21. try {
  22. $a = [
  23. 'order_parent_sn' => '2023122209404839580432',
  24. 'order_sn' => '2023122209404820762242',
  25. 'KuaidiNo' => '11223344',
  26. 'Kuaidicode' => 'debangkuaidi',
  27. 'Kuaidiname' => '德邦快递',
  28. 'third_code' => 'DBL',
  29. 'date' => '1703209646',
  30. 'state' => '1',
  31. 'company' => '328',
  32. 'shipNoDetail' => '',
  33. 'timestamp' => '1703209682',
  34. 'sign' => '7642F464429BE11543AF06C651259EE6'
  35. ];
  36. echo Json::encode($a) . "\n";
  37. // (new OrderCreateListener())->async_handle(['order_ids' => [12032]]);
  38. // (new OrderPaidListener())->async_handle(['id' => 11721]);
  39. (new OrderRefundBuyerExpressListener())->handleSync(['id' => 390]);
  40. } catch (\Exception $e) {
  41. var_dump(1, $e->getMessage(), $e->getFile(), $e->getLine());
  42. } catch (GuzzleException $e) {
  43. var_dump(2, $e->getMessage());
  44. }
  45. }
  46. public function actionRegion()
  47. {
  48. $provinces = $this->region(0);
  49. $inserts = [];
  50. foreach ($provinces as $province) {
  51. $citys = $this->region($province['region_id']);
  52. $inserts[] = [
  53. 'name' => $province['region_name'],
  54. 'level' => 1,
  55. 'id' => $province['region_id'],
  56. 'province_id' => 0,
  57. 'province' => "",
  58. 'city_id' => 0,
  59. 'city' => "",
  60. 'region'=> $province['region_name'],
  61. 'created_at' => time(),
  62. 'updated_at' => time(),
  63. ];
  64. foreach ($citys as $city) {
  65. $districts = $this->region($city['region_id']);
  66. $inserts[] = [
  67. 'name' => $city['region_name'],
  68. 'level' => 2,
  69. 'id' => $city['region_id'],
  70. 'province_id' => $province['region_id'],
  71. 'province' => $province['region_name'],
  72. 'city_id' => 0,
  73. 'city' => "",
  74. 'region'=> "{$province['region_name']} {$city['region_name']}",
  75. 'created_at' => time(),
  76. 'updated_at' => time(),
  77. ];
  78. foreach ($districts as $district) {
  79. $inserts[] = [
  80. 'name' => $district['region_name'],
  81. 'level' => 3,
  82. 'id' => $district['region_id'],
  83. 'province_id' => $province['region_id'],
  84. 'province' => $province['region_name'],
  85. 'city_id' => $city['region_id'],
  86. 'city' => $city['region_name'],
  87. 'region'=> "{$province['region_name']} {$city['region_name']} {$district['region_name']}",
  88. 'created_at' => time(),
  89. 'updated_at' => time(),
  90. ];
  91. }
  92. }
  93. }
  94. $cnt = 10;
  95. $iArr = array_chunk($inserts, $cnt);
  96. foreach ($iArr as $item) {
  97. QiShangTongRegion::find()->createCommand()->batchInsert(QiShangTongRegion::tableName(), array_keys($item[0]), $item)->execute();
  98. }
  99. }
  100. public function actionOrder()
  101. {
  102. (new OrderCreateListener())->async_handle(['order_ids' => [13155]]);
  103. }
  104. protected function region(int $parent_id)
  105. {
  106. // 获取配送方式
  107. $mall_id = 1;
  108. $contentModel = new RegionModel();
  109. $contentModel->parent_id = $parent_id;
  110. return RequestHelper::send(new RegionRequest(), $contentModel, $mall_id);
  111. }
  112. public function actionMap()
  113. {
  114. $level = 3;
  115. /**
  116. * @var $item QiShangTongRegion
  117. */
  118. foreach (QiShangTongRegion::find()->where(['city_id' => StatusEnum::DISABLED])->andWhere(['level' => $level])->each() as $item) {
  119. // $parent = QiShangTongRegion::findOne(['id' => $item->city_id]);
  120. // $parent = QiShangTongRegion::findOne(['id' => $item->province_id]);
  121. // if (in_array($item->province_id, [132, 151, 2370])) {
  122. // $parent = Region::findOne(['name' => $parent->name, 'level' => $level]);
  123. // $region = Region::findOne(['name' => $item->name, 'level' => $level]); // , 'parent_id' => $parent->id
  124. // }
  125. if ($level == 3) {
  126. $parent = QiShangTongRegion::findOne(['id' => $item->city_id]);
  127. var_dump($parent);
  128. // die();
  129. // $region = Region::findOne(['name' => $item->name, 'level' => $level, 'parent_id' => $parent->local_id]);
  130. }
  131. // var_dump($parent->local_name, $parent->local_id, $item->name, !empty($region) ? $region->toArray() : []);
  132. // break;
  133. if (!empty($region)) {
  134. var_dump("============$item->name");
  135. // $item->local_id = $region->id;
  136. // $item->local_name = $region->name;
  137. if ($level == 2 && !empty($parent)) {
  138. // 记录省级
  139. $item->local_province_id = $parent->local_id;
  140. $item->local_province = $parent->local_province;
  141. } elseif ($level == 3 && !empty($parent)) {
  142. // 记录省级
  143. $item->local_province_id = $parent->local_province_id;
  144. $item->local_city_id = $parent->local_id;
  145. $item->local_province = $parent->local_province;
  146. $item->local_city = $parent->local_city;
  147. // $item->city_id = $parent
  148. }
  149. $item->save();
  150. } else {
  151. var_dump("······$item->name");
  152. }
  153. }
  154. }
  155. public function actionUp()
  156. {
  157. $mall_id = 1;
  158. $image = 'https://img.lanyipp.com//images/2023/11/30/image_1701317607_BuQVUdKu.jpg';
  159. $iInfo = getimagesize($image);
  160. $iContentModel = RequestHelper::contentModelInstance($mall_id);
  161. $iContentModel->content->data = new RefundUploadResourceModel();
  162. $iContentModel->content->data->file = "data:{$iInfo['mime']};base64,".base64_encode(file_get_contents($image));
  163. $iContentModel->content->data->resource_type = StatusEnum::ENABLED; // 图片
  164. $iRes = RequestHelper::send(new RefundUploadResourceRequest(), RequestHelper::enCrypto($iContentModel, $mall_id));
  165. var_dump($iRes);
  166. /**
  167. * array(2) {
  168. ["object"]=>
  169. string(36) "2023/12/05/20231205113728650250.jpeg"
  170. ["url"]=>
  171. string(31) "http://csstatics.7dingdong.com/"
  172. }
  173. */
  174. }
  175. public function actionFix()
  176. {
  177. /**
  178. * @var $item QiShangTongRegion
  179. */
  180. foreach (QiShangTongRegion::find()->each() as $item) {
  181. // local_id
  182. $old = QiShangTongRegionOld::findOne(['id' => $item->id]);
  183. $item->local_id = $old->local_id;
  184. $item->local_province_id = $old->local_province_id;
  185. $item->local_city_id = $old->local_city_id;
  186. $item->local_district_id = $old->local_district_id;
  187. $item->local_name = $old->local_name;
  188. $item->local_province = $old->local_province;
  189. $item->local_city = $old->local_city;
  190. $item->local_district = $old->local_district;
  191. if (!$item->save()) var_dump($item->id);
  192. }
  193. }
  194. public function actionDe()
  195. {
  196. foreach (QiDingDongEvent::find()->where(['content' => '[]'])->each() as $each) {
  197. }
  198. }
  199. }