LiveCallbackForm.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\models\live;
  8. use app\models\ErpInventory;
  9. use app\models\ErpInventoryProp;
  10. use app\models\ErpInventoryPropLog;
  11. use app\models\ErpInventoryLog;
  12. use app\models\ErpPurchaseinOrder;
  13. use app\models\ErpPurchasein;
  14. use app\models\ErpPurchaseoutOrder;
  15. use app\models\ErpPurchaseout;
  16. use app\models\ErpSupplier;
  17. use app\models\Goods;
  18. use app\models\GoodsCat;
  19. use app\models\Cat;
  20. use app\models\Option;
  21. use app\constants\OptionSetting;
  22. use app\models\Order;
  23. use app\models\OrderDetail;
  24. use app\models\User;
  25. use app\models\SaasUser;
  26. use app\models\Warehouse;
  27. use app\models\WarehouseZone;
  28. use app\models\LiveConfig;
  29. use app\models\LiveAnchor;
  30. use app\models\LiveCat;
  31. use app\models\LiveRoom;
  32. use app\models\LiveComment;
  33. use app\models\LiveFollow;
  34. use app\models\LiveGoods;
  35. class LiveCallbackForm extends LiveForm {
  36. public static function callback($data) {
  37. $command = $data['action'];
  38. debug_log([__FUNCTION__, __LINE__, $command, $data], __CLASS__ . '.log');
  39. $command = 'cb_' . $command;
  40. if($data['data']){
  41. $data = json_decode($data['data'], true);
  42. }
  43. $res = call_user_func_array([new self(), $command], [$data]);
  44. if($res['code'] === 0){
  45. $res['code'] = 200;
  46. }
  47. debug_log([__FUNCTION__, __LINE__, $command, $res], __CLASS__ . '.log');
  48. return $res;
  49. }
  50. public function cb_publish($data) {
  51. $decode = self::decodePath($data['appname'], $data['id']);
  52. $this->anchorSaveKey($decode['anchor_id'], 'is_push', 1);
  53. $this->roomSaveKey($decode['room_id'], 'on_time', new \yii\db\Expression('IF(on_time <= 0, '. (time() - 2) .', on_time)'));
  54. $this->roomSaveKey($decode['room_id'], 'off_time', 0);
  55. $this->roomSaveKey($decode['room_id'], 'pre_play_time', 0);
  56. return [
  57. 'code' => 0,
  58. ];
  59. }
  60. public function cb_publish_done($data) {
  61. $decode = self::decodePath($data['appname'], $data['id']);
  62. $this->anchorSaveKey($decode['anchor_id'], 'is_push', 0);
  63. $this->roomSaveKey($decode['room_id'], 'off_time', time());
  64. self::roomTimeoutClose($decode['room_id']);
  65. return [
  66. 'code' => 0,
  67. ];
  68. }
  69. public static function record() {
  70. $data = file_get_contents("php://input");
  71. $data = json_decode($data, true);
  72. $uri = $data['uri'];
  73. if (empty($uri)) {
  74. return false;
  75. }
  76. $decode = self::decodePath($data['app'], $data['stream']);
  77. self::roomRecordAdd($decode['room_id'], $uri);
  78. return [
  79. 'code' => 0,
  80. ];
  81. }
  82. }