AuditManagementService.php 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <?php
  2. namespace App\Http\Services\Backend\DataManagement;
  3. use App\Http\Services\ConstDef\GeneralConst;
  4. use App\Models\Web\Round;
  5. use App\Models\Web\GameGpRatio;
  6. use App\Models\Web\CheckinGpAlloc;
  7. use App\Models\Web\Good;
  8. use App\Models\Web\Syslog;
  9. class AuditManagementService
  10. {
  11. // 相關私有 model 調用器宣告
  12. private $roundManagementDb;
  13. private $gameManagementDb;
  14. private $checkinManagementDb;
  15. private $goodManagementDb;
  16. private $syslogManagementDb;
  17. public function __construct()
  18. {
  19. date_default_timezone_set("Asia/Taipei");
  20. // 建構 model 調用器
  21. $this->roundManagementDb = new Round();
  22. $this->gameManagementDb = new GameGpRatio();
  23. $this->checkinManagementDb = new CheckinGpAlloc();
  24. $this->goodManagementDb = new Good();
  25. $this->syslogManagementDb = new Syslog();
  26. }
  27. public function getRounds(
  28. &$cnt = 0,
  29. $orderColumn,
  30. $orderDir,
  31. $start,
  32. $length,
  33. $searchValue
  34. )
  35. {
  36. // 選欄位
  37. $activeStr = '';
  38. foreach (GeneralConst::$activeMap as $k => $v) {
  39. $activeStr .= ' when \'' . $k . '\' then \'' . $v . '\'';
  40. }
  41. $rounds = $this->roundManagementDb
  42. ->select([
  43. \DB::raw("(case when dateFinal_tmp=dateFinal and dateFinal_tmp=dateFinal and redeemExtra_tmp=redeemExtra then '' else CONCAT('<a href=\"auditManagement/round/', id, '\">通過</a>') end) as BtnAudit"),
  44. 'id',
  45. 'roundName',
  46. \DB::raw("CONCAT(IFNULL(dateBegin_tmp, ''), '<hr>', IFNULL(dateBegin, '')) as dateBegin"),
  47. \DB::raw("CONCAT(IFNULL(dateFinal_tmp, ''), '<hr>', IFNULL(dateFinal, '')) as dateFinal"),
  48. \DB::raw("CONCAT(IFNULL(redeemExtra_tmp, ''), '<hr>', IFNULL(redeemExtra, '')) as redeemExtra"),
  49. \DB::raw("(case active $activeStr end) as active"),
  50. 'cdate',
  51. 'mdate',
  52. \DB::raw("(select name from users where id=rounds.oid) as oid"),
  53. ]);
  54. // 過濾搜尋條件
  55. // 取總筆數
  56. $cnt = $rounds->count();
  57. // 排序
  58. $rounds = $rounds
  59. ->orderByRaw((int)$orderColumn . ' ' . $orderDir);
  60. // 彙整
  61. // 分頁
  62. $rounds = $rounds
  63. ->skip($start)->take($length);
  64. // 實際取資料
  65. $rounds = $rounds
  66. ->get()
  67. ->toArray();
  68. // 整理返回值並返回
  69. return $rounds;
  70. }
  71. public function getGames(
  72. &$cnt = 0,
  73. $orderColumn,
  74. $orderDir,
  75. $start,
  76. $length,
  77. $searchValue
  78. )
  79. {
  80. $games = $this->gameManagementDb
  81. ->select([
  82. \DB::raw("(case when ratio_tmp=ratio and gp_tmp=gp then '' else CONCAT('<a href=\"auditManagement/game/', id, '\">通過</a>') end) as BtnAudit"),
  83. 'id',
  84. \DB::raw("CONCAT(IFNULL(ratio_tmp, ''), '<hr>', IFNULL(ratio, '')) as ratio"),
  85. \DB::raw("CONCAT(IFNULL(gp_tmp, ''), '<hr>', IFNULL(gp, '')) as gp"),
  86. 'cdate',
  87. 'mdate',
  88. \DB::raw("(select name from users where id=gameGpRatio.oid) as oid"),
  89. ]);
  90. // 過濾搜尋條件
  91. // 取總筆數
  92. $cnt = $games->count();
  93. // 排序
  94. $games = $games
  95. ->orderByRaw((int)$orderColumn . ' ' . $orderDir);
  96. // 彙整
  97. // 分頁
  98. $games = $games
  99. ->skip($start)->take($length);
  100. // 實際取資料
  101. $games = $games
  102. ->get()
  103. ->toArray();
  104. // 整理返回值並返回
  105. return $games;
  106. }
  107. public function getCheckins(
  108. &$cnt = 0,
  109. $orderColumn,
  110. $orderDir,
  111. $start,
  112. $length,
  113. $searchValue
  114. )
  115. {
  116. $checkins = $this->checkinManagementDb
  117. ->select([
  118. \DB::raw("(case when day_tmp=day and gp_tmp=gp then '' else CONCAT('<a href=\"auditManagement/checkin/', id, '\">通過</a>') end) as BtnAudit"),
  119. 'id',
  120. \DB::raw("CONCAT(IFNULL(day_tmp, ''), '<hr>', IFNULL(day, '')) as day"),
  121. \DB::raw("CONCAT(IFNULL(gp_tmp, ''), '<hr>', IFNULL(gp, '')) as gp"),
  122. 'cdate',
  123. 'mdate',
  124. \DB::raw("(select name from users where id=checkinGpAlloc.oid) as oid"),
  125. ]);
  126. // 過濾搜尋條件
  127. // 取總筆數
  128. $cnt = $checkins->count();
  129. // 排序
  130. $checkins = $checkins
  131. ->orderByRaw((int)$orderColumn . ' ' . $orderDir);
  132. // 彙整
  133. // 分頁
  134. $checkins = $checkins
  135. ->skip($start)->take($length);
  136. // 實際取資料
  137. $checkins = $checkins
  138. ->get()
  139. ->toArray();
  140. // 整理返回值並返回
  141. return $checkins;
  142. }
  143. public function getGoods(
  144. &$cnt = 0,
  145. $orderColumn,
  146. $orderDir,
  147. $start,
  148. $length,
  149. $searchValue
  150. )
  151. {
  152. $goods = $this->goodManagementDb
  153. ->select([
  154. \DB::raw("(case when lp_tmp=lp and gp_tmp=gp and active_tmp=active and totalQty_tmp=totalQty then '' else CONCAT('<a href=\"auditManagement/good/', id, '\">通過</a>') end) as BtnAudit"),
  155. 'id',
  156. \DB::raw("CONCAT(IFNULL(lp_tmp, ''), '<hr>', IFNULL(lp, '')) as lp"),
  157. \DB::raw("CONCAT(IFNULL(gp_tmp, ''), '<hr>', IFNULL(gp, '')) as gp"),
  158. \DB::raw("CONCAT(IFNULL(active_tmp, ''), '<hr>', IFNULL(active, '')) as active"),
  159. \DB::raw("CONCAT(IFNULL(totalQty_tmp, ''), '<hr>', IFNULL(totalQty, '')) as totalQty"),
  160. 'issuedQty',
  161. 'cdate',
  162. 'mdate',
  163. \DB::raw("(select name from users where id=goods.oid) as oid"),
  164. ]);
  165. // 過濾搜尋條件
  166. // 取總筆數
  167. $cnt = $goods->count();
  168. // 排序
  169. $goods = $goods
  170. ->orderByRaw((int)$orderColumn . ' ' . $orderDir);
  171. // 彙整
  172. // 分頁
  173. $goods = $goods
  174. ->skip($start)->take($length);
  175. // 實際取資料
  176. $goods = $goods
  177. ->get()
  178. ->toArray();
  179. // 整理返回值並返回
  180. return $goods;
  181. }
  182. public function passRound($id, $oid)
  183. {
  184. // 寫入
  185. $data = [
  186. 'dateBegin' => \DB::raw('dateBegin' . '_tmp'),
  187. 'dateFinal' => \DB::raw('dateFinal' . '_tmp'),
  188. 'redeemExtra' => \DB::raw('redeemExtra' . '_tmp'),
  189. 'mdate' => date('Y-m-d H:i:s'),
  190. 'oid' => $oid,
  191. ];
  192. $res = $this->roundManagementDb->where('id', $id)->update($data);
  193. $rc = \DB::select("SELECT ROW_COUNT() AS rc;");
  194. $rc = $rc[0]->rc;
  195. // syslog
  196. $this->syslogManagementDb
  197. ->insert([
  198. 'type' => GeneralConst::LOG_ADMIN,
  199. 'func' => __FUNCTION__,
  200. 'k' => $oid,
  201. 'memoIn' => json_encode(['id' => $id, 'data' => $data], JSON_UNESCAPED_UNICODE),
  202. 'memoOut' => json_encode(['rc' => $rc], JSON_UNESCAPED_UNICODE),
  203. 'cdate' => date("Y-m-d H:i:s"),
  204. ]);
  205. // 整理返回值並返回
  206. return $res;
  207. }
  208. public function passGame($id, $oid)
  209. {
  210. // 寫入
  211. $data = [
  212. 'ratio' => \DB::raw('ratio' . '_tmp'),
  213. 'gp' => \DB::raw('gp' . '_tmp'),
  214. 'mdate' => date('Y-m-d H:i:s'),
  215. 'oid' => $oid,
  216. ];
  217. $res = $this->gameManagementDb->where('id', $id)->update($data);
  218. $rc = \DB::select("SELECT ROW_COUNT() AS rc;");
  219. $rc = $rc[0]->rc;
  220. // syslog
  221. $this->syslogManagementDb
  222. ->insert([
  223. 'type' => GeneralConst::LOG_ADMIN,
  224. 'func' => __FUNCTION__,
  225. 'k' => $oid,
  226. 'memoIn' => json_encode(['id' => $id, 'data' => $data], JSON_UNESCAPED_UNICODE),
  227. 'memoOut' => json_encode(['rc' => $rc], JSON_UNESCAPED_UNICODE),
  228. 'cdate' => date("Y-m-d H:i:s"),
  229. ]);
  230. // 整理返回值並返回
  231. return $res;
  232. }
  233. public function passCheckin($id, $oid)
  234. {
  235. // 寫入
  236. $data = [
  237. 'day' => \DB::raw('day' . '_tmp'),
  238. 'gp' => \DB::raw('gp' . '_tmp'),
  239. 'mdate' => date('Y-m-d H:i:s'),
  240. 'oid' => $oid,
  241. ];
  242. $res = $this->checkinManagementDb->where('id', $id)->update($data);
  243. $rc = \DB::select("SELECT ROW_COUNT() AS rc;");
  244. $rc = $rc[0]->rc;
  245. // syslog
  246. $this->syslogManagementDb
  247. ->insert([
  248. 'type' => GeneralConst::LOG_ADMIN,
  249. 'func' => __FUNCTION__,
  250. 'k' => $oid,
  251. 'memoIn' => json_encode(['id' => $id, 'data' => $data], JSON_UNESCAPED_UNICODE),
  252. 'memoOut' => json_encode(['rc' => $rc], JSON_UNESCAPED_UNICODE),
  253. 'cdate' => date("Y-m-d H:i:s"),
  254. ]);
  255. // 整理返回值並返回
  256. return $res;
  257. }
  258. public function passGood($id, $oid)
  259. {
  260. // 寫入
  261. $data = [
  262. 'lp' => \DB::raw('lp' . '_tmp'),
  263. 'gp' => \DB::raw('gp' . '_tmp'),
  264. 'active' => \DB::raw('active' . '_tmp'),
  265. 'totalQty' => \DB::raw('totalQty' . '_tmp'),
  266. 'mdate' => date('Y-m-d H:i:s'),
  267. 'oid' => $oid,
  268. ];
  269. $res = $this->goodManagementDb->where('id', $id)->update($data);
  270. $rc = \DB::select("SELECT ROW_COUNT() AS rc;");
  271. $rc = $rc[0]->rc;
  272. // syslog
  273. $this->syslogManagementDb
  274. ->insert([
  275. 'type' => GeneralConst::LOG_ADMIN,
  276. 'func' => __FUNCTION__,
  277. 'k' => $oid,
  278. 'memoIn' => json_encode(['id' => $id, 'data' => $data], JSON_UNESCAPED_UNICODE),
  279. 'memoOut' => json_encode(['rc' => $rc], JSON_UNESCAPED_UNICODE),
  280. 'cdate' => date("Y-m-d H:i:s"),
  281. ]);
  282. // 整理返回值並返回
  283. return $res;
  284. }
  285. }