|
@@ -15,6 +15,7 @@ namespace app\common\repositories\store;
|
|
|
|
|
|
use app\common\dao\store\StorePercentageDao as dao;
|
|
|
use app\common\repositories\BaseRepository;
|
|
|
+use app\common\repositories\store\order\StoreOrderRepository;
|
|
|
|
|
|
/**
|
|
|
* @mixin dao
|
|
@@ -22,9 +23,64 @@ use app\common\repositories\BaseRepository;
|
|
|
class StorePercentageRepository extends BaseRepository
|
|
|
{
|
|
|
|
|
|
+ public $one_register_percentage;
|
|
|
+ public $two_register_percentage;
|
|
|
+ public $one_attention_percentage;
|
|
|
+ public $two_attention_percentage;
|
|
|
+ public $one_order_percentage;
|
|
|
+ public $two_order_percentage;
|
|
|
public function __construct(dao $dao)
|
|
|
{
|
|
|
$this->dao = $dao;
|
|
|
+ $this->one_register_percentage = 5;
|
|
|
+ $this->two_register_percentage = 3;
|
|
|
+ $this->one_attention_percentage = 8;
|
|
|
+ $this->two_attention_percentage = 6;
|
|
|
+ $this->one_order_percentage = 8;
|
|
|
+ $this->two_order_percentage = 6;
|
|
|
+ }
|
|
|
+ //抵扣返利比
|
|
|
+ public function deduction_percentage($deduction_type,$passivity_user_id,$order_id,StoreOrderRepository $order_epository){
|
|
|
+ switch ($deduction_type){
|
|
|
+ case 1:
|
|
|
+ $deduction_num = $this->one_register_percentage;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ $deduction_num = $this->two_register_percentage;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ $deduction_num = $this->one_attention_percentage;
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ $deduction_num = $this->two_attention_percentage;
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ $deduction_num = $this->one_order_percentage;
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ $deduction_num = $this->two_order_percentage;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if($deduction_num <= 0){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $order_info = $order_epository->findOrCreate(array('order_id'=>$order_id));
|
|
|
+ $order_status = $order_info->status;
|
|
|
+ if(!in_array($order_status,[0,1,4])){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $residue_percentage = $order_info->residue_percentage - $deduction_num;
|
|
|
+ if($residue_percentage <= 0 && $order_status == 4){
|
|
|
+ $order_status = 0;
|
|
|
+ }
|
|
|
+ $order_epository->update($order_id,array('residue_percentage'=>$residue_percentage,'status'=>$order_status));
|
|
|
+ $percentage_data = array(
|
|
|
+ 'user_id' => $order_info->uid,
|
|
|
+ 'deduction_num' => $deduction_num,
|
|
|
+ 'deduction_type' => $deduction_type,
|
|
|
+ 'passivity_user_id' => $passivity_user_id,
|
|
|
+ 'order_id' => $order_id
|
|
|
+ );
|
|
|
+ $this->create($percentage_data);
|
|
|
}
|
|
|
-
|
|
|
}
|