REAPI/app/merchant/controller/ProjectProduct.php
2024-09-29 15:43:18 +08:00

153 lines
6.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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 ProjectProduct extends Controller
{
/**
* 绑定数据表
* @var string
*/
public $table = 'merchant_project_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()) {
$this->mid = input('mid');
$this->project_id = input('project_id');
$this->merchant = $this->app->db->name('merchant_list')->where(array('id' => $this->mid))->find();
$this->project = $this->app->db->name('merchant_project')->where(array('id' => $this->project_id))->find();
$this->title = '商户通道关联渠道列表';
$w = array
(
'mid' => $this->mid,
'project_id' => $this->project_id,
);
$relation = $this->app->db->name($this->table)->where($w)->select()->toArray();
foreach ($relation as $k => $v) {
$this->relation[$v['pid']] = $v;
}
$w = array
(
'status' => 1,
'is_deleted' => 0,
);
$this->list = $this->app->db->name('ChannelList')->where($w)->select()->toArray();
foreach ($this->list as $k => $v) {
$this->list[$k]['product'] = $this->app->db->name('ChannelProduct')->where('cid',$v['id'])->where($w)->select()->toArray();
foreach ($this->list[$k]['product'] as $k1 => $v1) {
# 可用面值
if ($this->list[$k]['product'][$k1]['value']) {
$this->list[$k]['product'][$k1]['value'] = explode(',', $this->list[$k]['product'][$k1]['value']);
} else {
$this->list[$k]['product'][$k1]['value'] = array();
}
if (isset($this->relation[$v1['id']]) && $this->relation[$v1['id']]) {
$this->list[$k]['product'][$k1]['select'] = 1;
$this->list[$k]['product'][$k1]['cash'] = explode(',', $this->relation[$v1['id']]['cash']);
$this->list[$k]['product'][$k1]['sort'] = $this->relation[$v1['id']]['sort'];
} else {
$this->list[$k]['product'][$k1]['select'] = 0;
$this->list[$k]['product'][$k1]['cash'] = array();
$this->list[$k]['product'][$k1]['sort'] = $v1['sort'];
}
}
}
$this->_form($this->table, 'setting','',[],$this->list);
} else {
$data = input();
$mid = $data['mid'];
$project_id = $data['project_id'];
$all = $this->app->db->name($this->table)->where(array('mid' => $mid, 'project_id' => $project_id))->select()->toArray();
$select = $product_key = array();
if ($all) {
foreach ($all as $k => $v) {
$select[$v['pid']] = $v;
}
}
if ($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'] = '';
}
if (isset($select[$pid]) && $select[$pid]) {
$update['mid'] = $mid;
$update['project_id'] = $project_id;
$update['cid'] = $cid;
$update['pid'] = $pid;
$this->app->db->name($this->table)->where(array('id' => $select[$pid]['id']))->update($update);
unset($select[$pid]);
} else {
$update['mid'] = $mid;
$update['project_id'] = $project_id;
$update['cid'] = $cid;
$update['pid'] = $pid;
$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('操作成功', '');
}
}
}