Files
crew_admin/app/Models/admin/AdminModel.php
2019-12-27 22:34:28 +08:00

262 lines
6.2 KiB
PHP

<?php
namespace App\Models\admin;
use Illuminate\Database\Eloquent\Model;
use DB;
class AdminModel extends Model
{
function selectPaymentDetails($field, $value){
if($field != "All"){
$i = DB::table('payment_details')
->where($field, $value)
->orderby('Id', 'ASC')
->get();
}else{
$i = DB::table('payment_details')
->leftjoin('orders', 'payment_details.CartKey', '=', 'orders.CartKey')
->leftjoin('teamstores', 'teamstores.Id', '=', 'orders.StoreId')
->select('payment_details.*', 'orders.StoreId', 'teamstores.StoreName')
->where("payment_details.CartKey", "!=", null)
->groupby('orders.CartKey')
->orderby('payment_details.Id', 'ASC')
->get();
}
return $i;
}
function selectOrderItem($field, $ck){
$i = DB::table('orders')
->where($field, $ck)
->get();
return $i;
}
function itemGroup($cartKey){
$pdo = DB::connection()->getPdo();
$query = $pdo->prepare("SELECT *, COUNT(Id) AS qty, Price * SUM(Quantity) AS total_price FROM orders WHERE CartKey = :ck GROUP BY ProductId");
$query->execute([':ck'=>$cartKey]);
$row = $query->fetchAll(\PDO::FETCH_OBJ);
return $row;
}
function selectDisplayItemThumb(){
$i = DB::table('teamstore_product_thumbnails')
->where('ImageClass', 'active')
->get();
return $i;
}
function selectShippingAddress($field, $value){
$i = DB::table('shipping_addresses')
->where($field, $value)
->get();
return $i;
}
function selectClientDesign($design_code){
$i = DB::table('client_designs')
->where('DesignCode', $design_code)
->get();
return $i;
}
function insertTeamstore($data){
$i = DB::table('teamstores')->insert($data);
return $i;
}
function selectTeamstore(){
$i = DB::table('teamstores')
->paginate(16);
return $i;
}
function selectTeamstoreFilter($field, $value){
$i = DB::table('teamstores')
->orderby($field, $value)
->paginate(16);
return $i;
}
function selectTeamstoreSearch($field, $value, $keyword){
$i = DB::table('teamstores')
->where("StoreName", "LIKE","%$keyword%")
->orderby($field, $value)
->paginate(16);
return $i;
}
function selectTeamstoreById($id){
$i = DB::table('teamstores')
->where("Id", $id)
->get();
return $i;
}
function updateTeamstore($id, $data){
$i = DB::table('teamstores')
->where("Id", $id)
->update($data);
return $i;
}
function deleteTeamstoreById($id){
$i = DB::table('teamstores')
->where("Id", $id)
->delete();
return $i;
}
function selectPattern(){
$i = DB::table('patterns')
->get();
return $i;
}
function selectPatternWithfield($field, $value){
$i = DB::table('patterns')
->where($field, $value)
->get();
return $i;
}
function selectClipartCategory(){
$i = DB::table('clipart_categories')
->leftjoin('user_logins', 'clipart_categories.UserId', '=', 'user_logins.id')
->select('clipart_categories.*', 'user_logins.username')
->orderby('clipart_categories.Ordering', 'ASC')
->get();
return $i;
}
function ClipartCategory(){
$i = DB::table('clipart_categories')
->leftjoin('user_logins', 'clipart_categories.UserId', '=', 'user_logins.id')
->select('clipart_categories.*', 'user_logins.username')
->orderby('clipart_categories.Ordering', 'ASC')
->paginate(18);
return $i;
}
function selectStoreOwners($store_id){
$i = DB::table('user_logins')
->where('role', 'store_owner')
->where('store_id', $store_id)
->get();
return $i;
}
function insertClipartCategory($data){
$i = DB::table('clipart_categories')->insertGetId($data);
return $i;
}
function insertClipart($data){
$i = DB::table('cliparts')->insert($data);
return $i;
}
function updateClipartCatOrdering($order, $id){
$i = DB::table('clipart_categories')->where('Id', $id)
->update(['Ordering' => $order]);
}
function userList(){
$i = DB::table('user_logins')
->select('id', 'name', 'username', 'email')
// ->where("name", "LIKE","%$keyword%")
// ->orWhere("username", "LIKE","%$keyword%")
// ->orWhere("email", "LIKE","%$keyword%")
->where("role", "user")
->orderby('name', 'ASC')
->get();
return $i;
}
function makeUserAsStoreOwner($data){
$i = DB::table('user_logins')
->where("Id", $data['user_id'])
->update(['role'=> 'store_owner', 'store_id'=> $data['store_id']]);
return $i;
}
function model_removeStoreAccess($data){
$i = DB::table('user_logins')
->where("Id", $data['user_id'])
->update(['role'=> 'user', 'store_id'=> $data['store_id']]);
return $i;
}
function deleteClipartCategory($id){
$i = DB::table('clipart_categories')
->where("Id", $id)
->delete();
return $i;
}
function updateClipartCategory($id, $data){
$i = DB::table('clipart_categories')
->where("Id", $id)
->update($data);
return $i;
}
function selectCliparts(){
$i = DB::table('cliparts')
->orderby("Id", "DESC")
->paginate(16);
return $i;
}
function selectSports(){
$i = DB::table('sports')
->orderby("SportsName", "ASC")
->get();
return $i;
}
function selectSportsCategory($id){
$i = DB::table('template_categories')
->where('TemplateId', $id)
->orderby("Category", "ASC")
->get();
return $i;
}
function selectStoreOrders(){
$i = DB::table('orders')->select('orders.*', 'orders.Id as Order_Id', 'payment_details.InvoiceNumber', 'payment_details.Currency', 'payment_details.Payer_Email', 'payment_details.Payer_Firstname', 'payment_details.Payer_Lastname', 'shipping_addresses.*')
->leftjoin('payment_details', 'payment_details.CartKey','=','orders.CartKey')
->leftjoin('shipping_addresses', 'shipping_addresses.PaymentDetail_Id','=','payment_details.Id')
// ->where('orders.StoreId', $store_id)
->orderby('orders.DateCreated', 'DESC')
->get();
return $i;
}
}