383 行
14 KiB
PHP
可执行文件
383 行
14 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Retail\Controller;
|
||
|
||
use Retail\Business\DaDa;
|
||
use Think\Controller;
|
||
|
||
//[1.7.90]
|
||
class DeliveryController extends BaseController
|
||
{
|
||
public function configure()
|
||
{
|
||
$info = M('retail_da_merchant')->where(array('merchantid' => $this->merchant_id))->find();
|
||
//如果存在不能添加
|
||
if ($info) {
|
||
$this->assign('add', 1);
|
||
} else {
|
||
$this->assign('add', 2);
|
||
}
|
||
$arr = array(
|
||
'addDamerchant' => '/index.php/Retail/Delivery/addDamerchant',
|
||
'query' => '/index.php/Retail/Delivery/query',
|
||
'recharge' => '/index.php/Retail/Delivery/recharge',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$this->display();
|
||
}
|
||
|
||
//达达商户信息
|
||
public function getDamerchant()
|
||
{
|
||
$info = M('retail_da_merchant')->where(array('merchantid' => $this->merchant_id))->select();
|
||
if ($info) {
|
||
$count = M('retail_da_merchant')->where(array('merchantid' => $this->merchant_id))->count();
|
||
foreach ($info as $key => $val) {
|
||
$info[$key]['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
|
||
}
|
||
$res['add_status'] = true;
|
||
} else {
|
||
$res['add_status'] = false;
|
||
}
|
||
$res['code'] = 0;
|
||
$res['msg'] = '';
|
||
$res['data'] = $info;
|
||
$res['count'] = $count ? $count : 0;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//添加达达商户页面
|
||
public function addDamerchant()
|
||
{
|
||
$this->assign('merchantid', $this->merchant_id);
|
||
$this->display();
|
||
}
|
||
|
||
//注册达达商户操作
|
||
public function addDameract()
|
||
{
|
||
if (IS_POST) {
|
||
$data['mobile'] = I('post.mobile');
|
||
$data['city_name'] = I('post.city_name');
|
||
$data['enterprise_name'] = I('post.enterprise_name');
|
||
$data['enterprise_address'] = I('post.enterprise_address');
|
||
$data['contact_name'] = I('post.contact_name');
|
||
$data['contact_phone'] = I('post.contact_phone');
|
||
$data['email'] = I('post.email');
|
||
$data['merchantid'] = I('post.merchantid');
|
||
if (!$data['mobile'] || !$data['city_name'] || !$data['enterprise_name'] || !$data['enterprise_address'] || !$data['contact_name'] || !$data['contact_phone'] || !$data['email'] || !$data['merchantid']) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '信息有误,请重新输入';
|
||
} else {
|
||
$partnerid = M('retail_merchant')->where(array('id' => $data['merchantid']))->getField('partnerid');
|
||
$developer = M('retail_da_developer')->where(array('partnerid' => $partnerid))->find();
|
||
if (!$developer) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请先联系合伙人完善开发者信息';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
$result = A('Retail/DadaCeshi')->registermerchant($developer['app_key'], $developer['app_secret'], $data);
|
||
$result = json_decode($result, true);
|
||
if ($result['status'] == 'success') {
|
||
$data['addtime'] = time();
|
||
$data['resultid'] = $result['result'];
|
||
$data['status'] = 2;
|
||
$add = M('retail_da_merchant')->add($data);
|
||
if ($add) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '注册成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '注册成功,但信息存入失败';
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = $result['msg'];
|
||
}
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请求方式有误';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 已注册达达商户的用户用于添加已有信息
|
||
*/
|
||
public function addInfo()
|
||
{
|
||
$content = I('post.');
|
||
$data['mobile'] = $content['mobile'];
|
||
$data['city_name'] = $content['city_name'];
|
||
$data['enterprise_name'] = $content['enterprise_name'];
|
||
$data['enterprise_address'] = $content['enterprise_address'];
|
||
$data['contact_name'] = $content['contact_name'];
|
||
$data['contact_phone'] = $content['contact_phone'];
|
||
$data['email'] = $content['email'];
|
||
$data['merchantid'] = $content['merchantid'];
|
||
$data['resultid'] = $content['result_id'];
|
||
if (!$data['mobile'] || !$data['city_name'] || !$data['enterprise_name'] || !$data['enterprise_address'] || !$data['contact_name'] || !$data['contact_phone'] || !$data['email'] || !$data['merchantid'] || !$data['resultid']) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请完善表单信息';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$partnerid = M('retail_merchant')->where(array('id' => $data['merchantid']))->getField('partnerid');
|
||
$developer = M('retail_da_developer')->where(array('partnerid' => $partnerid))->find();
|
||
if (!$developer) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请先联系合伙人完善开发者信息';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$data['addtime'] = time();
|
||
$data['status'] = 2;
|
||
$add = M('retail_da_merchant')->add($data);
|
||
if ($add) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '添加成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '添加失败';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//充值
|
||
public function recharge()
|
||
{
|
||
$id = I('post.id');
|
||
$money = I('post.money');
|
||
if (!$id || !$money) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数错误';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
$data['amount'] = $money;
|
||
$data['category'] = 'PC';
|
||
$data['notify_url'] = 'http://' . C('adminhttp') . '/Retail/store/Home.html';
|
||
$merchantid = M('retail_da_merchant')->where(array('id' => $id))->find();
|
||
if (!$merchantid) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请先注册达达商户';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
$partnerid = M('retail_merchant')->where(array('id' => $merchantid['merchantid']))->getField('partnerid');
|
||
$developer = M('retail_da_developer')->where(array('partnerid' => $partnerid))->find();
|
||
if (!$developer) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请先联系合伙人完善开发者信息';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
$success = A('Retail/DadaCeshi')->recharge($developer['app_key'], $developer['app_secret'], $merchantid['resultid'], $data);
|
||
$success = json_decode($success, true);
|
||
if ($success['status'] == 'success') {
|
||
$res['status'] = 1;
|
||
$res['result'] = $success['result'];
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
$desc = '达达商户充值操作'; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = $success['msg'];
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//余额
|
||
public function query()
|
||
{
|
||
$partnerid = M('retail_merchant')->where(array('id' => $this->merchant_id))->getField('partnerid');
|
||
$developer = M('retail_da_developer')->where(array('partnerid' => $partnerid))->find();
|
||
if (!$developer) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请先联系合伙人完善开发者信息';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
$damerchant = M('retail_da_merchant')->where(array('merchantid' => $this->merchant_id))->find();
|
||
if (!$damerchant) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请先注册达达商户';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
$data['category'] = 3;
|
||
$success = A('Retail/DadaCeshi')->query($developer['app_key'], $developer['app_secret'], $damerchant['resultid'], $data);
|
||
$success = json_decode($success, true);
|
||
if ($success['status'] == 'success') {
|
||
$this->assign('deliverBalance', $success['result']['deliverBalance']);
|
||
$this->assign('redPacketBalance', $success['result']['redPacketBalance']);
|
||
} else {
|
||
$this->assign('deliverBalance', 0.00);
|
||
$this->assign('redPacketBalance', 0.00);
|
||
}
|
||
$this->display();
|
||
}
|
||
|
||
//开发者
|
||
public function developer()
|
||
{
|
||
$developer = M('retail_da_developer')->where(array('merchantid' => $this->merchant_id))->find();
|
||
if ($developer) {
|
||
$this->assign('app_key', $developer['app_key']);
|
||
$this->assign('app_secret', $developer['app_secret']);
|
||
$this->assign('gould_key', $developer['gould_key']);
|
||
} else {
|
||
$this->assign('app_key', '');
|
||
$this->assign('app_secret', '');
|
||
$this->assign('gould_key', '');
|
||
}
|
||
$this->display();
|
||
}
|
||
|
||
//添加开发者
|
||
public function adddeveloper()
|
||
{
|
||
$data['merchantid'] = $this->merchant_id;
|
||
$data['app_key'] = I('post.app_key');
|
||
$data['app_secret'] = I('post.app_secret');
|
||
$data['gould_key'] = I('post.gould_key');
|
||
if (!$data['app_key'] || !$data['app_secret']) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请完善表单信息';
|
||
} else {
|
||
$data['addtime'] = time();
|
||
$developer = M('retail_da_developer')->where(array('merchantid' => $data['merchantid']))->find();
|
||
if (!$developer) {
|
||
$add = M('retail_da_developer')->add($data);
|
||
} else {
|
||
$add = M('retail_da_developer')->where(array('merchantid' => $data['merchantid']))->save($data);
|
||
}
|
||
if ($add) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '设置成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '设置失败';
|
||
}
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//配送记录
|
||
public function deliveryrecord()
|
||
{
|
||
$this->display();
|
||
}
|
||
|
||
//订单类型不同统计数据不同
|
||
public function getMerDeliveryTotal()
|
||
{
|
||
$DaDaClass = new DaDa();
|
||
$param = I('post.');
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
$this->ajaxReturn($DaDaClass->getDdDeliveryTotal($param));
|
||
}
|
||
|
||
//配送记录
|
||
public function getMerDeliveryList()
|
||
{
|
||
$DaDaClass = new DaDa();
|
||
$param = I('post.');
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
$this->ajaxReturn($DaDaClass->getDdDeliveryList($param));
|
||
}
|
||
|
||
//导出
|
||
public function merExport()
|
||
{
|
||
$DaDaClass = new DaDa();
|
||
$param = I('get.');
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
$param['is_export'] = 1;
|
||
$result = $DaDaClass->getDdDeliveryList($param);
|
||
|
||
$filename = "配送记录";
|
||
$arr = [
|
||
['index', '序号'],
|
||
['order_no', '门店订单号'],
|
||
['client_id', '达达订单号'],
|
||
['store_name', '门店名称'],
|
||
['add_time', '添加时间'],
|
||
['dm_name', '配送员姓名'],
|
||
['dm_mobile', '配送员手机号'],
|
||
['distance', '配送距离(米)'],
|
||
['fee', '实际配送费'],
|
||
['deliver_fee', '配送费'],
|
||
['order_status', '状态'],
|
||
['cancel_reason', '商家取消订单原因'],
|
||
['deduct_fee', '违约金'],
|
||
['order_type', '订单类型'],
|
||
['update_time', '操作时间'],
|
||
];
|
||
$str = "导出时间" . date('Y-m-d H:i:s', time());
|
||
getExcel($filename, $arr, $result['data']['list'], $str);
|
||
}
|
||
|
||
//门店订单类型不同统计数据不同
|
||
public function getStoreDeliveryTotal()
|
||
{
|
||
$DaDaClass = new DaDa();
|
||
$param = I('post.');
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
$param['store_id'] = $this->store_id;
|
||
$this->ajaxReturn($DaDaClass->getDdDeliveryTotal($param));
|
||
}
|
||
|
||
public function storerecord()
|
||
{
|
||
$this->display();
|
||
}
|
||
|
||
public function getStoreDeliveryList()
|
||
{
|
||
$DaDaClass = new DaDa();
|
||
$param = I('post.');
|
||
$param['store_id'] = $this->store_id;
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
$this->ajaxReturn($DaDaClass->getDdDeliveryList($param));
|
||
}
|
||
|
||
//门店配送记录
|
||
public function storeExport()
|
||
{
|
||
$DaDaClass = new DaDa();
|
||
$param = I('get.');
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
$param['store_id'] = $this->store_id;
|
||
$param['is_export'] = 1;
|
||
|
||
$result = $DaDaClass->getDdDeliveryList($param);
|
||
$filename = "达达配送记录";
|
||
$arr = [
|
||
['index', '序号'],
|
||
['order_no', '门店订单号'],
|
||
['client_id', '达达订单号'],
|
||
['store_name', '门店名称'],
|
||
['add_time', '添加时间'],
|
||
['dm_name', '配送员姓名'],
|
||
['dm_mobile', '配送员手机号'],
|
||
['distance', '配送距离(米)'],
|
||
['fee', '实际配送费'],
|
||
['deliver_fee', '配送费'],
|
||
['order_status', '状态'],
|
||
['cancel_reason', '商家取消订单原因'],
|
||
['deduct_fee', '违约金'],
|
||
['order_type', '订单类型'],
|
||
['update_time', '操作时间'],
|
||
];
|
||
$str = "导出时间" . date('Y-m-d H:i:s', time());
|
||
getExcel($filename, $arr, $result['data']['list'], $str);
|
||
}
|
||
|
||
}
|