API Mobile

This commit is contained in:
Fiza Ali
2021-02-02 18:57:04 +08:00
parent 829e437e11
commit 1dabcdb086
4 changed files with 152 additions and 1 deletions
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class BankMaster extends Model
{
protected $connection = 'mysql7';
protected $table = 'bank';
protected $primaryKey = 'BANKCODE';
/**
* The attributes that are mass assignable.
*
* @var array
*/
// protected $fillable = [
// ];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
// protected $hidden = [];
}
+43
View File
@@ -3,9 +3,11 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
class Customer extends Model
{
protected $table = 'customer';
public $timestamps = false;
/**
@@ -13,6 +15,8 @@ class Customer extends Model
*
* @var array
*/
protected $primaryKey = ['kplama','kpbaru'];
public $incrementing = false;
protected $fillable = [
'ahli',
'kodcaw',
@@ -65,4 +69,43 @@ class Customer extends Model
* @var array
*/
// protected $hidden = [];
/**
* Set the keys for a save update query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function setKeysForSaveQuery(Builder $query)
{
$keys = $this->getKeyName();
if(!is_array($keys)){
return parent::setKeysForSaveQuery($query);
}
foreach($keys as $keyName){
$query->where($keyName, '=', $this->getKeyForSaveQuery($keyName));
}
return $query;
}
/**
* Get the primary key value for a save query.
*
* @param mixed $keyName
* @return mixed
*/
protected function getKeyForSaveQuery($keyName = null)
{
if(is_null($keyName)){
$keyName = $this->getKeyName();
}
if (isset($this->original[$keyName])) {
return $this->original[$keyName];
}
return $this->getAttribute($keyName);
}
}
+77 -1
View File
@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\BankMaster;
use App\Customer;
use App\Gadai;
use App\Lelong;
@@ -418,4 +419,79 @@ class CustomerController extends Controller
return response('Deleted Successfully', 200);
}
}
public function akaunBankMobile($nokp)
{
$array_cust = [];
$cawangan_all = Cawangan::on('mysql7')->get();
foreach($cawangan_all as $cawangan)
{
$customer = Customer::on($cawangan['mysql'])
->where('kplama','=',$nokp)
->orWhere('kpbaru','=',$nokp)
->rightJoin('online_arrahn.bank', 'bank.id', '=', 'customer.kodbank')
->first();
if(!empty($customer))
{
$customer_detail['noakaun'] = $customer['noakaun'];
$customer_detail['namabank'] = $customer['name'];
$customer_detail['kodbank'] = $customer['id'];
return response()->json($customer_detail);
}
else
{
return response()->json('Data Not Found');
}
}
}
public function bankListMobile()
{
$bank_array = [];
$cawangan_all = Cawangan::on('mysql7')->get();
foreach($cawangan_all as $cawangan)
{
$bank = BankMaster::get();
if(!empty($bank))
{
//loop each array
foreach($bank as $banklist)
{
array_push($bank_array, array(
'kodbank' => $banklist->id,
'namabank' => $banklist->name,
));
}
return response()->json($bank_array);
}
else
{
return response()->json('Data Not Found');
}
}
}
public function insertAkaunBankMobile(Request $request)
{
$cawangan_all = Cawangan::on('mysql7')->get(); //return all 8 branches
foreach($cawangan_all as $index=>$cawangan)
{
$customer = Customer::on($cawangan['mysql']) //search Customer on dtabase cawangan (1-8)
->where('kplama','=',$request->nokp)
->orWhere('kpbaru','=',$request->nokp)
->first();
if(!empty($customer))
{
$customer->kodbank = $request->kodbank;
$customer->noakaun = $request->noakaun;
$customer->save();
}
}
return response()->json($customer, 200);
}
}
+3
View File
@@ -270,6 +270,9 @@ $router->group(['prefix'=>'mobile'], function () use ($router){
$router->get('harga_emas',['uses'=>'HargaEmasController@showAllHargaEmasMobile']);
$router->get('gadai/norujukan/count/{nokp}',['uses'=>'CustomerController@countNorujukanMobile']);
$router->get('gadai/norujukan/{nokp}',['uses'=>'CustomerController@listNorujukanMobile']);
$router->get('akaun-bank/{nokp}',['uses'=>'CustomerController@akaunBankMobile']);
$router->get('bank-listing/{nokp}',['uses'=>'CustomerController@bankListMobile']);
$router->post('insert/akaun-bank',['uses'=>'CustomerController@insertAkaunBankMobile']);
//gadaian
$router->get('gadai/{noic}',['uses'=>'GadaiController@showOneGadaiMobile']);