TAuditManagementService.php 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. namespace App\Http\Services\Backend\DataManagement;
  3. use App\Http\Services\ConstDef\GeneralConst;
  4. use App\Models\Web\TRound;
  5. use App\Models\Web\TCheckinGpAlloc;
  6. use App\Models\Web\TGood;
  7. use App\Models\Web\Syslogt;
  8. class TAuditManagementService
  9. {
  10. // 相關私有 model 調用器宣告
  11. private $troundManagementDb;
  12. private $tcheckinManagementDb;
  13. private $tgoodManagementDb;
  14. private $syslogtManagementDb;
  15. public function __construct()
  16. {
  17. date_default_timezone_set("Asia/Taipei");
  18. // 建構 model 調用器
  19. $this->troundManagementDb = new TRound();
  20. $this->tcheckinManagementDb = new TCheckinGpAlloc();
  21. $this->tgoodManagementDb = new TGood();
  22. $this->syslogtManagementDb = new Syslogt();
  23. }
  24. public function getTRounds(
  25. &$cnt = 0,
  26. $orderColumn,
  27. $orderDir,
  28. $start,
  29. $length,
  30. $searchValue
  31. )
  32. {
  33. // 選欄位
  34. $activeStr = '';
  35. foreach (GeneralConst::$activeMap as $k => $v) {
  36. $activeStr .= ' when \'' . $k . '\' then \'' . $v . '\'';
  37. }
  38. $trounds = $this->troundManagementDb
  39. ->select([
  40. \DB::raw("(case when dateFinal_tmp=dateFinal and dateFinal_tmp=dateFinal and redeemExtra_tmp=redeemExtra then '' else CONCAT('<a href=\"tauditManagement/tround/', id, '\">通過</a>') end) as BtnTAudit"),
  41. 'id',
  42. 'roundName',
  43. \DB::raw("CONCAT(IFNULL(dateBegin_tmp, ''), '<hr>', IFNULL(dateBegin, '')) as dateBegin"),
  44. \DB::raw("CONCAT(IFNULL(dateFinal_tmp, ''), '<hr>', IFNULL(dateFinal, '')) as dateFinal"),
  45. \DB::raw("CONCAT(IFNULL(redeemExtra_tmp, ''), '<hr>', IFNULL(redeemExtra, '')) as redeemExtra"),
  46. \DB::raw("(case active $activeStr end) as active"),
  47. 'cdate',
  48. 'mdate',
  49. \DB::raw("(select name from users where id=trounds.oid) as oid"),
  50. ]);
  51. // 過濾搜尋條件
  52. // 取總筆數
  53. $cnt = $trounds->count();
  54. // 排序
  55. $trounds = $trounds
  56. ->orderByRaw((int)$orderColumn . ' ' . $orderDir);
  57. // 彙整
  58. // 分頁
  59. $trounds = $trounds
  60. ->skip($start)->take($length);
  61. // 實際取資料
  62. $trounds = $trounds
  63. ->get()
  64. ->toArray();
  65. // 整理返回值並返回
  66. return $trounds;
  67. }
  68. public function getTCheckins(
  69. &$cnt = 0,
  70. $orderColumn,
  71. $orderDir,
  72. $start,
  73. $length,
  74. $searchValue
  75. )
  76. {
  77. $tcheckins = $this->tcheckinManagementDb
  78. ->select([
  79. \DB::raw("(case when day_tmp=day and gp_tmp=gp then '' else CONCAT('<a href=\"tauditManagement/tcheckin/', id, '\">通過</a>') end) as BtnAudit"),
  80. 'id',
  81. \DB::raw("CONCAT(IFNULL(day_tmp, ''), '<hr>', IFNULL(day, '')) as day"),
  82. \DB::raw("CONCAT(IFNULL(gp_tmp, ''), '<hr>', IFNULL(gp, '')) as gp"),
  83. 'cdate',
  84. 'mdate',
  85. \DB::raw("(select name from users where id=tcheckinGpAlloc.oid) as oid"),
  86. ]);
  87. // 過濾搜尋條件
  88. // 取總筆數
  89. $cnt = $tcheckins->count();
  90. // 排序
  91. $tcheckins = $tcheckins
  92. ->orderByRaw((int)$orderColumn . ' ' . $orderDir);
  93. // 彙整
  94. // 分頁
  95. $tcheckins = $tcheckins
  96. ->skip($start)->take($length);
  97. // 實際取資料
  98. $tcheckins = $tcheckins
  99. ->get()
  100. ->toArray();
  101. // 整理返回值並返回
  102. return $tcheckins;
  103. }
  104. public function getTGoods(
  105. &$cnt = 0,
  106. $orderColumn,
  107. $orderDir,
  108. $start,
  109. $length,
  110. $searchValue
  111. )
  112. {
  113. $tgoods = $this->tgoodManagementDb
  114. ->select([
  115. \DB::raw("(case when lp_tmp=lp and ratio_tmp=ratio and active_tmp=active and totalQty_tmp=totalQty then '' else CONCAT('<a href=\"tauditManagement/tgood/', id, '\">通過</a>') end) as BtnTAudit"),
  116. 'id',
  117. \DB::raw("CONCAT(IFNULL(lp_tmp, ''), '<hr>', IFNULL(lp, '')) as lp"),
  118. \DB::raw("CONCAT(IFNULL(ratio_tmp, ''), '<hr>', IFNULL(ratio, '')) as ratio"),
  119. \DB::raw("CONCAT(IFNULL(active_tmp, ''), '<hr>', IFNULL(active, '')) as active"),
  120. \DB::raw("CONCAT(IFNULL(totalQty_tmp, ''), '<hr>', IFNULL(totalQty, '')) as totalQty"),
  121. 'issuedQty',
  122. 'cdate',
  123. 'mdate',
  124. \DB::raw("(select name from users where id=tgoods.oid) as oid"),
  125. ]);
  126. // 過濾搜尋條件
  127. // 取總筆數
  128. $cnt = $tgoods->count();
  129. // 排序
  130. $tgoods = $tgoods
  131. ->orderByRaw((int)$orderColumn . ' ' . $orderDir);
  132. // 彙整
  133. // 分頁
  134. $tgoods = $tgoods
  135. ->skip($start)->take($length);
  136. // 實際取資料
  137. $tgoods = $tgoods
  138. ->get()
  139. ->toArray();
  140. // 整理返回值並返回
  141. return $tgoods;
  142. }
  143. public function passTRound($id, $oid)
  144. {
  145. // 寫入
  146. $data = [
  147. 'dateBegin' => \DB::raw('dateBegin' . '_tmp'),
  148. 'dateFinal' => \DB::raw('dateFinal' . '_tmp'),
  149. 'redeemExtra' => \DB::raw('redeemExtra' . '_tmp'),
  150. 'mdate' => date('Y-m-d H:i:s'),
  151. 'oid' => $oid,
  152. ];
  153. $res = $this->troundManagementDb->where('id', $id)->update($data);
  154. $rc = \DB::select("SELECT ROW_COUNT() AS rc;");
  155. $rc = $rc[0]->rc;
  156. // syslogt
  157. $this->syslogtManagementDb
  158. ->insert([
  159. 'type' => GeneralConst::LOG_ADMIN,
  160. 'func' => __FUNCTION__,
  161. 'k' => $oid,
  162. 'memoIn' => json_encode(['id' => $id, 'data' => $data], JSON_UNESCAPED_UNICODE),
  163. 'memoOut' => json_encode(['rc' => $rc], JSON_UNESCAPED_UNICODE),
  164. 'cdate' => date("Y-m-d H:i:s"),
  165. ]);
  166. // 整理返回值並返回
  167. return $res;
  168. }
  169. public function passTCheckin($id, $oid)
  170. {
  171. // 寫入
  172. $data = [
  173. 'day' => \DB::raw('day' . '_tmp'),
  174. 'gp' => \DB::raw('gp' . '_tmp'),
  175. 'mdate' => date('Y-m-d H:i:s'),
  176. 'oid' => $oid,
  177. ];
  178. $res = $this->tcheckinManagementDb->where('id', $id)->update($data);
  179. $rc = \DB::select("SELECT ROW_COUNT() AS rc;");
  180. $rc = $rc[0]->rc;
  181. // syslog
  182. $this->syslogtManagementDb
  183. ->insert([
  184. 'type' => GeneralConst::LOG_ADMIN,
  185. 'func' => __FUNCTION__,
  186. 'k' => $oid,
  187. 'memoIn' => json_encode(['id' => $id, 'data' => $data], JSON_UNESCAPED_UNICODE),
  188. 'memoOut' => json_encode(['rc' => $rc], JSON_UNESCAPED_UNICODE),
  189. 'cdate' => date("Y-m-d H:i:s"),
  190. ]);
  191. // 整理返回值並返回
  192. return $res;
  193. }
  194. public function passTGood($id, $oid)
  195. {
  196. // 寫入
  197. $data = [
  198. 'lp' => \DB::raw('lp' . '_tmp'),
  199. 'ratio' => \DB::raw('ratio' . '_tmp'),
  200. 'active' => \DB::raw('active' . '_tmp'),
  201. 'totalQty' => \DB::raw('totalQty' . '_tmp'),
  202. 'mdate' => date('Y-m-d H:i:s'),
  203. 'oid' => $oid,
  204. ];
  205. $res = $this->tgoodManagementDb->where('id', $id)->update($data);
  206. $rc = \DB::select("SELECT ROW_COUNT() AS rc;");
  207. $rc = $rc[0]->rc;
  208. // syslogt
  209. $this->syslogtManagementDb
  210. ->insert([
  211. 'type' => GeneralConst::LOG_ADMIN,
  212. 'func' => __FUNCTION__,
  213. 'k' => $oid,
  214. 'memoIn' => json_encode(['id' => $id, 'data' => $data], JSON_UNESCAPED_UNICODE),
  215. 'memoOut' => json_encode(['rc' => $rc], JSON_UNESCAPED_UNICODE),
  216. 'cdate' => date("Y-m-d H:i:s"),
  217. ]);
  218. // 整理返回值並返回
  219. return $res;
  220. }
  221. }