| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- /**
- * 渠道包服务层.
- *
- * @author nj
- * @date 2021-05-26 16:26
- */
- namespace Modules\InnerApi\Services;
- use Hashids\Hashids;
- use Modules\Admin\Models\ChannelPackageModel;
- class ChannelPackageService
- {
- /**
- * 更新渠道包的下载链接(Todo mock).
- * @param $items
- * @return array
- */
- public function updateUrls($items)
- {
- $result = [
- 'total' => 0,
- 'success_ids' => [],
- 'fail_ids' => [],
- ];
- if (!empty($items)) {
- foreach ($items as $item) {
- //打包失败情况
- $model = new ChannelPackageModel();
- $channelConfigurationModel = $model::all()
- ->where('is_private_update', '=', $item['is_private_update'])
- ->where('channel_uid', '=', $item['channel_id'])
- ->where('user_uid', '=', $item['user_id'])
- ->where('app_version', '=', $item['app_version'])
- ->first();
- if ($channelConfigurationModel) {
- //失败情况
- if ($item['code'] !== 200) {
- $data['path'] = " ";
- $data['status'] = 2;
- $res = $channelConfigurationModel->update($data);
- if ($res) {
- $result['success_ids']++;
- } else {
- $result['fail_ids']++;
- }
- return $result;
- }
- //存在在覆盖更新包
- $data = [];
- if ($item['mom_platform'] === 'I') {
- //'I'为苹果包
- $data['type'] = 2;
- } else {
- //'A'为安卓包
- $data['type'] = 1;
- }
- $data['path'] = $item['channel_apk_url'];
- $data ['status'] = 1;
- $res = $channelConfigurationModel->update($data);
- if ($res) {
- $result['success_ids']++;
- } else {
- $result['fail_ids']++;
- }
- }
- }
- }
- return $result;
- }
- /**
- * 根据渠道一键打包,渠道分私有控制版本和使用全局母包版本2种情况(Todo mock).
- * Note: 这个方法是给代理系统后台调用的服务方法.
- * @param $channelUid
- * @return array|false
- */
- public function packByChannelId($channelUid)
- {
- $res = [];
- $channelModel = new \stdClass();
- $channelColumns = [
- 'id',
- 'user_uid',
- 'name',
- 'uid',
- 'mom_app_uid',
- 'is_private_update'
- ];
- $channelObj = $channelModel->where(
- 'uid',
- $channelUid
- )->first($channelColumns);
- if (empty($channelObj)) {
- return false;
- }
- $momAppUid = $channelObj->mom_app_uid; // 母包应用唯一自定义ID,非自增ID.
- $momModel = new \stdClass();
- $momColumns = ['id', 'uid', 'name'];
- $momObj = $momModel->where(
- 'uid',
- $channelObj->mom_app_uid
- )->first($momColumns);
- if (empty($momObj)) {
- return false;
- }
- $recentLimit = 10; // 取最近的n个.
- $versionColumns = [
- 'id',
- 'app_uid',
- 'platform',
- 'version',
- 'apk_url',
- 'ipk_url',
- 'icon_url',
- 'office_url'
- ];
- if (boolval($channelObj->is_private_update) === true) {
- $channelPrivateModel = new \stdClass();
- $items = $channelPrivateModel->where(
- 'channel_uid',
- $channelUid
- )->orderBy(
- 'version',
- 'DESC'
- )->take($recentLimit)->get($versionColumns);
- if (!empty($items)) {
- foreach ($items as $item) {
- $res[] = [
- 'id' => $item->id,
- 'is_private_update' => 1,
- 'user_uid' => $channelObj->uid,
- 'mom_app_uid' => $channelObj->mom_app_uid,
- 'mom_app_name' => $momObj->name,
- 'channel_id' => $channelUid,
- 'channel_name' => $channelObj->name,
- 'mom_platform' => $item->platform,
- 'mom_app_version' => $item->version,
- 'mom_apk_url' => $item->apk_url,
- 'mom_ipa_url' => $item->ipa_url,
- 'app_icon_url' => $item->icon_url,
- ];
- }
- }
- } else {
- $momAppVersionModel = new \stdClass();
- $items = $momAppVersionModel->where(
- 'app_uid',
- $momAppUid
- )->orderBy(
- 'version',
- 'DESC'
- )->take($recentLimit)->get($versionColumns);
- if (!empty($items)) {
- foreach ($items as $item) {
- $res[] = [
- 'id' => $item->id,
- 'is_private_update' => 0,
- 'user_uid' => $channelObj->uid,
- 'mom_app_uid' => $channelObj->mom_app_uid,
- 'mom_app_name' => $momObj->name,
- 'channel_id' => $channelUid,
- 'channel_name' => $channelObj->name,
- 'mom_platform' => $item->platform,
- 'mom_app_version' => $item->version,
- 'mom_apk_url' => $item->apk_url,
- 'mom_ipa_url' => $item->ipa_url,
- 'app_icon_url' => $item->icon_url,
- ];
- }
- }
- }
- return $res;
- }
- }
|