| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- <?php
- namespace console\controllers;
- use addons\Achievement\common\listeners\order\OrderPayRewardListener as OrderOrderPayRewardListener;
- use addons\Achievement\common\models\AchievementGrantLog;
- use addons\Agent\common\listeners\order\OrderPayRewardListener;
- use addons\ServicePointAppointment\common\enums\ServicePointAppointmentEnums;
- use addons\ServicePointAppointment\common\logic\ConditionUpgrade;
- use addons\ServicePointAppointment\common\models\ServicePointLevel;
- use addons\ServicePointAppointment\common\models\ServicePointUser;
- use common\components\BaseEvent;
- use common\enums\StatusEnum;
- use common\models\mall\Mall;
- use common\models\order\OrderUnreadMsg;
- use common\models\user\User;
- use yii\console\Controller;
- use common\events\order\OrderPaidEvent;
- use common\events\order\OrderCreateEvent;
- use common\events\order\OrderTakeDeliveryEvent;
- use common\events\order\OrderFinishEvent;
- use common\models\order\Order;
- use common\models\user\UserInviteCode;
- use addons\CardCoupons\common\sms\SmsBase;
- use addons\CloudStock\common\models\CloudStockAgent;
- use addons\CardCoupons\common\listeners\order\OrderFinishRewardListener;
- use common\helpers\DateHelper;
- class AutoTestController extends Controller
- {
- public function actionEe(){
- $event = new OrderPaidEvent(5);
- $order['id'] = 1;
- $order['operator_id'] = $params['operator_id'] ?? 0;
- $order['operator_name'] = $params['operator_name'] ?? '';
- $order['is_admin'] = (int)!empty($params['is_admin']);
- \Yii::$app->services->events->dispatch($event, $order, $event->listeners);
- exit;
- $data = [];
- (new \addons\AgentBase\common\listeners\order\OrderPayRewardListener())->handleSync($data);
- // $ids = [798155,797417,784601,756116,580755];
- $ids = [380140,380141,380142,380143,380144];
- $mall_id = 26;
- $supply_id = 20;
- $api = ApiService::getConnect($mall_id, $supply_id);
- // id转Int
- $ids = array_map(function ($v) {
- return (int) $v;
- }, $ids);
- // 商品详情
- $result = $api->getGoodsInfo($ids);
- $list = current($result);
- if(!empty($list)){
- $getIds = array_column($list, 'id');
- $pull_ids = array_diff($ids, $getIds);
- }else{
- $pull_ids = $ids;
- }
- if(!empty($list)){
- foreach ($list as $detail) {
- if(!empty($detail)){ // 商品存在
- if ($detail['is_display'] == 0) { // 商品存在且下架
- $pull_ids[] = $detail['id'];
- }
- }
- }
- }
- if($pull_ids){
- var_dump($pull_ids);
- return;
- // 商城商品下架
- StorageService::mallGoodsPull($pull_ids);
- // 执行商品下架
- GoodsModel::GoodsPullByMiddleIds($pull_ids);
- }
- }
- public function actionFf()
- {
- $batchSize = 100; // 每次处理100条
- $executionsPerMinute = 10; // 每分钟执行10次
- $totalMinutes = 10; // 总运行时间(分钟),按需调整
- // 获取所有商城
- $supplysList = SupplysModel::find()->where(['mall_id' => 26])->asArray()->all();
- // 外层循环:控制总运行时间(分钟)
- for ($minute = 0; $minute < $totalMinutes; $minute++) {
- $minuteStartTime = time();
- // 内层循环:每分钟执行10次
- for ($execution = 0; $execution < $executionsPerMinute; $execution++) {
- $executionStartTime = microtime(true);
- // 遍历每个商城
- foreach ($supplysList as $mall) {
- // 计算当前分页偏移量
- $offset = ($minute * $executionsPerMinute + $execution) * $batchSize;
- // 查询当前批次的100条数据
- $data = StorageModel::find()->where(['mall_id' => $mall['mall_id']])->orderBy('id ASC')->offset($offset)->limit($batchSize)->asArray()->all();
- if (empty($data)) {
- continue; // 该商城无更多数据
- }
- // 处理当前批次(保持你的原有逻辑)
- $this->processBatch($mall, $data);
- }
- // 确保每次执行间隔6秒(控制每分钟10次)
- $executionTime = microtime(true) - $executionStartTime;
- $sleepTime = max(0, 6 - $executionTime);
- usleep($sleepTime * 1000000); // 微秒级等待
- }
- // 确保每分钟刚好60秒
- $elapsed = time() - $minuteStartTime;
- if ($elapsed < 60) {
- sleep(60 - $elapsed);
- }
- }
- }
- private function processBatch($mall, $data)
- {
- $ids = array_column($data, 'middle_goods_id');
- // id转Int
- $ids = array_map(function ($v) {
- return (int) $v;
- }, $ids);
- $api = ApiService::getConnect($mall['mall_id'], $mall['id']);
- // 调用API获取商品详情
- $result = $api->getGoodsInfo($ids);
- if(!empty($result)){
- $list = current($result);
- if(!empty($list)){
- $getIds = array_column($list, 'id');
- $pull_ids = array_diff($ids, $getIds);
- }
- }else{
- $pull_ids = $ids;
- }
- if (!empty($list)) {
- foreach ($list as $detail) {
- if(!empty($detail)){ // 商品存在
- if ($detail['is_display'] == 0) { // 商品存在且下架
- $pull_ids[] = $detail['id'];
- }
- }
- }
- }
- if($pull_ids){
- var_dump($pull_ids);
- return;
- // 商城商品下架
- StorageService::mallGoodsPull($pull_ids);
- // 执行商品下架
- GoodsModel::GoodsPullByMiddleIds($pull_ids);
- }
- }
- public function actionDd(){
- $order_sn = Order::find()->where(['mall_id' => 16])->andWhere(['status' => 1])->andWhere(['order_status' => 1])->asArray()->all();
- foreach($order_sn as $v){
- var_dump($v['order_no']);
- $params = [
- "data" => [
- "message_code" => 0,
- "order_sn" => $v['order_no'],
- "message_type" => "order.delivery",
- "member_sign" => "6ead81e2e999b24fcb6faf47e6cf2273",
- "message_id" => "selfb3JkZXJzMjAyNTAzMzEwODI5MjkxMDgzNzhvcmRlci5kZWxpdmVyeTE3NDM0MTczMzE="
- ],
- "method" => "order_delivery",
- "supplys_id" => "11"
- ];
- \addons\QiJuhe\common\service\NoticeHandleService::handle($params);
- }
- }
- public function actionBb(){
- $params = [
- "data" => [
- "message_code" => 0,
- "order_sn" => "s20250329212945270941",
- "message_type" => "order.delivery",
- "member_sign" => "6ead81e2e999b24fcb6faf47e6cf2273",
- "message_id" => "selfb3JkZXJzMjAyNTAzMzEwODI5MjkxMDgzNzhvcmRlci5kZWxpdmVyeTE3NDM0MTczMzE="
- ],
- "method" => "order_delivery",
- "supplys_id" => "11"
- ];
- \addons\QiJuhe\common\service\NoticeHandleService::handle($params);
- }
- public function actionAgentCommission()
- {
- $json = '{"data":{"id":843,"mch_id":0,"mall_id":5,"user_id":3,"order_no":"s202111171513073911817606","out_trade_no":"","mobile":"17781115894","province":2,"city":3,"area":4,"address":"ssaasdsai","region_name":"北京市 北京市 东城区 东四街道","zip":"","receiver_name":"bing","remark":"","seller_remark":"","shipping_type":1,"shipping_money":"0.00","refund_money":"0.00","pay_money":"1200.00","goods_price":"1200.00","original_goods_price":"1200.00","ip":"","coupon_id":0,"coupon_money":"0.00","score":0,"score_money":"0.00","order_status":1,"pay_status":1,"shipping_status":0,"review_status":0,"is_feedback":0,"payment_type":5,"marketing_id":0,"marketing_type":"0","invoice_id":null,"status":1,"is_comment":0,"is_recycle":0,"is_virtual":0,"is_new_user":0,"pay_time":1637133317,"shipping_time":0,"sign_time":0,"consign_time":0,"finish_time":0,"close_time":0,"created_at":1637133187,"updated_at":1637133317,"operator_id":"","operator_name":""}}';
- $data = json_decode($json, true);
- $listener = new OrderPayRewardListener();
- $listener->handleSync($data['data']);
- }
- public function actionIndex()
- {
- $event = new OrderPaidEvent(1);
- $order['id'] = 1964;
- \Yii::$app->services->events->dispatch($event, $order, $event->listeners);
- }
- public function actionFixOrderUnread(){
- ini_set ("memory_limit","-1");
- $mall_list = Mall::getEnableMallList(true);
- foreach ($mall_list as $mall) {
- $where = ['mall_id' => $mall['id']];
- foreach (User::find()->where($where)->each(500) as $user_info){
- OrderUnreadMsg::updateData($user_info['mall_id'],$user_info['id']);
- }
- }
- echo 'success';
- }
- public function actionG(){
- $mall_id = 1;
- $user_list = User::lists([
- 'where' => [['mall_id' => $mall_id], ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]],
- 'select' => 'id'
- ]);
- foreach($user_list as $user){
- $res = UserInviteCode::setData([
- 'mall_id' => $mall_id,
- 'user_id' => $user['id'],
- ]);
- if($res === false){
- \Yii::error('err://id:'.$user['id'].'//msg:'.UserInviteCode::getStaticError());
- }
- }
- }
- public function actionQ()
- {
- $order = Order::getOne([['id' => 12016]], true, ['detail']);
- // 触发条件升级
- $cond_upgrade = new ConditionUpgrade();
- $cond_upgrade->execute(ServicePointAppointmentEnums::ADDONS_NAME, (new ServicePointUser()), (new ServicePointLevel()), $order);
- }
- public function actionLinggong()
- {
- $data = [
- 'mall_id' => '959',
- 'id' => 1550,
- 'settlementInfoId' => '557bde439951b7e035d93010042bfbef',
- ];
- $res = (new \addons\Linggong\common\service\WithdrawService())->handlePay($data);
- print_r($res);exit;
- }
- public function actionTest()
- {
- $data = [
- 'id' => 71884,
- ];
- $res = (new \common\listeners\user\UserUpgradeListener())->handleSync($data);
- print_r($res);exit;
- }
- }
|