GreenScoreLogLogic.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace app\admin\logic;
  3. use app\common\model\GreenScoreLogModel;
  4. use app\common\model\ScoreLogModel;
  5. class GreenScoreLogLogic
  6. {
  7. // 预约福袋 2.预约福袋空盒退回 3.买商品送积分 4.提现多次返回 6.兑换商品, 12-平台充补,13-平台扣除
  8. private static $typeMap = [
  9. ['id' => 12, 'name' => '平台充值'],
  10. ['id' => 13, 'name' => '平台扣除'],
  11. ['id' => 0, 'name' => '其他'],
  12. ];
  13. private static $stateMap = [
  14. ['id' => 1, 'name' => '增加'],
  15. ['id' => 2, 'name' => '减少']
  16. ];
  17. /**
  18. * @return array[]
  19. */
  20. public static function getStateMap(): array
  21. {
  22. return self::$stateMap;
  23. }
  24. /**
  25. * @return array[]
  26. */
  27. public static function getTypeMap(): array
  28. {
  29. return self::$typeMap;
  30. }
  31. /**
  32. * 绿色积分记录
  33. * @param $page
  34. * @param $limit
  35. * @param $where
  36. * @param array $sort
  37. * @return array
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\DbException
  40. * @throws \think\db\exception\ModelNotFoundException
  41. */
  42. public static function scoreLog($page, $limit, $where, $sort)
  43. {
  44. $model = new GreenScoreLogModel();
  45. $count = $model
  46. ->where($where)
  47. ->count();
  48. $type_conf = config('type.green_score');
  49. $list = $model
  50. ->where($where)
  51. ->withAttr('type', function ($value, $data) use ($type_conf) {
  52. if (array_key_exists($value, $type_conf)) {
  53. return $type_conf[$value];
  54. }
  55. return '';
  56. })
  57. ->withAttr('score', function ($value, $data) {
  58. if ($data['state'] == 2)
  59. $value = '-' . $value;
  60. return $value;
  61. })
  62. ->page($page, $limit)
  63. ->order($sort)
  64. ->select();
  65. return [$count, $list];
  66. }
  67. }