ChannelPackageService.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /**
  3. * 渠道包服务层.
  4. *
  5. * @author nj
  6. * @date 2021-05-26 16:26
  7. */
  8. namespace Modules\InnerApi\Services;
  9. use Hashids\Hashids;
  10. use Modules\Admin\Models\ChannelPackageModel;
  11. class ChannelPackageService
  12. {
  13. /**
  14. * 更新渠道包的下载链接(Todo mock).
  15. * @param $items
  16. * @return array
  17. */
  18. public function updateUrls($items)
  19. {
  20. $result = [
  21. 'total' => 0,
  22. 'success_ids' => [],
  23. 'fail_ids' => [],
  24. ];
  25. if (!empty($items)) {
  26. foreach ($items as $item) {
  27. //打包失败情况
  28. $model = new ChannelPackageModel();
  29. $channelConfigurationModel = $model::all()
  30. ->where('is_private_update', '=', $item['is_private_update'])
  31. ->where('channel_uid', '=', $item['channel_id'])
  32. ->where('user_uid', '=', $item['user_id'])
  33. ->where('app_version', '=', $item['app_version'])
  34. ->first();
  35. if ($channelConfigurationModel) {
  36. //失败情况
  37. if ($item['code'] !== 200) {
  38. $data['path'] = " ";
  39. $data['status'] = 2;
  40. $res = $channelConfigurationModel->update($data);
  41. if ($res) {
  42. $result['success_ids']++;
  43. } else {
  44. $result['fail_ids']++;
  45. }
  46. return $result;
  47. }
  48. //存在在覆盖更新包
  49. $data = [];
  50. if ($item['mom_platform'] === 'I') {
  51. //'I'为苹果包
  52. $data['type'] = 2;
  53. } else {
  54. //'A'为安卓包
  55. $data['type'] = 1;
  56. }
  57. $data['path'] = $item['channel_apk_url'];
  58. $data ['status'] = 1;
  59. $res = $channelConfigurationModel->update($data);
  60. if ($res) {
  61. $result['success_ids']++;
  62. } else {
  63. $result['fail_ids']++;
  64. }
  65. }
  66. }
  67. }
  68. return $result;
  69. }
  70. /**
  71. * 根据渠道一键打包,渠道分私有控制版本和使用全局母包版本2种情况(Todo mock).
  72. * Note: 这个方法是给代理系统后台调用的服务方法.
  73. * @param $channelUid
  74. * @return array|false
  75. */
  76. public function packByChannelId($channelUid)
  77. {
  78. $res = [];
  79. $channelModel = new \stdClass();
  80. $channelColumns = [
  81. 'id',
  82. 'user_uid',
  83. 'name',
  84. 'uid',
  85. 'mom_app_uid',
  86. 'is_private_update'
  87. ];
  88. $channelObj = $channelModel->where(
  89. 'uid',
  90. $channelUid
  91. )->first($channelColumns);
  92. if (empty($channelObj)) {
  93. return false;
  94. }
  95. $momAppUid = $channelObj->mom_app_uid; // 母包应用唯一自定义ID,非自增ID.
  96. $momModel = new \stdClass();
  97. $momColumns = ['id', 'uid', 'name'];
  98. $momObj = $momModel->where(
  99. 'uid',
  100. $channelObj->mom_app_uid
  101. )->first($momColumns);
  102. if (empty($momObj)) {
  103. return false;
  104. }
  105. $recentLimit = 10; // 取最近的n个.
  106. $versionColumns = [
  107. 'id',
  108. 'app_uid',
  109. 'platform',
  110. 'version',
  111. 'apk_url',
  112. 'ipk_url',
  113. 'icon_url',
  114. 'office_url'
  115. ];
  116. if (boolval($channelObj->is_private_update) === true) {
  117. $channelPrivateModel = new \stdClass();
  118. $items = $channelPrivateModel->where(
  119. 'channel_uid',
  120. $channelUid
  121. )->orderBy(
  122. 'version',
  123. 'DESC'
  124. )->take($recentLimit)->get($versionColumns);
  125. if (!empty($items)) {
  126. foreach ($items as $item) {
  127. $res[] = [
  128. 'id' => $item->id,
  129. 'is_private_update' => 1,
  130. 'user_uid' => $channelObj->uid,
  131. 'mom_app_uid' => $channelObj->mom_app_uid,
  132. 'mom_app_name' => $momObj->name,
  133. 'channel_id' => $channelUid,
  134. 'channel_name' => $channelObj->name,
  135. 'mom_platform' => $item->platform,
  136. 'mom_app_version' => $item->version,
  137. 'mom_apk_url' => $item->apk_url,
  138. 'mom_ipa_url' => $item->ipa_url,
  139. 'app_icon_url' => $item->icon_url,
  140. ];
  141. }
  142. }
  143. } else {
  144. $momAppVersionModel = new \stdClass();
  145. $items = $momAppVersionModel->where(
  146. 'app_uid',
  147. $momAppUid
  148. )->orderBy(
  149. 'version',
  150. 'DESC'
  151. )->take($recentLimit)->get($versionColumns);
  152. if (!empty($items)) {
  153. foreach ($items as $item) {
  154. $res[] = [
  155. 'id' => $item->id,
  156. 'is_private_update' => 0,
  157. 'user_uid' => $channelObj->uid,
  158. 'mom_app_uid' => $channelObj->mom_app_uid,
  159. 'mom_app_name' => $momObj->name,
  160. 'channel_id' => $channelUid,
  161. 'channel_name' => $channelObj->name,
  162. 'mom_platform' => $item->platform,
  163. 'mom_app_version' => $item->version,
  164. 'mom_apk_url' => $item->apk_url,
  165. 'mom_ipa_url' => $item->ipa_url,
  166. 'app_icon_url' => $item->icon_url,
  167. ];
  168. }
  169. }
  170. }
  171. return $res;
  172. }
  173. }