<?php
|
|
namespace app\operations\model\plus\agent;
|
|
use app\common\model\plus\agent\Product as AgentProductModel;
|
use app\common\model\product\Product as ProductModel;
|
|
/**
|
* 分销商用户模型
|
*/
|
class Product extends AgentProductModel
|
{
|
public function getList($product_id)
|
{
|
return $this->where('product_id', '=', $product_id)
|
->select();
|
}
|
|
/**
|
* 保存
|
*/
|
public function edit($params)
|
{
|
$this->startTrans();
|
try {
|
(new ProductModel())->where('product_id', '=', $params['product_id'])
|
->save([
|
'is_agent' => $params['is_agent'],
|
]);
|
// 参与分销
|
if ($params['is_agent'] == 1) {
|
// 先删除
|
$model = self::detail($params['product_id']);
|
if(!$model){
|
$model = new self();
|
}
|
$model->save(array_merge($params, [
|
'app_id' => self::$app_id
|
]));
|
}
|
$this->commit();
|
return true;
|
} catch (\Exception $e) {
|
$this->error = $e->getMessage();
|
$this->rollback();
|
return false;
|
}
|
}
|
|
//设置状态
|
public function setAgent($productIds, $is_agent)
|
{
|
$productIds = explode(",",$productIds);
|
if($is_agent == 1){
|
// 先删除
|
$model = $this;
|
$model->where('product_id', 'in', $productIds)->delete();
|
foreach ($productIds as $val){
|
$save_data=[
|
'is_ind_agent' => 0,
|
'agent_money_type' => 10,
|
'product_id' => $val,
|
'app_id' => self::$app_id,
|
];
|
$this->create($save_data);
|
}
|
}
|
return (new ProductModel)->where('product_id', 'in', $productIds)->save(['is_agent' => $is_agent]);
|
}
|
}
|