DefaultService.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace addons\Scratch\api\modules\v1\services;
  3. use addons\Scratch\common\enums\ScratchEnum;
  4. use addons\Scratch\common\models\ScratchCommissionLog;
  5. use addons\Scratch\common\models\ScratchLevelModel;
  6. use addons\Scratch\common\models\ScratchModel;
  7. use addons\Scratch\common\models\ScratchUserPartitionRelationshipModel;
  8. use common\components\Service;
  9. use common\enums\StatusEnum;
  10. use common\models\common\CapitalLog;
  11. use common\models\order\OrderDetail;
  12. /**
  13. * Class DefaultService
  14. * @package addons\Scratch\api\modules\v1\services
  15. */
  16. class DefaultService extends Service
  17. {
  18. /**
  19. * @param $mallId
  20. * @param $userData
  21. * @return mixed
  22. * @throws \ErrorException
  23. */
  24. public static function getInfo($mallId, $userData)
  25. {
  26. try {
  27. $Scratch = ScratchModel::getData($mallId, $userData->id);
  28. if (empty($Scratch)) {
  29. throw new \ErrorException('ccc');
  30. }
  31. $data = [
  32. 'id' => $userData->id ?? '',//会员id
  33. 'nickname' => $userData->nickname ?? '',//会员昵称
  34. 'mobile' => $userData->mobile ?? '',//手机号
  35. 'avatar_url' => $userData->avatar_url ?? '',//头像
  36. ];
  37. return $data;
  38. } catch (\ErrorException $errorException) {
  39. throw new \ErrorException($errorException->getMessage());
  40. } catch (\Exception $exception) {
  41. throw new \Exception($exception->getMessage());
  42. }
  43. }
  44. /**
  45. * @param $mallId
  46. * @param $userData
  47. * @param string $fromType
  48. * @param string $capitalType
  49. * @param int $page
  50. * @param int $limit
  51. * @param string[] $order
  52. * @return mixed
  53. * @throws \ErrorException
  54. */
  55. public static function getLogList($mallId, $userData, $fromType = [], $capitalType = '', $page = 1, $limit = 10, $order = 'id desc')
  56. {
  57. try {
  58. $params = [
  59. 'page' => $page,
  60. 'limit' => $limit,
  61. 'order' => $order,
  62. 'select' => 'id,change_num,source_table,source_table_id,from_type,capital_type,log_type',
  63. 'where' => [
  64. ['=', 'mall_id', $mallId],
  65. ['=', 'user_id', $userData->id],
  66. ['in', 'from_type', $fromType],
  67. ],
  68. ];
  69. if (!empty($capitalType)) {
  70. $params['where'][] = ['=', 'capital_type', ScratchEnum::getApiCapitalType($capitalType)];
  71. }
  72. $list = ScratchCommissionLog::listPage($params);
  73. return $list;
  74. } catch (\ErrorException $errorException) {
  75. throw new \ErrorException($errorException->getMessage());
  76. } catch (\Exception $exception) {
  77. throw new \Exception($exception->getMessage());
  78. }
  79. }
  80. }