| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 | 
							- <?php
 - 
 - namespace App\Http\Services\Backend\DataManagement;
 - 
 - use App\Http\Services\ConstDef\GeneralConst;
 - use App\Models\Web\TGood;
 - use App\Models\Web\Syslogt;
 - 
 - class TGoodManagementService
 - {
 -     // 相關私有 model 調用器宣告
 -     private $tgoodManagementDb;
 -     private $syslogtManagementDb;
 -     
 -     public function __construct()
 -     {
 -         date_default_timezone_set("Asia/Taipei");
 -         // 建構 model 調用器
 -         $this->tgoodManagementDb = new TGood();
 -         $this->syslogtManagementDb = new Syslogt();
 -     }
 -     
 -     public function getTGoods(
 -         &$cnt = 0,
 -         $orderColumn,
 -         $orderDir,
 -         $start,
 -         $length,
 -         $searchValue
 -     )
 -     {
 -         $tgoods = $this->tgoodManagementDb
 -             ->select([
 -                 'id',
 -                 \DB::raw("CONCAT('<a href=\"tgoodManagement/edit/', id, '\">', IFNULL(lp_tmp, ''), '</a>', '<hr>', IFNULL(lp, '')) as lp"),
 -                 \DB::raw("CONCAT(IFNULL(ratio_tmp, ''), '<hr>', IFNULL(ratio, '')) as ratio"),
 -                 \DB::raw("CONCAT(IFNULL(active_tmp, ''), '<hr>', IFNULL(active, '')) as active"),
 -                 \DB::raw("CONCAT(IFNULL(totalQty_tmp, ''), '<hr>', IFNULL(totalQty, '')) as totalQty"),
 -                 'issuedQty',
 -                 'cdate',
 -                 'mdate',
 -                 \DB::raw("(select name from users where id=tgoods.oid) as oid"),
 -             ]);
 -         // 過濾搜尋條件
 -         // 取總筆數
 -         $cnt = $tgoods->count();
 -         // 排序
 -         $tgoods = $tgoods
 -             ->orderByRaw((int)$orderColumn . ' ' . $orderDir);
 -         // 彙整
 -         // 分頁
 -         $tgoods = $tgoods
 -             ->skip($start)->take($length);
 -         // 實際取資料
 -         $tgoods = $tgoods
 -             ->get()
 -             ->toArray();
 -         
 -         // 整理返回值並返回
 -         return $tgoods;
 -     }
 -     
 -     public function getTGoodById($id)
 -     {
 -         // 取得參數
 -         // 調用資料庫(或者其他業務邏輯)
 -         $tgoods = $this->tgoodManagementDb->select([
 -             'id',
 -             \DB::raw("lp_tmp as lp"),
 -             \DB::raw("ratio_tmp as ratio"),
 -             \DB::raw("active_tmp as active"),
 -             \DB::raw("totalQty_tmp as totalQty"),
 -             'issuedQty',
 -             'cdate',
 -             'mdate',
 -             \DB::raw("(select name from users where id=tgoods.oid) as oid"),
 -         ])
 -             ->where('id', $id)
 -             ->first()
 -             ->toArray();
 -         
 -         // 整理返回值並返回
 -         return $tgoods;
 -     }
 -     
 -     public function insertTGood($lp, $ratio, $active, $totalQty, $oid)
 -     {
 -         // 取得參數
 -         $data = [
 -             'lp' . '_tmp'       => $lp,
 -             'ratio' . '_tmp'    => $ratio,
 -             'active' . '_tmp'   => $active,
 -             'totalQty' . '_tmp' => $totalQty,
 -             'issuedQty'         => 0,
 -             'cdate'             => date('Y-m-d H:i:s'),
 -             'mdate'             => date('Y-m-d H:i:s'),
 -             'oid'               => $oid,
 -         ];
 -         // 調用資料庫(或者其他業務邏輯)
 -         $this->tgoodManagementDb
 -             ->insert($data);
 -         $id = \DB::getPdo()->lastInsertId();
 -         // syslogt
 -         $this->syslogtManagementDb
 -             ->insert([
 -                 'type'    => GeneralConst::LOG_ADMIN,
 -                 'func'    => __FUNCTION__,
 -                 'k'       => $oid,
 -                 'memoIn'  => json_encode(['data' => $data], JSON_UNESCAPED_UNICODE),
 -                 'memoOut' => json_encode(['id' => $id], JSON_UNESCAPED_UNICODE),
 -                 'cdate'   => date("Y-m-d H:i:s"),
 -             ]);
 -         
 -         // 整理返回值並返回
 -         return $id;
 -     }
 -     
 -     public function modifyTGood($id, $lp, $ratio, $active, $totalQty, $oid)
 -     {
 -         // 取得參數
 -         $data = [
 -             'lp' . '_tmp'       => $lp,
 -             'ratio' . '_tmp'    => $ratio,
 -             'active' . '_tmp'   => $active,
 -             'totalQty' . '_tmp' => $totalQty,
 -             'mdate'             => date('Y-m-d H:i:s'),
 -             'oid'               => $oid,
 -         ];
 -         // 調用資料庫(或者其他業務邏輯)
 -         $res = $this->tgoodManagementDb
 -             ->where('id', $id)
 -             ->update($data);
 -         $rc = \DB::select("SELECT ROW_COUNT() AS rc;");
 -         $rc = $rc[0]->rc;
 -         // syslogt
 -         $this->syslogtManagementDb
 -             ->insert([
 -                 'type'    => GeneralConst::LOG_ADMIN,
 -                 'func'    => __FUNCTION__,
 -                 'k'       => $oid,
 -                 'memoIn'  => json_encode(['id' => $id, 'data' => $data], JSON_UNESCAPED_UNICODE),
 -                 'memoOut' => json_encode(['rc' => $rc], JSON_UNESCAPED_UNICODE),
 -                 'cdate'   => date("Y-m-d H:i:s"),
 -             ]);
 -         
 -         // 整理返回值並返回
 -         return $res;
 -     }
 -     
 - }
 
 
  |