AutoTestController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <?php
  2. namespace console\controllers;
  3. use addons\Achievement\common\listeners\order\OrderPayRewardListener as OrderOrderPayRewardListener;
  4. use addons\Achievement\common\models\AchievementGrantLog;
  5. use addons\Agent\common\listeners\order\OrderPayRewardListener;
  6. use addons\ServicePointAppointment\common\enums\ServicePointAppointmentEnums;
  7. use addons\ServicePointAppointment\common\logic\ConditionUpgrade;
  8. use addons\ServicePointAppointment\common\models\ServicePointLevel;
  9. use addons\ServicePointAppointment\common\models\ServicePointUser;
  10. use common\components\BaseEvent;
  11. use common\enums\StatusEnum;
  12. use common\models\mall\Mall;
  13. use common\models\order\OrderUnreadMsg;
  14. use common\models\user\User;
  15. use yii\console\Controller;
  16. use common\events\order\OrderPaidEvent;
  17. use common\events\order\OrderCreateEvent;
  18. use common\events\order\OrderTakeDeliveryEvent;
  19. use common\events\order\OrderFinishEvent;
  20. use common\models\order\Order;
  21. use common\models\user\UserInviteCode;
  22. use addons\CardCoupons\common\sms\SmsBase;
  23. use addons\CloudStock\common\models\CloudStockAgent;
  24. use addons\CardCoupons\common\listeners\order\OrderFinishRewardListener;
  25. use common\helpers\DateHelper;
  26. class AutoTestController extends Controller
  27. {
  28. public function actionEe(){
  29. $event = new OrderPaidEvent(5);
  30. $order['id'] = 1;
  31. $order['operator_id'] = $params['operator_id'] ?? 0;
  32. $order['operator_name'] = $params['operator_name'] ?? '';
  33. $order['is_admin'] = (int)!empty($params['is_admin']);
  34. \Yii::$app->services->events->dispatch($event, $order, $event->listeners);
  35. exit;
  36. $data = [];
  37. (new \addons\AgentBase\common\listeners\order\OrderPayRewardListener())->handleSync($data);
  38. // $ids = [798155,797417,784601,756116,580755];
  39. $ids = [380140,380141,380142,380143,380144];
  40. $mall_id = 26;
  41. $supply_id = 20;
  42. $api = ApiService::getConnect($mall_id, $supply_id);
  43. // id转Int
  44. $ids = array_map(function ($v) {
  45. return (int) $v;
  46. }, $ids);
  47. // 商品详情
  48. $result = $api->getGoodsInfo($ids);
  49. $list = current($result);
  50. if(!empty($list)){
  51. $getIds = array_column($list, 'id');
  52. $pull_ids = array_diff($ids, $getIds);
  53. }else{
  54. $pull_ids = $ids;
  55. }
  56. if(!empty($list)){
  57. foreach ($list as $detail) {
  58. if(!empty($detail)){ // 商品存在
  59. if ($detail['is_display'] == 0) { // 商品存在且下架
  60. $pull_ids[] = $detail['id'];
  61. }
  62. }
  63. }
  64. }
  65. if($pull_ids){
  66. var_dump($pull_ids);
  67. return;
  68. // 商城商品下架
  69. StorageService::mallGoodsPull($pull_ids);
  70. // 执行商品下架
  71. GoodsModel::GoodsPullByMiddleIds($pull_ids);
  72. }
  73. }
  74. public function actionFf()
  75. {
  76. $batchSize = 100; // 每次处理100条
  77. $executionsPerMinute = 10; // 每分钟执行10次
  78. $totalMinutes = 10; // 总运行时间(分钟),按需调整
  79. // 获取所有商城
  80. $supplysList = SupplysModel::find()->where(['mall_id' => 26])->asArray()->all();
  81. // 外层循环:控制总运行时间(分钟)
  82. for ($minute = 0; $minute < $totalMinutes; $minute++) {
  83. $minuteStartTime = time();
  84. // 内层循环:每分钟执行10次
  85. for ($execution = 0; $execution < $executionsPerMinute; $execution++) {
  86. $executionStartTime = microtime(true);
  87. // 遍历每个商城
  88. foreach ($supplysList as $mall) {
  89. // 计算当前分页偏移量
  90. $offset = ($minute * $executionsPerMinute + $execution) * $batchSize;
  91. // 查询当前批次的100条数据
  92. $data = StorageModel::find()->where(['mall_id' => $mall['mall_id']])->orderBy('id ASC')->offset($offset)->limit($batchSize)->asArray()->all();
  93. if (empty($data)) {
  94. continue; // 该商城无更多数据
  95. }
  96. // 处理当前批次(保持你的原有逻辑)
  97. $this->processBatch($mall, $data);
  98. }
  99. // 确保每次执行间隔6秒(控制每分钟10次)
  100. $executionTime = microtime(true) - $executionStartTime;
  101. $sleepTime = max(0, 6 - $executionTime);
  102. usleep($sleepTime * 1000000); // 微秒级等待
  103. }
  104. // 确保每分钟刚好60秒
  105. $elapsed = time() - $minuteStartTime;
  106. if ($elapsed < 60) {
  107. sleep(60 - $elapsed);
  108. }
  109. }
  110. }
  111. private function processBatch($mall, $data)
  112. {
  113. $ids = array_column($data, 'middle_goods_id');
  114. // id转Int
  115. $ids = array_map(function ($v) {
  116. return (int) $v;
  117. }, $ids);
  118. $api = ApiService::getConnect($mall['mall_id'], $mall['id']);
  119. // 调用API获取商品详情
  120. $result = $api->getGoodsInfo($ids);
  121. if(!empty($result)){
  122. $list = current($result);
  123. if(!empty($list)){
  124. $getIds = array_column($list, 'id');
  125. $pull_ids = array_diff($ids, $getIds);
  126. }
  127. }else{
  128. $pull_ids = $ids;
  129. }
  130. if (!empty($list)) {
  131. foreach ($list as $detail) {
  132. if(!empty($detail)){ // 商品存在
  133. if ($detail['is_display'] == 0) { // 商品存在且下架
  134. $pull_ids[] = $detail['id'];
  135. }
  136. }
  137. }
  138. }
  139. if($pull_ids){
  140. var_dump($pull_ids);
  141. return;
  142. // 商城商品下架
  143. StorageService::mallGoodsPull($pull_ids);
  144. // 执行商品下架
  145. GoodsModel::GoodsPullByMiddleIds($pull_ids);
  146. }
  147. }
  148. public function actionDd(){
  149. $order_sn = Order::find()->where(['mall_id' => 16])->andWhere(['status' => 1])->andWhere(['order_status' => 1])->asArray()->all();
  150. foreach($order_sn as $v){
  151. var_dump($v['order_no']);
  152. $params = [
  153. "data" => [
  154. "message_code" => 0,
  155. "order_sn" => $v['order_no'],
  156. "message_type" => "order.delivery",
  157. "member_sign" => "6ead81e2e999b24fcb6faf47e6cf2273",
  158. "message_id" => "selfb3JkZXJzMjAyNTAzMzEwODI5MjkxMDgzNzhvcmRlci5kZWxpdmVyeTE3NDM0MTczMzE="
  159. ],
  160. "method" => "order_delivery",
  161. "supplys_id" => "11"
  162. ];
  163. \addons\QiJuhe\common\service\NoticeHandleService::handle($params);
  164. }
  165. }
  166. public function actionBb(){
  167. $params = [
  168. "data" => [
  169. "message_code" => 0,
  170. "order_sn" => "s20250329212945270941",
  171. "message_type" => "order.delivery",
  172. "member_sign" => "6ead81e2e999b24fcb6faf47e6cf2273",
  173. "message_id" => "selfb3JkZXJzMjAyNTAzMzEwODI5MjkxMDgzNzhvcmRlci5kZWxpdmVyeTE3NDM0MTczMzE="
  174. ],
  175. "method" => "order_delivery",
  176. "supplys_id" => "11"
  177. ];
  178. \addons\QiJuhe\common\service\NoticeHandleService::handle($params);
  179. }
  180. public function actionAgentCommission()
  181. {
  182. $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":""}}';
  183. $data = json_decode($json, true);
  184. $listener = new OrderPayRewardListener();
  185. $listener->handleSync($data['data']);
  186. }
  187. public function actionIndex()
  188. {
  189. $event = new OrderPaidEvent(1);
  190. $order['id'] = 1964;
  191. \Yii::$app->services->events->dispatch($event, $order, $event->listeners);
  192. }
  193. public function actionFixOrderUnread(){
  194. ini_set ("memory_limit","-1");
  195. $mall_list = Mall::getEnableMallList(true);
  196. foreach ($mall_list as $mall) {
  197. $where = ['mall_id' => $mall['id']];
  198. foreach (User::find()->where($where)->each(500) as $user_info){
  199. OrderUnreadMsg::updateData($user_info['mall_id'],$user_info['id']);
  200. }
  201. }
  202. echo 'success';
  203. }
  204. public function actionG(){
  205. $mall_id = 1;
  206. $user_list = User::lists([
  207. 'where' => [['mall_id' => $mall_id], ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]],
  208. 'select' => 'id'
  209. ]);
  210. foreach($user_list as $user){
  211. $res = UserInviteCode::setData([
  212. 'mall_id' => $mall_id,
  213. 'user_id' => $user['id'],
  214. ]);
  215. if($res === false){
  216. \Yii::error('err://id:'.$user['id'].'//msg:'.UserInviteCode::getStaticError());
  217. }
  218. }
  219. }
  220. public function actionQ()
  221. {
  222. $order = Order::getOne([['id' => 12016]], true, ['detail']);
  223. // 触发条件升级
  224. $cond_upgrade = new ConditionUpgrade();
  225. $cond_upgrade->execute(ServicePointAppointmentEnums::ADDONS_NAME, (new ServicePointUser()), (new ServicePointLevel()), $order);
  226. }
  227. public function actionLinggong()
  228. {
  229. $data = [
  230. 'mall_id' => '959',
  231. 'id' => 1550,
  232. 'settlementInfoId' => '557bde439951b7e035d93010042bfbef',
  233. ];
  234. $res = (new \addons\Linggong\common\service\WithdrawService())->handlePay($data);
  235. print_r($res);exit;
  236. }
  237. public function actionTest()
  238. {
  239. $data = [
  240. 'id' => 71884,
  241. ];
  242. $res = (new \common\listeners\user\UserUpgradeListener())->handleSync($data);
  243. print_r($res);exit;
  244. }
  245. }