UserSignScoreDao.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace app\common\dao\user;
  3. use app\common\dao\BaseDao;
  4. use app\common\enum\user\UserSignScoreEnum;
  5. use app\common\model\BaseModel;
  6. use app\common\model\user\UserSignScore;
  7. use app\entity\CommonEntity;
  8. use app\entity\data\user\UserSignScoreEntity;
  9. use think\db\exception\DataNotFoundException;
  10. use think\db\exception\DbException;
  11. use think\db\exception\ModelNotFoundException;
  12. use think\facade\Log;
  13. class UserSignScoreDao extends BaseDao
  14. {
  15. /**
  16. * @return BaseModel
  17. */
  18. protected function getModel(): string
  19. {
  20. return UserSignScore::class;
  21. }
  22. /**
  23. * @param array $idList
  24. * @return CommonEntity[]
  25. */
  26. public function getUserSignScoreEntityListByIdList(array $idList): array
  27. {
  28. $entityList = [];
  29. try {
  30. /** @var UserSignScore $model */
  31. $model = $this->getModel();
  32. $dataRes = $model::getDB()
  33. ->whereIn('id', $idList)
  34. ->select()
  35. ->toArray();
  36. if (!empty($dataRes)) {
  37. $entityList = array_map(function ($data) {
  38. return UserSignScoreEntity::newInstance($data);
  39. }, $dataRes);
  40. }
  41. } catch (\Exception $e) {
  42. }
  43. return $entityList;
  44. }
  45. /**
  46. * @param string $orderType
  47. * @param array $orderIdList
  48. * @return UserSignScoreEntity[]
  49. */
  50. public function getUserSignScoreEntityListByOrderIdListAndPending(string $orderType, array $orderIdList): array
  51. {
  52. $entityList = [];
  53. try {
  54. $dataList = UserSignScore::getDB()
  55. ->where('order_type', '=', $orderType)
  56. ->whereIn('order_id', $orderIdList)
  57. ->where('status', '=', UserSignScoreEnum::STATUS['Pending']['code'])
  58. ->select()
  59. ->toArray();
  60. if (!empty($dataList)) {
  61. $entityList = array_map(function ($data) {
  62. return UserSignScoreEntity::newInstance($data);
  63. }, $dataList);
  64. }
  65. } catch (DataNotFoundException|ModelNotFoundException|DbException $e) {
  66. }
  67. return $entityList;
  68. }
  69. /**
  70. * 批量更新
  71. * @param $dataList
  72. * @return array
  73. */
  74. public function saveAll($dataList): array
  75. {
  76. try {
  77. return $this->getModel()::getInstance()->allowField(array_keys(reset($dataList)))->saveAll($dataList)->toArray();
  78. } catch (\Exception $e) {
  79. return [];
  80. }
  81. }
  82. /**
  83. * 根据order_id与uid查找奖励积分值(status=1, source_type=3, pm=1)
  84. */
  85. public function getRewardScoreFromUidOrderId($orderId, $uid)
  86. {
  87. try {
  88. return $this::getModel()::getDB()
  89. ->where('order_id', '=', $orderId)
  90. ->where('status', '=', 1)
  91. ->where('source_type', '=', 3)
  92. ->where('uid', '=', $uid)
  93. ->where('pm', '=', 1)
  94. ->value('reward_socre');
  95. } catch (\Exception $e) {
  96. return [];
  97. }
  98. }
  99. /**
  100. * 根据order_id与uid查找支付积分值(status=1, pm=2)
  101. */
  102. public function getPayScoreFromUidOrderId($orderId, $uid)
  103. {
  104. try {
  105. return $this::getModel()::getDB()
  106. ->where('order_id', '=', $orderId)
  107. ->where('status', '=', 1)
  108. ->where('uid', '=', $uid)
  109. ->where('pm', '=', 2)
  110. ->value('reward_socre');
  111. } catch (\Exception $e) {
  112. return [];
  113. }
  114. }
  115. /**
  116. * 根据order_id与uid查找奖励积分值(status=1)
  117. */
  118. public function getRewardScoreFromStatusUidOrderId($orderId, $uid)
  119. {
  120. try {
  121. return $this::getModel()::getDB()
  122. ->where('order_id', '=', $orderId)
  123. ->where('uid', '=', $uid)
  124. ->where('status', '=', 1)
  125. ->value('reward_socre');
  126. } catch (\Exception $e) {
  127. return [];
  128. }
  129. }
  130. /**
  131. * 根据order_id查找扫码推荐人uid(mark like '%扫码%', status=1)
  132. */
  133. public function getUidFromMarkLikeStatusOrderId($orderId)
  134. {
  135. try {
  136. return $this::getModel()::getDB()
  137. ->where('order_id', '=', $orderId)
  138. ->whereLike('mark', '%扫码%')
  139. ->where('status', '=', 1)
  140. ->value('uid');
  141. } catch (\Exception $e) {
  142. return [];
  143. }
  144. }
  145. /**
  146. * 根据上面getUidFromMarkLikeStatusOrderId方法查处的Uid来确定score
  147. */
  148. public function getScoreFromUidOrderId($orderId, $smSpreadUid)
  149. {
  150. try {
  151. return $this::getModel()::getDB()
  152. ->where('order_id', '=', $orderId)
  153. ->where('uid', '=', $smSpreadUid)
  154. ->where('status', '=', 1)
  155. ->value('reward_socre');
  156. } catch (\Exception $e) {
  157. return [];
  158. }
  159. }
  160. }