ScoreLogLogic.php 2.3 KB

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