| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- <?php
- namespace addons\QiShangTong\console\controllers;
- use addons\QiDingDong\common\models\QiDingDongEvent;
- use addons\QiShangTong\common\expand\sdk\qishangtong\src\model\RegionModel;
- use addons\QiShangTong\common\expand\sdk\qishangtong\src\request\RegionRequest;
- use addons\QiShangTong\common\helper\RequestHelper;
- use addons\QiShangTong\common\listeners\OrderCreateListener;
- use addons\QiShangTong\common\listeners\OrderPaidListener;
- use addons\QiShangTong\common\listeners\OrderRefundBuyerExpressListener;
- use addons\QiShangTong\common\models\QiShangTongRegion;
- use addons\QiShangTong\common\models\QiShangTongRegionOld;
- use common\enums\StatusEnum;
- use common\models\common\Region;
- use GuzzleHttp\Exception\GuzzleException;
- use yii\console\Controller;
- use yii\helpers\Json;
- class TestController extends Controller
- {
- public function actionReq()
- {
- try {
- $a = [
- 'order_parent_sn' => '2023122209404839580432',
- 'order_sn' => '2023122209404820762242',
- 'KuaidiNo' => '11223344',
- 'Kuaidicode' => 'debangkuaidi',
- 'Kuaidiname' => '德邦快递',
- 'third_code' => 'DBL',
- 'date' => '1703209646',
- 'state' => '1',
- 'company' => '328',
- 'shipNoDetail' => '',
- 'timestamp' => '1703209682',
- 'sign' => '7642F464429BE11543AF06C651259EE6'
- ];
- echo Json::encode($a) . "\n";
- // (new OrderCreateListener())->async_handle(['order_ids' => [12032]]);
- // (new OrderPaidListener())->async_handle(['id' => 11721]);
- (new OrderRefundBuyerExpressListener())->handleSync(['id' => 390]);
- } catch (\Exception $e) {
- var_dump(1, $e->getMessage(), $e->getFile(), $e->getLine());
- } catch (GuzzleException $e) {
- var_dump(2, $e->getMessage());
- }
- }
- public function actionRegion()
- {
- $provinces = $this->region(0);
- $inserts = [];
- foreach ($provinces as $province) {
- $citys = $this->region($province['region_id']);
- $inserts[] = [
- 'name' => $province['region_name'],
- 'level' => 1,
- 'id' => $province['region_id'],
- 'province_id' => 0,
- 'province' => "",
- 'city_id' => 0,
- 'city' => "",
- 'region'=> $province['region_name'],
- 'created_at' => time(),
- 'updated_at' => time(),
- ];
- foreach ($citys as $city) {
- $districts = $this->region($city['region_id']);
- $inserts[] = [
- 'name' => $city['region_name'],
- 'level' => 2,
- 'id' => $city['region_id'],
- 'province_id' => $province['region_id'],
- 'province' => $province['region_name'],
- 'city_id' => 0,
- 'city' => "",
- 'region'=> "{$province['region_name']} {$city['region_name']}",
- 'created_at' => time(),
- 'updated_at' => time(),
- ];
- foreach ($districts as $district) {
- $inserts[] = [
- 'name' => $district['region_name'],
- 'level' => 3,
- 'id' => $district['region_id'],
- 'province_id' => $province['region_id'],
- 'province' => $province['region_name'],
- 'city_id' => $city['region_id'],
- 'city' => $city['region_name'],
- 'region'=> "{$province['region_name']} {$city['region_name']} {$district['region_name']}",
- 'created_at' => time(),
- 'updated_at' => time(),
- ];
- }
- }
- }
- $cnt = 10;
- $iArr = array_chunk($inserts, $cnt);
- foreach ($iArr as $item) {
- QiShangTongRegion::find()->createCommand()->batchInsert(QiShangTongRegion::tableName(), array_keys($item[0]), $item)->execute();
- }
- }
- public function actionOrder()
- {
- (new OrderCreateListener())->async_handle(['order_ids' => [13155]]);
- }
-
- protected function region(int $parent_id)
- {
- // 获取配送方式
- $mall_id = 1;
- $contentModel = new RegionModel();
- $contentModel->parent_id = $parent_id;
- return RequestHelper::send(new RegionRequest(), $contentModel, $mall_id);
- }
- public function actionMap()
- {
- $level = 3;
- /**
- * @var $item QiShangTongRegion
- */
- foreach (QiShangTongRegion::find()->where(['city_id' => StatusEnum::DISABLED])->andWhere(['level' => $level])->each() as $item) {
- // $parent = QiShangTongRegion::findOne(['id' => $item->city_id]);
- // $parent = QiShangTongRegion::findOne(['id' => $item->province_id]);
- // if (in_array($item->province_id, [132, 151, 2370])) {
- // $parent = Region::findOne(['name' => $parent->name, 'level' => $level]);
- // $region = Region::findOne(['name' => $item->name, 'level' => $level]); // , 'parent_id' => $parent->id
- // }
- if ($level == 3) {
- $parent = QiShangTongRegion::findOne(['id' => $item->city_id]);
- var_dump($parent);
- // die();
- // $region = Region::findOne(['name' => $item->name, 'level' => $level, 'parent_id' => $parent->local_id]);
- }
- // var_dump($parent->local_name, $parent->local_id, $item->name, !empty($region) ? $region->toArray() : []);
- // break;
- if (!empty($region)) {
- var_dump("============$item->name");
- // $item->local_id = $region->id;
- // $item->local_name = $region->name;
- if ($level == 2 && !empty($parent)) {
- // 记录省级
- $item->local_province_id = $parent->local_id;
- $item->local_province = $parent->local_province;
- } elseif ($level == 3 && !empty($parent)) {
- // 记录省级
- $item->local_province_id = $parent->local_province_id;
- $item->local_city_id = $parent->local_id;
- $item->local_province = $parent->local_province;
- $item->local_city = $parent->local_city;
- // $item->city_id = $parent
- }
- $item->save();
- } else {
- var_dump("······$item->name");
- }
- }
- }
- public function actionUp()
- {
- $mall_id = 1;
- $image = 'https://img.lanyipp.com//images/2023/11/30/image_1701317607_BuQVUdKu.jpg';
- $iInfo = getimagesize($image);
- $iContentModel = RequestHelper::contentModelInstance($mall_id);
- $iContentModel->content->data = new RefundUploadResourceModel();
- $iContentModel->content->data->file = "data:{$iInfo['mime']};base64,".base64_encode(file_get_contents($image));
- $iContentModel->content->data->resource_type = StatusEnum::ENABLED; // 图片
- $iRes = RequestHelper::send(new RefundUploadResourceRequest(), RequestHelper::enCrypto($iContentModel, $mall_id));
- var_dump($iRes);
- /**
- * array(2) {
- ["object"]=>
- string(36) "2023/12/05/20231205113728650250.jpeg"
- ["url"]=>
- string(31) "http://csstatics.7dingdong.com/"
- }
- */
- }
- public function actionFix()
- {
- /**
- * @var $item QiShangTongRegion
- */
- foreach (QiShangTongRegion::find()->each() as $item) {
- // local_id
- $old = QiShangTongRegionOld::findOne(['id' => $item->id]);
- $item->local_id = $old->local_id;
- $item->local_province_id = $old->local_province_id;
- $item->local_city_id = $old->local_city_id;
- $item->local_district_id = $old->local_district_id;
- $item->local_name = $old->local_name;
- $item->local_province = $old->local_province;
- $item->local_city = $old->local_city;
- $item->local_district = $old->local_district;
- if (!$item->save()) var_dump($item->id);
- }
- }
- public function actionDe()
- {
- foreach (QiDingDongEvent::find()->where(['content' => '[]'])->each() as $each) {
- }
- }
- }
|