ScoreLogLogic.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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' => 1, 'name' => '预约福袋'],
  15. // ['id' => 2, 'name' => '预约福袋空盒退回'],
  16. // ['id' => 3, 'name' => '买商品送积分'],
  17. // ['id' => 4, 'name' => '提现多次返回'],
  18. // ['id' => 6, 'name' => '兑换商品'],
  19. ['id' => 12, 'name' => '平台充值'],
  20. ['id' => 13, 'name' => '平台扣除'],
  21. ['id' => 0, '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 $page
  44. * @param $limit
  45. * @param $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($page, $limit, $where, $sort)
  53. {
  54. $model = new ScoreLogModel();
  55. $count = $model
  56. ->where($where)
  57. ->count();
  58. $type_conf = config('type.scoreAll');
  59. $list = $model
  60. ->where($where)
  61. ->withAttr('type', function ($value, $data) use ($type_conf) {
  62. if (array_key_exists($value, $type_conf)) {
  63. return $type_conf[$value];
  64. }
  65. return '';
  66. })
  67. ->withAttr('score', function ($value, $data) {
  68. if ($data['state'] == 2)
  69. $value = '-' . $value;
  70. return $value;
  71. })
  72. ->page($page, $limit)
  73. ->order($sort)
  74. ->select();
  75. return [$count, $list];
  76. }
  77. }