168 lines
6.0 KiB
PHP
168 lines
6.0 KiB
PHP
![]() |
<?php
|
|||
|
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | ThinkAdmin
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | 官方网站: https://thinkadmin.top
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | 开源协议 ( https://mit-license.org )
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
|
|||
|
// | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
|
|||
|
namespace app\merchant\controller;
|
|||
|
|
|||
|
use think\admin\Controller;
|
|||
|
use app\merchant\service\MerchantLogService;
|
|||
|
use app\merchant\service\MerchantService;
|
|||
|
use app\channel\service\ProductService;
|
|||
|
use app\merchant\service\OrderService;
|
|||
|
use app\merchant\service\PercentService;
|
|||
|
/**
|
|||
|
* 商户关联渠道产品管理
|
|||
|
* Class MerchantRelation
|
|||
|
* @package app\merchant\controller
|
|||
|
*/
|
|||
|
class Product extends Controller
|
|||
|
{
|
|||
|
|
|||
|
/**
|
|||
|
* 绑定数据表
|
|||
|
* @var string
|
|||
|
*/
|
|||
|
public $table = 'merchant_product';
|
|||
|
|
|||
|
/**
|
|||
|
* 编辑商户关联渠道
|
|||
|
* @auth true
|
|||
|
* @throws \think\db\exception\DataNotFoundException
|
|||
|
* @throws \think\db\exception\DbException
|
|||
|
* @throws \think\db\exception\ModelNotFoundException
|
|||
|
*/
|
|||
|
public function setting()
|
|||
|
{
|
|||
|
if ($this->request->isGet()) {
|
|||
|
$id = input('id');
|
|||
|
$this->vo = $this->app->db->name('merchant_list')->where(array('id' => $id))->find();
|
|||
|
$this->title = '商户关联渠道列表';
|
|||
|
$w = array
|
|||
|
(
|
|||
|
'mid' => $id,
|
|||
|
);
|
|||
|
|
|||
|
$relation = $this->app->db->name($this->table)->where($w)->order('sort desc,id desc')->select()->toArray();
|
|||
|
foreach ($relation as $k => $v) {
|
|||
|
$this->relation[$v['pid']] = $v;
|
|||
|
}
|
|||
|
|
|||
|
$w = array
|
|||
|
(
|
|||
|
'status' => 1,
|
|||
|
'is_deleted' => 0,
|
|||
|
);
|
|||
|
$channelData = $this->app->db->name('ChannelList')->where($w)->select()->toArray();
|
|||
|
$channel = array();
|
|||
|
foreach ($channelData as $k => $v) {
|
|||
|
$channel[$v['id']] = $v;
|
|||
|
}
|
|||
|
|
|||
|
$sort = array();
|
|||
|
$this->name = $this->product = array();
|
|||
|
$product = $this->app->db->name('ChannelProduct')->where($w)->order('sort desc,id desc')->select()->toArray();
|
|||
|
|
|||
|
foreach ($product as $k => $v) {
|
|||
|
if (!isset($this->name[$v['key']])) {
|
|||
|
$this->name[$v['key']] = $v['name'];
|
|||
|
}
|
|||
|
if (!isset($channel[$v['cid']])) {
|
|||
|
continue;
|
|||
|
}
|
|||
|
$v['channel'] = $channel[$v['cid']];
|
|||
|
# 可用面值
|
|||
|
if ($v['value']) {
|
|||
|
$v['value'] = explode(',', $v['value']);
|
|||
|
} else {
|
|||
|
$v['value'] = array();
|
|||
|
}
|
|||
|
|
|||
|
if (isset($this->relation[$v['id']]) && $this->relation[$v['id']]) {
|
|||
|
$v['select'] = 1;
|
|||
|
$v['cash'] = explode(',', $this->relation[$v['id']]['cash']);
|
|||
|
$v['sort'] = $this->relation[$v['id']]['sort'];
|
|||
|
} else {
|
|||
|
$v['select'] = 0;
|
|||
|
$v['cash'] = array();
|
|||
|
$v['sort'] = $v['sort'];
|
|||
|
}
|
|||
|
$sort[$v['key']][] = $v['sort'];
|
|||
|
|
|||
|
$this->product[$v['key']][] = $v;
|
|||
|
|
|||
|
array_multisort($sort, SORT_DESC, SORT_NUMERIC, $this->product);
|
|||
|
}
|
|||
|
|
|||
|
if ($sort && $this->name) {
|
|||
|
foreach ($this->name as $k => $v) {
|
|||
|
if (isset($sort[$k])) {
|
|||
|
array_multisort($sort[$k], SORT_DESC, SORT_NUMERIC, $this->product[$k]);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
$this->_form($this->table, 'setting','',[], $this->product);
|
|||
|
} else {
|
|||
|
$data = input();
|
|||
|
|
|||
|
$mid = $data['mid'];
|
|||
|
$all = $this->app->db->name($this->table)->where(array('mid' => $mid))->select()->toArray();
|
|||
|
$select = $product_key = array();
|
|||
|
if ($all) {
|
|||
|
foreach ($all as $k => $v) {
|
|||
|
$select[$v['pid']] = $v;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (isset($data['pid']) && $data['pid']) {
|
|||
|
foreach ($data['pid'] as $k => $v) {
|
|||
|
$t = explode('|', $v);
|
|||
|
$pid = $t[0];
|
|||
|
$cid = $t[1];
|
|||
|
$product = $this->app->db->name('ChannelProduct')->where(array('id' => $pid))->find();
|
|||
|
if ($product) {
|
|||
|
$update['product_key'] = $product['key'];
|
|||
|
if (isset($data['sort_' . $pid]) && $data['sort_' . $pid]) {
|
|||
|
$update['sort'] = $data['sort_' . $pid];
|
|||
|
}
|
|||
|
if (isset($data['cash_' . $pid]) && $data['cash_' . $pid]) {
|
|||
|
$update['cash'] = implode(',', $data['cash_' . $pid]);
|
|||
|
} else {
|
|||
|
$update['cash'] = '';
|
|||
|
}
|
|||
|
$update['mid'] = $mid;
|
|||
|
$update['cid'] = $cid;
|
|||
|
$update['pid'] = $pid;
|
|||
|
if (isset($select[$pid]) && $select[$pid]) {
|
|||
|
$this->app->db->name($this->table)->where(array('id' => $select[$pid]['id']))->update($update);
|
|||
|
unset($select[$pid]);
|
|||
|
} else {
|
|||
|
$this->app->db->name($this->table)->insert($update);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if ($select) {
|
|||
|
# 删除
|
|||
|
foreach ($select as $k => $v) {
|
|||
|
$this->app->db->name($this->table)->where(array('id' => $v['id']))->delete();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
$this->success('操作成功', '');
|
|||
|
}
|
|||
|
}
|
|||
|
}
|