add daily listing by paid_by, add customer cart details
This commit is contained in:
@@ -5,6 +5,7 @@ namespace common\models;
|
||||
use Yii;
|
||||
use yii\db\Query;
|
||||
use yii\db\Expression;
|
||||
use common\components\Helper;
|
||||
|
||||
/**
|
||||
* This is the model class for table "user_sold_item".
|
||||
@@ -89,27 +90,55 @@ class UserSoldItem extends \yii\db\ActiveRecord
|
||||
/**
|
||||
* @param common\models\User $user
|
||||
* */
|
||||
public static function payout( $user, $idTransfers = null ) {
|
||||
public static function payout( $user, $idTransfers = null, $account = null ) {
|
||||
//apply transfer object
|
||||
//delete cart
|
||||
$sql = "UPDATE transfer AS t
|
||||
INNER JOIN user_sold_item AS s ON t.id_transfer = s.id_transfer
|
||||
SET t.paid_by = ".$user->id.", t.status = " . Transfer::STATUS_PAID . ", t.paid_at = '" . date('Y-m-d H:i:s' ) ."'"
|
||||
. " WHERE t.status = " . Transfer::STATUS_NOT_PAID
|
||||
. " and s.id_user =" . $user->id ;
|
||||
SET t.paid_by = ".$user->id.", t.status = " . Transfer::STATUS_PAID . ", t.paid_at = '" . date('Y-m-d H:i:s' ) ."' ";
|
||||
|
||||
if ( isset($idTransfers)){
|
||||
$sql .= " and t.id_transfer in ( '" . implode("','", $idTransfers )."' )";
|
||||
}
|
||||
if ( isset($account)){
|
||||
$sql .= " , id_account = " . $account;
|
||||
}
|
||||
|
||||
$sql .= " WHERE t.status = " . Transfer::STATUS_NOT_PAID;
|
||||
|
||||
//we can see all transfer in cart, or just our
|
||||
if ( Helper::isUserCartVisibilityUser()){
|
||||
$sql .= " and s.id_user =" . $user->id ;
|
||||
}
|
||||
|
||||
//just payout selected transfers
|
||||
if ( isset($idTransfers)){
|
||||
$sql .= " and t.id_transfer in ( '" . implode("','", $idTransfers )."' )";
|
||||
}
|
||||
|
||||
$q1 = Yii::$app->db->createCommand($sql);
|
||||
$q1->execute();
|
||||
|
||||
|
||||
$deleteConditions = [];
|
||||
|
||||
if ( isset($idTransfers) ){
|
||||
UserSoldItem::deleteAll(['and' ,['id_user' => Yii::$app->user->id] ,['in','id_transfer',$idTransfers] ]);
|
||||
}else{
|
||||
UserSoldItem::deleteAll(['id_user' => Yii::$app->user->id]);
|
||||
$deleteConditions[] = ['in','id_transfer',$idTransfers];
|
||||
}
|
||||
|
||||
if ( Helper::isUserCartVisibilityUser()){
|
||||
$deleteConditions[] = ['id_user' => Yii::$app->user->id];
|
||||
}
|
||||
|
||||
if ( count($deleteConditions) > 1 ){
|
||||
// ['and', 'cond1','cond2']
|
||||
$deleteConditions = ["and"] + $deleteConditions;
|
||||
}else if ( count($deleteConditions) == 1 ){
|
||||
//[a => b ]
|
||||
$deleteConditions = $deleteConditions[0];
|
||||
}else{
|
||||
//[]
|
||||
$deleteConditions = [];
|
||||
}
|
||||
UserSoldItem::deleteAll($deleteConditions);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user