160 lines
5.0 KiB
PHP
160 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace addon\merch\model;
|
|
use app\model\BaseModel;
|
|
use app\model\system\Cron;
|
|
use app\model\upload\Upload;
|
|
use app\model\system\Group;
|
|
use app\model\system\User;
|
|
use think\facade\Db;
|
|
class Merch extends BaseModel
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
* 添加商户
|
|
* @param $param
|
|
*/
|
|
public function addMerch($data,$user_data)
|
|
{
|
|
|
|
|
|
if (empty($user_data[ "username" ])) return $this->error('', '用户名不能为空');
|
|
if (empty($user_data[ "password" ])) return $this->error('', '密码不能为空');
|
|
//判断 用户名 是否存在
|
|
$user_info = model('user')->getInfo(
|
|
[
|
|
[ 'username', "=", $user_data[ "username" ] ],
|
|
[ 'site_id', '=', $data['site_id'] ],
|
|
[ 'app_module', '=', 'merch' ]
|
|
]
|
|
);
|
|
if (!empty($user_info)) {
|
|
return $this->error('', '账号已存在');
|
|
}
|
|
//添加系统用户组
|
|
$group_model = new Group();
|
|
$group_data = array (
|
|
"site_id" => $data['site_id'],
|
|
"app_module" => "merch",
|
|
"group_name" => "商户管理员",
|
|
"group_status" => 1,
|
|
"is_system" => 1,
|
|
"menu_array" => "",
|
|
"desc" => "",
|
|
);
|
|
$group_result = $group_model->addGroup($group_data);
|
|
$group_id = $group_result[ "data" ];
|
|
//添加用户
|
|
$user_model = new User();
|
|
$user_data[ "password" ] = $user_data[ "password" ];
|
|
$user_data[ "create_time" ] = time();
|
|
$userdata = array(
|
|
"app_module" => "merch",
|
|
"app_group" => 0,
|
|
'is_admin'=>1,
|
|
"site_id" => $data['site_id'],
|
|
"group_id" => $group_id,
|
|
"username" => $user_data['username'],
|
|
"password" => $user_data['password'],
|
|
);
|
|
$user_result = $user_model->addUser($userdata);
|
|
if ($user_result[ "code" ] < 0) {
|
|
return $this->error('', '商家管理员添加失败!');
|
|
}
|
|
$data['uid'] = $user_result[ "data" ];
|
|
$result = model('merch')->add($data);
|
|
return $this->success($result);
|
|
|
|
|
|
}
|
|
/**
|
|
* 编辑商户
|
|
* @param $param
|
|
*/
|
|
public function editMerch($condition,$data)
|
|
{
|
|
$result = model('merch')->update($condition,$data);
|
|
return $this->success($result);
|
|
}
|
|
|
|
/**
|
|
* 删除商户
|
|
* @param $id
|
|
* @param $site_id
|
|
*/
|
|
public function deleteMerch($id, $site_id)
|
|
{
|
|
$info = model('merch')->getInfo([ [ 'site_id', '=', $site_id ], [ 'merch_id', '=', $id ] ], 'id');
|
|
if (empty($info)) return $this->error('', '未获取到商户信息');
|
|
$res = model('merch')->delete([ [ 'site_id', '=', $site_id ], [ 'merch_id', '=', $id ] ]);
|
|
return $this->success($res);
|
|
}
|
|
|
|
/**
|
|
* 获取商户列表
|
|
* @param array $condition
|
|
* @param bool $field
|
|
* @param string $order
|
|
* @param int $page
|
|
* @param int $list_rows
|
|
* @param string $alias
|
|
* @param array $join
|
|
* @return array
|
|
*/
|
|
public function getMerchPageList($condition = [], $field = true, $order = '', $page = 1, $list_rows = PAGE_LIST_ROWS, $alias = 'a', $join = [])
|
|
{
|
|
$data = model('merch')->pageList($condition, $field, $order, $page, $list_rows, $alias, $join);
|
|
|
|
return $this->success($data);
|
|
}
|
|
|
|
/**
|
|
* 获取文章列表
|
|
* @param array $condition
|
|
* @param string $field
|
|
* @param string $order
|
|
* @param string $limit
|
|
*/
|
|
public function getMerchList($condition = [], $field = '*', $order = '', $limit = null, $alias = '', $join = [])
|
|
{
|
|
$list = model('merch')->getList($condition, $field, $order, $alias, $join, '', $limit);
|
|
return $this->success($list);
|
|
}
|
|
|
|
/**
|
|
* 获取文章分页列表
|
|
* @param array $condition
|
|
* @param int $page
|
|
* @param int $page_size
|
|
* @param string $order
|
|
* @param string $field
|
|
* @return array
|
|
*/
|
|
// public function getArticlePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'pn.sort asc', $field = 'pn.*,png.category_name')
|
|
// {
|
|
// $alias = 'pn';
|
|
// $join = [
|
|
// [
|
|
// 'article_category png',
|
|
// 'png.category_id = pn.category_id',
|
|
// 'left'
|
|
// ]
|
|
// ];
|
|
// $list = model('article')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
|
|
// return $this->success($list);
|
|
// }
|
|
|
|
|
|
/**
|
|
* 修改商户状态
|
|
* @param $id
|
|
* @param $site_id
|
|
*/
|
|
public function statusMerch($merch_id, $status)
|
|
{
|
|
$res = model('merch')->update(['status'=>$status],['merch_id'=>$merch_id]);
|
|
return $this->success($res);
|
|
}
|
|
} |