<?php namespace Phpcmf\Model\Store;
class Order extends \Phpcmf\Model
{
private $zk;
public function my_cart_items($ids) {
return $this->db->table(SITE_ID.'_store_cart')->whereIn('id', $ids)->where('uid', $this->uid)->get()->getResultArray();
}
public function my_order_cart_items($cid) {
return $this->db->table(SITE_ID.'_store_order_cart')->where('cid', $cid)->where('uid', $this->uid)->get()->getRowArray();
}
public function my_order_cart_info($id) {
return $this->db->table(SITE_ID.'_store_order_cart')->where('id', $id)->where('uid', $this->uid)->get()->getRowArray();
}
public function delete_order_cart($id) {
$this->db->table(SITE_ID.'_store_order_cart')->where('id', $id)->delete();
}
public function add_my_order_cart($cid) {
return $this->table_site('store_order_cart')->insert([
'uid' => $this->uid,
'cid' => $cid,
]);
}
public function item($id) {
$data = $this->table_site('store_order_goods')->where('id', $id)->getRow();
if (!$data) {
return [];
}
$data['yuan'] = floatval($data['yuan']);
$data['p_info'] = $data['promotion_info'];
$data['p_name'] = $data['promotion_name'];
$data['content'] = dr_string2array($data['content']);
return $data;
}
public function goods($id) {
$data = $this->table_site('store_order_goods')->where('oid', $id)->getAll();
if (!$data) {
return [];
}
foreach ($data as $i => $t) {
$data[$i]['yuan'] = floatval($t['yuan']);
$data[$i]['p_info'] = $t['promotion_info'];
$data[$i]['p_name'] = $t['promotion_name'];
$data[$i]['content'] = dr_string2array($t['content']);
}
return $data;
}
public function service($id) {
$data = $this->table_site('store_order_service')->where('cid', $id)->getRow();
if (!$data) {
return [];
}
$data['images'] = dr_string2array($data['images']);
$data['system'] = dr_string2array($data['system']);
$data['myinfo'] = dr_string2array($data['myinfo']);
return $data;
}
public function service_id($id) {
$data = $this->table_site('store_order_service')->where('id', $id)->getRow();
if (!$data) {
return [];
}
$data['images'] = dr_string2array($data['images']);
$data['system'] = dr_string2array($data['system']);
$data['myinfo'] = dr_string2array($data['myinfo']);
return $data;
}
public function post_service($item, $data) {
$data['images'] = dr_array2string($data['images']);
$data['oid'] = $item['oid'];
$data['uid'] = $item['uid'];
$data['username'] = $this->member['username'];
$data['cid'] = $item['id'];
$data['title'] = $item['title'];
$data['thumb'] = $item['thumb'];
$data['url'] = $item['url'];
$data['money'] = 0;
$data['status'] = 1;
$data['system'] = '';
$data['myinfo'] = '';
$data['inputtime'] = SYS_TIME;
$rt = $this->table_site('store_order_service')->insert($data);
if (!$rt['code']) {
return $rt;
}
\Phpcmf\Service::M('member')->admin_notice(SITE_ID, 'pay', $this->member, dr_lang('提交订单售后申请'), 'store/service/edit:id/'.$rt['code'], SITE_ID);
return $rt;
}
public function checkout($data, $goods, $cart) {
if (!$this->uid) {
return dr_return_data(0, dr_lang('你未登录'));
}
$order = [
'sn' => $data['sn'],
'uid' => $this->member['uid'],
'username' => $this->member['username'],
'money' => $data['money'], 'freight' => $data['freight'], 'discount' => abs($data['discount']), 'coupon' => (int)$data['coupon'], 'give_score' => $data['give_score'], 'give_money' => $data['give_money'],
'source' => $data['source'],
'name' => $data['name'],
'email' => $this->member['email'],
'phone' => $data['phone'],
'address' => $data['address'],
'pay_id' => 0, 'pay_time' => 0, 'pay_type' => $data['pay_type'], 'pay_status' => 0,
'deliver_id' => 0, 'deliver_time' => 0, 'deliver_status' => 0,
'receipt_time' => 0,
'comment' => 0, 'comment_time' => 0,
'promotion_name' => $data['promotion_name'], 'promotion_info' => $data['promotion_info'],
'remark' => $data['remark'], 'status' => 1, 'inputtime' => SYS_TIME,
];
$rt = $this->table_site('store_order')->insert($order);
if (!$rt['code']) {
return $rt;
}
$order['id'] = $rt['code'];
foreach ($goods as $t) {
$content = $t['data'];
if (isset($t['data']['tableid'])) {
$data2 = $this->table($t['table'].'_data_'.$t['data']['tableid'])->get($t['data']['id']);
$data2 && $content = $content + $data2;
}
$content['thumb'] = dr_get_file($t['thumb']);
$rt = $this->table_site('store_order_goods')->insert([
'uid' => $this->uid,
'oid' => $order['id'],
'mid' => $t['mid'],
'num' => $t['num'],
'price' => $t['price'],
'total' => $t['total'],
'yuan' => $t['yuan'],
'promotion_name' => $t['p_name'],
'promotion_info' => $t['p_info'],
'sn' => (string)$t['sn'],
'sku_name' => dr_array2string($t['sku_name']),
'sku_value' => $t['sku_value'],
'title' => $t['title'],
'thumb' => $content['thumb'],
'url' => $t['url'],
'status' => 0,
'table' => $t['table'],
'content' => dr_array2string($content),
]);
if (!$rt['code']) {
$this->db->table(SITE_ID.'_store_order')->where('id', $order['id'])->delete();
$this->db->table(SITE_ID.'_store_order_goods')->where('oid', $order['id'])->delete();
return $rt;
}
}
if ($cart) {
$cart['cid'] && $this->table(SITE_ID.'_store_cart')->delete(0, 'id IN ('. $cart['cid'].')');
$this->db->table(SITE_ID.'_store_order_cart')->where('id', (int)$cart['id'])->delete();
}
$this->add_log($order, dr_lang('创建订单成功'));
\Phpcmf\Service::L('Notice')->send_notice('store_status_1', $order);
return dr_return_data($order['id'], 'ok');
}
public function comment($mid, $id) {
$data = $this->table_site('store_comment')->where('orderid', $id)->getAll();
if (!$data) {
return [];
}
$rt = [];
foreach ($data as $i => $t) {
$t['image'] = dr_string2array($t['image']);
$rt[$t['cid']] = $t;
}
return $rt;
}
public function call_comment($call) {
if (!$call) {
return;
}
foreach ($call as $t) {
if ($t['mid']) {
$this->db->table(SITE_ID.'_store_comment')->where('id', (int)$t['eid'])->delete();
$this->db->table(SITE_ID.'_store_comment_index')->where('id', (int)$t['eid'])->delete();
}
}
}
public function save_comment($id) {
$this->table_site('store_order')->update($id, [
'comment' => 1,
'comment_time' => SYS_TIME,
]);
}
public function info($id) {
$order = $this->table_site('store_order')->get($id);
return $order;
}
public function add_log($order, $log) {
$this->table_site('store_order_log')->insert([
'oid' => (int)$order['id'],
'uid' => (int)$this->uid,
'username' => (string)$this->member['username'],
'log' => (string)$log,
'status' => (int)$order['status'],
'pay_status' => (int)$order['pay_status'],
'deliver_status' => (int)$order['deliver_status'],
'inputtime' => SYS_TIME
]);
}
public function log($id) {
return $this->table_site('store_order_log')->where('oid', $id)->getAll();
}
public function get_delivery_corp() {
$value = $this->table(SITE_ID.'_store_delivery_corp')->where('disabled', 0)->order_by('displayorder asc,id desc')->getAll();
if (!$value) {
return [];
}
$data = [];
foreach ($value as $t) {
$data[$t['id']] = $t;
}
return $data;
}
public function deliver_info($id) {
if (!$id) {
return [];
}
$sql = 'select a.*,b.code as deliver_code,b.url as deliver_url from `'.$this->dbprefix(SITE_ID.'_store_order_deliver_goods').'` as a left join `'.$this->dbprefix(SITE_ID.'_store_delivery_corp').'` as b on a.deliver_id=b.id where a.`id`='.$id;
return $this->db->query($sql)->getRowArray();
}
public function service_deliver_info($id) {
if (!$id) {
return [];
}
$sql = 'select b.name as deliver_name,b.code as deliver_code,b.url as deliver_url from `'.$this->dbprefix(SITE_ID.'_store_delivery_corp').'` as b where b.`id`='.$id;
return $this->db->query($sql)->getRowArray();
}
public function add_deliver_goods($tid, $order, $data) {
$save = [
'tid' => (int)$tid,
'oid' => $order['id'],
'sn' => $order['sn'],
'uid' => $order['uid'],
'username' => $order['username'],
'name' => $data['name'],
'phone' => $data['phone'],
'address' => $data['address'],
'note' => $data['note'],
'deliver_id' => (int)$data['id'],
'deliver_sn' => $data['sn'],
'deliver_name' => $data['deliver_name'],
'admin_uid' => $this->uid,
'admin_username' => $this->member['username'],
'inputtime' => SYS_TIME
];
$rt = $this->table_site('store_order_deliver_goods')->insert($save);
if (!$rt['code']) {
return $rt;
}
$save['id'] = $rt['code'];
$rt = $this->delivery($order, $save);
if ($rt && !$rt['code']) {
$this->table_site('store_order_deliver_goods')->delete($save['id']);
return $rt;
}
return dr_return_data($save['id'], 'ok');
}
public function get_goods_info($id, $field, $num, $sku) {
$rt = \Phpcmf\Service::M('Pay')->get_pay_info($id, $field, $num, $sku);
if (isset($rt['code']) && !$rt['code']) {
return dr_return_data(0, $rt['msg']);
}
$rt['yuan'] = '';
$rt['p_name'] = '';
$rt['p_info'] = '';
$rt['give_money'] = 0;
$rt['give_score'] = 0;
list($table, $cid) = explode('-', $rt['mid']);
if ($table == SITE_ID.'_store') {
$p = $this->get_goods_discount($cid, $rt['price'], \Phpcmf\Service::C()->member);
if ($p['promotion']) {
$rt['yuan'] = $rt['price'];
$rt['price'] = $p['price'];
$rt['p_name'] = $p['promotion']['title'];
$rt['p_info'] = $p['info'];
$rt['total'] = $rt['price'] * $rt['num'];
$rt['give_money'] = $p['promotion']['type'] == 4 ? $p['promotion']['value'] : 0;
$rt['give_score'] = $p['promotion']['type'] == 5 ? $p['promotion']['value'] : 0;
}
}
$rt['total'] = max(0, $rt['total']);
return $rt;
}
public function get_tuan_goods_info($id, $field, $num, $sku, $tuan) {
}
public function get_goods_discount($cid, $price, $member) {
if (floatval($price) == 0) {
return [];
}
if (!isset($this->zk[$cid]) || !$this->zk[$cid]) {
$this->zk[$cid] = $this->table(SITE_ID.'_store_goods_promotion')->where('status=1 and stime < '.SYS_TIME.' and etime > '.SYS_TIME.' and id IN (select pid from `'.$this->dbprefix(SITE_ID).'_store_goods_promotion_item` where cid='.$cid.')')->getAll();
}
if (!$this->zk[$cid]) {
return [];
}
foreach ($this->zk[$cid] as $p) {
if (!$p['member']) {
break;
} elseif (array_intersect($p['member'], $member['groupid'])) {
break;
} elseif ($p['member'] && !$member) {
return [
'price' => $price,
'info' => dr_lang('登录查看优惠价格'),
'promotion' => $p
];
}
}
if (!$p) {
return [];
}
$value = floatval($p['value']);
switch ($p['type']) {
case '1':
$price = $price * ($value/100);
$info = dr_lang('折扣价¥%s元', number_format($price, 2));
break;
case '2':
$price = max(0, $price - $value);
$info = dr_lang('减价到¥%s元', number_format($value, 2));
break;
case '3':
$info = dr_lang('特价¥%s元', number_format($value, 2));
break;
case '4':
$info = dr_lang('返现金¥%s元', number_format($value, 2));
break;
case '5':
$info = dr_lang('返%s%s', SITE_SCORE, $value);
break;
default:
return [
'price' => $price,
'info' => dr_lang('无优惠'),
'promotion' => $p
];
break;
}
return [
'price' => $price,
'info' => $info,
'promotion' => $p
];
}
public function xgs($mid, $xgs) {
if (!$xgs) {
return 0;
}
$counts = $this->table(SITE_ID.'_store_order_goods')->where('mid', $mid)->counts();
if ($counts > $xgs) {
return 1;
}
return 0;
}
public function get_order_discount($price, $member) {
$rows = $this->table(SITE_ID.'_store_order_promotion')->where('status=1 and money< '.floatval($price).' and stime < '.SYS_TIME.' and etime > '.SYS_TIME.'')->getAll();
if (!$rows) {
return [];
}
foreach ($rows as $t) {
if (!$t['member']) {
break;
} elseif (array_intersect($t['member'], $member['groupid'])) {
break;
}
}
if (!$t) {
return [];
}
$value = floatval($t['value']);
$t['jian'] = 0;
switch ($t['type']) {
case '1':
$t['jian'] = $price - $price * ($value/100);
$info = dr_lang('优惠 ¥%s元', number_format($t['jian'], 2));
break;
case '2':
$t['jian'] = $value;
$info = dr_lang('减价¥%s元', number_format($value, 2));
break;
case '4':
$info = dr_lang('返现金¥%s元', number_format($value, 2));
break;
case '5':
$info = dr_lang('返%s%s', SITE_SCORE, $value);
break;
default:
return [];
break;
}
$t['info'] = $info;
$t['price'] = $price;
return $t;
}
public function get_shipping_info($shipping, $city) {
$free = dr_string2array($shipping['free']); #包邮策略
$freight = dr_string2array($shipping['freight']); #运费策略
unset($shipping['free'], $shipping['freight']);
$info = dr_linkage(FC_ADDRESS_CITY, $city);
if (!$info) {
log_message('error', '无法计算运费:城市ID:'.$city.'不存在('.FC_NOW_URL.')');
return [[], []];
}
$city = explode(',', $info['pids'].','.$info['ii']);
if (!$city[0]) {
unset($city[0]);
}
$free_value = $value = $default = [];
if ($free) {
foreach ($free as $t) {
if ($t['city']) {
if (in_array($t['city'], $city)) {
$value = $t;
break;
}
} else {
$default = $t;
}
}
$free_value = $value ? $value : $default;
if ($free_value) {
$free_value['value'] = $free_value[$free_value['type']];
unset($free_value[1], $free_value[2], $free_value[3]);
}
}
$value = [];
$default = $freight['default'];
unset($freight['default']);
if ($freight) {
foreach ($freight as $t) {
if ($t['city']) {
if (in_array($t['city'], $city)) {
$value = $t;
break;
}
} else {
$default = $t;
}
}
}
$freight_value = $value ? $value : $default;
return [$free_value, $freight_value];
}
public function get_freight_price($city, $goods) {
if (!$city) {
return 0;
} else if (!\Phpcmf\Service::C()->mall_info['shipping']) {
return 0;
}
$price = 0;
foreach ($goods as $t) {
if (!$t['data']['shipping'] || !\Phpcmf\Service::C()->mall_info['shipping'][$t['data']['shipping']]) {
log_message('error', '无法计算运费:城市ID:'.$city.'不存在('.FC_NOW_URL.')');
continue;
}
$yunfei = 0;
$shipping_param = dr_string2array($t['data']['shipping_param']);
if (!isset($shipping_param['value']) || !$shipping_param['value']) {
log_message('error', '无法计算运费:没有设置商品运输参数('.FC_NOW_URL.')');
continue;
}
list($free, $freight) = $this->get_shipping_info(\Phpcmf\Service::C()->mall_info['shipping'][$t['data']['shipping']], $city);
if ($freight['start']) {
switch ($shipping_param['param']) {
case 1: $yunfei+= $freight['postage'];
$t['num'] > $freight['start'] && $yunfei+= floor(($t['num'] - $freight['start']) / $freight['plus']) * $freight['postageplus'];
if ($free) {
switch ($free['type']) {
case 1:
$t['num'] >= $free['value'] && $yunfei = 0;
break;
case 2:
$t['total'] - $free['value'] >= 0 && $yunfei = 0;
break;
case 3:
$t['num'] >= $free['value']['dw'] && $t['total'] - $free['value']['price'] >= 0 && $yunfei = 0;
break;
}
}
break;
case 2: $yunfei+= $freight['postage'];
$v = $t['num'] * $shipping_param['value']; $v > $freight['start'] && $yunfei+= floor(($v - $freight['start']) / $freight['plus']) * $freight['postageplus'];
if ($free) {
switch ($free['type']) {
case 1:
$v >= $free['value'] && $yunfei = 0;
break;
case 2:
$t['total'] - $free['value'] >= 0 && $yunfei = 0;
break;
case 3:
$v >= $free['value']['dw'] && $t['total'] - $free['value']['price'] >= 0 && $yunfei = 0;
break;
}
}
break;
case 3: $yunfei+= $freight['postage'];
$v = $t['num'] * $shipping_param['value']; $v > $freight['start'] && $yunfei+= floor(($v - $freight['start']) / $freight['plus']) * $freight['postageplus'];
if ($free) {
switch ($free['type']) {
case 1:
$v >= $free['value'] && $yunfei = 0;
break;
case 2:
$t['total'] - $free['value'] >= 0 && $yunfei = 0;
break;
case 3:
$v >= $free['value']['dw'] && $t['total'] - $free['value']['price'] >= 0 && $yunfei = 0;
break;
}
}
break;
}
}
$price+= $yunfei;
}
return $price;
}
public function pay($id, $pay_id, $pay_type = '') {
if (!$id) {
log_message('error', '订单付款回调失败:id值不存在('.FC_NOW_URL.')');
return;
}
$order = $this->table_site('store_order')->get($id);
if (!$order) {
log_message('error', '订单付款回调失败:订单('.$id.')不存在('.FC_NOW_URL.')');
return;
}
$order['pay_id'] = $pay_id;
$order['pay_time'] = SYS_TIME;
$order['pay_status'] = 1;
$order['pay_type'] = $pay_type ? $pay_type : $order['pay_type'];
$order['status'] = 2;
$rt = $this->table_site('store_order')->update($id, [
'pay_id' => $order['pay_id'],
'pay_type' => $order['pay_type'],
'pay_time' => $order['pay_time'],
'pay_status' => $order['pay_status'],
'status' => $order['status'],
]);
if (!$rt['code']) {
log_message('error', '订单('.$id.')付款回调失败:'.$rt['msg'].'('.FC_NOW_URL.')');
return;
}
$goods = $this->table_site('store_order_goods')->where('oid', $id)->getAll();
if (!$goods) {
log_message('error', '订单('.$id.')库存计算失败:没有找到订单对应的商品('.FC_NOW_URL.')');
} else {
foreach ($goods as $t) {
list($m, $table, $cid) = explode('-', $t['mid']);
$data = $this->table($table)->get($cid);
if ($data) {
$update = [];
if ($t['sku_value']) {
$data['price_sku'] = dr_string2array($data['price_sku']);
if (!isset($data['price_sku']['value'][$t['sku_value']]) || !$data['price_sku']['value'][$t['sku_value']]) {
log_message('error', '订单('.$id.')库存计算失败:sku信息查询失败('.FC_NOW_URL.')');
} else {
$data['price_sku']['value'][$t['sku_value']]['quantity'] = max(0, $data['price_sku']['value'][$t['sku_value']]['quantity'] - $t['num']);
$update = [
'price_sku' => dr_array2string($data['price_sku']),
'price_quantity' => max($data['price_quantity'] - $t['num'], 0),
];
}
}
!$update && $update = [
'price_quantity' => max($data['price_quantity'] - $t['num'], 0),
];
isset($data['volume']) && $update['volume'] = (int)$data['volume'] + $t['num'];
$this->db->table($table)->where('id', $cid)->update($update);
}
}
}
$this->add_log($order, dr_lang('付款成功'));
\Phpcmf\Service::L('Notice')->send_notice('store_status_2', $order);
switch ((int)\Phpcmf\Service::C()->mall_info['order']['buy_step']) {
case 1:
$this->delivery($order, '付款后自动发货');
break;
case 3:
$this->receipt($order, '付款后自动完成订单');
break;
}
return dr_return_data($order['id'], 'ok');
}
public function delivery($order, $info) {
$order['deliver_id'] = $info['id'];
$order['deliver_time'] = SYS_TIME;
$order['deliver_status'] = 1;
$rt = $this->table_site('store_order')->update($order['id'], [
'deliver_id' => $order['deliver_id'],
'deliver_time' => $order['deliver_time'],
'deliver_status' => $order['deliver_status'],
]);
if (!$rt['code']) {
return $rt;
}
$this->add_log($order, $info['note']);
\Phpcmf\Service::L('Notice')->send_notice('store_deliver_status_1', $order);
if ((int)\Phpcmf\Service::C()->mall_info['order']['buy_step'] == 2) {
$this->receipt($order, '发货后自动完成订单');
}
return dr_return_data($order['id'], 'ok');
}
public function receipt($order, $note) {
$order['status'] = 9; $order['deliver_status'] = 2;
$order['receipt_time'] = SYS_TIME;
$rt = $this->table_site('store_order')->update($order['id'], [
'status' => $order['status'],
'deliver_status' => $order['deliver_status'],
'receipt_time' => $order['receipt_time'],
]);
if (!$rt['code']) {
return $rt;
}
$this->db->table(SITE_ID.'_store_order_goods')->where('oid', $order['id'])->update([
'status' => 1,
]);
if ($order['give_score'] > 0) {
\Phpcmf\Service::M('member')->add_score($order['uid'], $order['give_score'], dr_lang('订单['.$order['sn'].']赠送'));
}
if ($order['give_money'] > 0) {
$rt = \Phpcmf\Service::M('Pay')->add_money($order['uid'], $order['give_money']);
$rt = \Phpcmf\Service::M('Pay')->add_paylog([
'uid' => $order['uid'],
'username' => $order['username'],
'touid' => '0',
'tousername' => '',
'mid' => 'order',
'title' => dr_lang('订单['.$order['sn'].']返现'),
'value' => $order['give_money'],
'type' => 'system',
'status' => 1,
'result' => '订单编号:'.$order['sn'],
'paytime' => SYS_TIME,
'inputtime' => SYS_TIME,
]);
}
$this->add_log($order, $note);
\Phpcmf\Service::L('Notice')->send_notice('store_status_9', $order);
return dr_return_data($order['id'], 'ok');
}
public function close($order, $note) {
if ($order['status'] == 0) {
return dr_return_data(0, dr_lang('订单已经关闭')); }
$rt = $this->table_site('store_order')->update($order['id'], [
'status' => 0,
'pay_status' => $order['pay_status'] == 1 ? 2 : $order['pay_status'],
]);
if (!$rt['code']) {
return $rt;
}
$order['status'] = 0;
$this->add_log($order, $note);
\Phpcmf\Service::L('Notice')->send_notice('store_status_0', $order);
if ($order['money'] > 0 && $order['pay_status'] == 1) {
$rt = $this->query('update `'.$this->dbprefix('member').'` set `money`=`money`+'.$order['money'].',`freeze`=`spend`-'.$order['money'].' where id='.$order['uid']);
if ($rt['code']) {
\Phpcmf\Service::M('pay')->add_paylog([
'mid' => 'order',
'uid' => $order['uid'],
'username' => $order['username'],
'touid' => 0,
'tousername' => '',
'title' => '订单退款',
'value' => $order['money'],
'type' => 'finecms',
'url' => dr_member_url('order/home/show', ['id' => $order['id']]),
'status' => 1,
'result' => '订单号:'.$order['sn'],
'paytime' => SYS_TIME,
]);
}
}
return dr_return_data($order['id'], 'ok');
}
public function refund($order, $note) {
if ($order['status'] != 2) {
return dr_return_data(0, dr_lang('订单状态不符合退款'));
} elseif ($order['pay_status'] == 2) {
return dr_return_data(0, dr_lang('订单已经退款'));
}
$rt = $this->table_site('store_order')->update($order['id'], [
'status' => 0,
'pay_status' => 2,
]);
if (!$rt['code']) {
return $rt;
}
if ($order['money'] > 0) {
$rt = $this->query('update `'.$this->dbprefix('member').'` set `money`=`money`+'.$order['money'].',`freeze`=`spend`-'.$order['money'].' where id='.$order['uid']);
if ($rt['code']) {
\Phpcmf\Service::M('pay')->add_paylog([
'mid' => 'order',
'uid' => $order['uid'],
'username' => $order['username'],
'touid' => 0,
'tousername' => '',
'title' => '订单退款',
'value' => $order['money'],
'type' => 'finecms',
'url' => dr_member_url('order/home/show', ['id' => $order['id']]),
'status' => 1,
'result' => '订单号:'.$order['sn'],
'paytime' => SYS_TIME,
]);
}
}
$this->add_log($order, $note);
return dr_return_data($order['id'], 'ok');
}
public function cache($site = SITE_ID) {
if (!\Phpcmf\Service::M()->db->tableExists(\Phpcmf\Service::M()->prefix.$site.'_store')) {
return;
}
$table = \Phpcmf\Service::M()->prefix.$site.'_store_comment';
if (\Phpcmf\Service::M()->db->tableExists($table)) {
if (!\Phpcmf\Service::M()->db->fieldExists('image', $table)) {
\Phpcmf\Service::M()->query('ALTER TABLE `'.$table.'` ADD `image` TEXT NULL;');
}
}
$data = $this->table($site.'_store_config')->getAll();
$cache = [];
if ($data) {
foreach ($data as $t) {
$value = dr_string2array($t['value']);
if ($t['name'] == 'config' && $value) {
foreach ($value as $i => $a) {
$cache[$i] = $a;
}
} else {
$cache [$t['name']] = $value;
}
$t['name'] == 'order' && $cache[$t['name']] = $value;
}
}
$data = $this->table($site.'_store_shipping')->getAll();
$cache['shipping'] = [];
if ($data) {
foreach ($data as $t) {
$t['free'] = dr_string2array($t['free']);
$t['freight'] = dr_string2array($t['freight']);
$cache['shipping'][$t['id']] = $t;
}
}
\Phpcmf\Service::L('cache')->set_file('mall-'.$site, $cache);
}
}