@@ -0,0 +1,232 @@ | |||
<?php | |||
/** | |||
* 全局通用方法集合 | |||
* ============================================================================ | |||
* * 版权所有 蜘蛛出行 * * | |||
* 网站地址: http://www.zhizhuchuxing.com | |||
* ---------------------------------------------------------------------------- | |||
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和 | |||
* 使用;不允许对程序代码以任何形式任何目的的再发布。 | |||
* ============================================================================ | |||
* Author By: 倪宗锋 | |||
* PhpStorm Util.php | |||
* Create By 2017/2/22 19:44 $ | |||
*/ | |||
namespace app\admin\command; | |||
use common\models\AdmUser; | |||
use common\models\FxUser; | |||
use common\models\LogUserOperation; | |||
use common\models\OrderMain; | |||
use common\models\ProdCategory; | |||
use common\models\ShUser; | |||
use yii\base\Exception; | |||
class Util | |||
{ | |||
/** | |||
* Function Description:返回成功数组数据 | |||
* Function Name: returnArrSu | |||
* @param string $msg 提示信息 | |||
* @param string $url 跳转地址 | |||
* @param string|array $data 需要传递的数据 | |||
* @param string $code 错误码 | |||
* | |||
* @return array | |||
* | |||
* @author 倪宗锋 | |||
*/ | |||
public static function returnArrSu($msg = '', $data = '', $url = '', $code = '') | |||
{ | |||
$return = array(); | |||
$return['flag'] = true; | |||
$return['msg'] = $msg; | |||
$return['url'] = $url; | |||
$return['code'] = $code; | |||
$return['data'] = $data; | |||
return $return; | |||
} | |||
/** | |||
* Function Description:返回错误数组数据 | |||
* Function Name: returnArrEr | |||
* @param string $msg 提示信息 | |||
* @param string $url 跳转地址 | |||
* @param string|array $data 需要传递的数据 | |||
* @param string $code 错误码 | |||
* | |||
* @return array | |||
* | |||
* @author 倪宗锋 | |||
*/ | |||
public static function returnArrEr($msg = '', $data = '', $url = '', $code = '') | |||
{ | |||
$return = array(); | |||
$return['flag'] = false; | |||
$return['msg'] = $msg; | |||
$return['url'] = $url; | |||
$return['code'] = $code; | |||
$return['data'] = $data; | |||
return $return; | |||
} | |||
/** | |||
* Function Description:json转换为xml | |||
* Function Name: jsonToXml | |||
* @param $json | |||
* | |||
* @return bool|string | |||
* | |||
* @author 倪宗锋 | |||
*/ | |||
public static function jsonToXml($json) | |||
{ | |||
if (empty($json)) { | |||
return false; | |||
} | |||
$array = json_decode($json); | |||
$xml = ''; | |||
$xml .= '<?xml version="1.0" encoding="UTF-8"?>' . self::arraysToXml(['response' => $array]); | |||
return $xml; | |||
} | |||
/** | |||
* Function Description:数组转换成xml | |||
* Function Name: arrayToXml | |||
* @param $array | |||
* @param $key | |||
* @return string | |||
* | |||
* @author 倪宗锋 | |||
*/ | |||
public static function arraysToXml($array, $key = '') | |||
{ | |||
$string = ''; | |||
if (count($array) == 0) { | |||
return ''; | |||
} | |||
foreach ($array as $k => $v) { | |||
if (is_array($v) && isset($v['0'])) { | |||
$string .= self::arraysToXml($v, $k);//是数组或者对像就的递归调用 | |||
} else { | |||
if ($key != '') { | |||
$k = $key; | |||
} | |||
$string .= '<' . $k . '>'; | |||
if (is_array($v) || is_object($v)) {//判断是否是数组,或者,对像 | |||
$string .= self::arraysToXml($v);//是数组或者对像就的递归调用 | |||
} elseif (is_numeric($v)) { | |||
$string .= $v; | |||
} elseif ($v != '') { | |||
$string .= '<![CDATA[' . $v . ']]>'; | |||
} else { | |||
$string .= ''; | |||
} | |||
$string .= '</' . $k . '>'; | |||
} | |||
} | |||
return $string; | |||
} | |||
/** | |||
* Function Description:xml转换为json | |||
* Function Name: xml_to_json | |||
* @param $source | |||
* | |||
* @return string | |||
* | |||
* @author 倪宗锋 | |||
*/ | |||
public static function xmlToJson($source) | |||
{ | |||
if (is_file($source)) { //传的是文件,还是xml的string的判断 | |||
$xml_array = simplexml_load_file($source); | |||
} else { | |||
$xml_array = simplexml_load_string(trim($source)); | |||
} | |||
$json = json_encode($xml_array, true); | |||
return $json; | |||
} | |||
/** | |||
* Function Description:xml转换成数组 | |||
* Function Name: xmlToArray | |||
* @param $source | |||
* | |||
* @return mixed | |||
* | |||
* @author 倪宗锋 | |||
*/ | |||
public static function xmlToArray($source) | |||
{ | |||
libxml_disable_entity_loader(true); | |||
$getResult = json_decode(json_encode(simplexml_load_string(trim($source), 'SimpleXMLElement', LIBXML_NOCDATA)), true); | |||
return $getResult; | |||
} | |||
/** Function Description:加密解密函数 | |||
* Function Name: authCode | |||
* @param $string | |||
* @param string $operation | |||
* @param int $expiry | |||
* @return string|array | |||
* @author 倪宗锋 | |||
*/ | |||
static function authCode($string, $operation = 'DECODE', $expiry = 0) | |||
{ | |||
$key = 'udM5A8S50eg8veH15dd0m601de7073N8Bcn7d1I8Res7C7o7z274D6y342I4C7t7'; | |||
$ckey_length = 4; // 随机密钥长度 取值 0-32; | |||
// 加入随机密钥,可以令密文无任何规律,即便是原文和密钥完全相同,加密结果也会每次不同,增大破解难度。 | |||
// 取值越大,密文变动规律越大,密文变化 = 16 的 $ckey_length 次方 | |||
// 当此值为 0 时,则不产生随机密钥 | |||
$key = md5($key); | |||
$keya = md5(substr($key, 0, 16)); | |||
$keyb = md5(substr($key, 16, 16)); | |||
$keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length)) : ''; | |||
$cryptkey = $keya . md5($keya . $keyc); | |||
$key_length = strlen($cryptkey); | |||
$string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $keyb), 0, 16) . $string; | |||
$string_length = strlen($string); | |||
$result = ''; | |||
$box = range(0, 255); | |||
$rndkey = array(); | |||
for ($i = 0; $i <= 255; $i++) { | |||
$rndkey[$i] = ord($cryptkey[$i % $key_length]); | |||
} | |||
for ($j = $i = 0; $i < 256; $i++) { | |||
$j = ($j + $box[$i] + $rndkey[$i]) % 256; | |||
$tmp = $box[$i]; | |||
$box[$i] = $box[$j]; | |||
$box[$j] = $tmp; | |||
} | |||
for ($a = $j = $i = 0; $i < $string_length; $i++) { | |||
$a = ($a + 1) % 256; | |||
$j = ($j + $box[$a]) % 256; | |||
$tmp = $box[$a]; | |||
$box[$a] = $box[$j]; | |||
$box[$j] = $tmp; | |||
$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256])); | |||
} | |||
if ($operation == 'DECODE') { | |||
if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) { | |||
return substr($result, 26); | |||
} else { | |||
return ''; | |||
} | |||
} else { | |||
return $keyc . str_replace('=', '', base64_encode($result)); | |||
} | |||
} | |||
} |
@@ -0,0 +1,155 @@ | |||
<?php | |||
/** | |||
* Created by PhpStorm. | |||
* User: nizongfeng | |||
* Date: 2021/10/27 | |||
* Time: 13:36 | |||
*/ | |||
namespace app\admin\service; | |||
use app\admin\command\Util; | |||
use app\admin\model\CfRoomInfo; | |||
use app\admin\model\OrderHotel; | |||
use app\admin\model\Purchase; | |||
use think\Exception; | |||
class OrderHotelDao | |||
{ | |||
/** | |||
* 添加失败 | |||
* @param $param | |||
* @param $orderId | |||
* @return array|string | |||
*/ | |||
public function addInfo($param, $orderId) | |||
{ | |||
$hotelInfo = $this->getHotelInfo($param['hotel_id']); | |||
if (!$hotelInfo['flag']){ | |||
return $hotelInfo; | |||
} | |||
$roomInfo = $this->getRoomInfo($param['room_id']); | |||
if (!$roomInfo['flag']){ | |||
return $roomInfo; | |||
} | |||
$roomPlan = $this->getRoomPlan($param['plan_id']); | |||
if (!$roomPlan['flag']) { | |||
return $roomPlan; | |||
} | |||
//设置入参 | |||
$data = [ | |||
"order_id" => $orderId, | |||
"hotel_id" => $param['hotel_id'], | |||
"hotel_name" => $hotelInfo['data']['hotel_name'], | |||
"hotel_phone" => $hotelInfo['data']['hotel_phone'], | |||
"country_name" => $hotelInfo['data']['country_name'], | |||
"province_name" => $hotelInfo['data']['province_name'], | |||
"city_name" => $hotelInfo['data']['city_name'], | |||
"detail_address" => $hotelInfo['data']['detail_address'], | |||
//房型 | |||
"room_id" => $param['data']['room_id'], | |||
"room_name" => $roomInfo['data']['room_name'], | |||
"room_memo" => $roomInfo['data']['room_memo'], | |||
//价格方案 | |||
"plan_id" => $param['data']['plan_id'], | |||
"plan_name" => $roomPlan['data']['plan_name'], | |||
"plan_memo" => $roomPlan['data']['plan_memo'], | |||
//其他 | |||
"check_in_date" => $param['check_in_date'], | |||
"check_out_date" => $param['check_out_date'], | |||
"confirm_status" => $param['confirm_status'], | |||
"confirm_no" => $param['confirm_no'], | |||
"customer_name" => $param['customer_name'], | |||
"customer_comments" => $param['customer_comments'], | |||
"trade_order_number" => $param['trade_order_number'], | |||
"res_person" => $param['res_person'], | |||
"res_person_id" => $param['res_person_id'] | |||
]; | |||
$orderHotelModel = new OrderHotel(); | |||
$id = $orderHotelModel->insertGetId($data); | |||
return Util::returnArrSu($id); | |||
} | |||
/** | |||
* 获取酒店信息 | |||
* @param $id | |||
* @return array | |||
*/ | |||
public function getHotelInfo($id) | |||
{ | |||
try { | |||
$model = new OrderHotel(); | |||
$result = $model->where(["id" => $id])->find(); | |||
if ($result == null) { | |||
return Util::returnArrEr("获取酒店信息失败" . $id); | |||
} | |||
return Util::returnArrSu($result); | |||
} catch (Exception $e) { | |||
return Util::returnArrEr("获取酒店信息失败" . $id); | |||
} | |||
} | |||
/** | |||
* 获取房型详情 | |||
* @param $id | |||
* @return array | |||
*/ | |||
public function getRoomInfo($id) | |||
{ | |||
try { | |||
$model = new CfRoomInfo(); | |||
$result = $model->where(["id" => $id])->find(); | |||
if ($result == null) { | |||
return Util::returnArrEr("获取房型信息失败" . $id); | |||
} | |||
return Util::returnArrSu($result); | |||
} catch (Exception $e) { | |||
return Util::returnArrEr("获取房型信息失败" . $id); | |||
} | |||
} | |||
/** | |||
* 获取房型价格方案 | |||
* @param $id | |||
* @return array | |||
*/ | |||
public function getRoomPlan($id) | |||
{ | |||
try { | |||
$model = new CfRoomInfo(); | |||
$result = $model->where(["id" => $id])->find(); | |||
if ($result == null) { | |||
return Util::returnArrEr("获取价格方案信息失败" . $id); | |||
} | |||
return Util::returnArrSu($result); | |||
} catch (Exception $e) { | |||
return Util::returnArrEr("获取价格方案信息失败" . $id); | |||
} | |||
} | |||
/** | |||
* 设置子订单金额 | |||
* @param int $subOrderId | |||
* @return array | |||
*/ | |||
public static function setSubOrderAmount( int $subOrderId) { | |||
try{ | |||
$purchaseModel = new Purchase(); | |||
$purchaseList = $purchaseModel->where(["order_detail_id"=>$subOrderId,"del_flag"=>0])->select(); | |||
$cost = 0; | |||
$amount = 0; | |||
$count = 0; | |||
foreach ($purchaseList as $purchase) { | |||
$cost += $purchase['total_cost']; | |||
$amount += $purchase['total_price']; | |||
$count += $purchase['count']; | |||
} | |||
OrderHotel::update(["total_price"=>$amount,"total_cost"=>$cost,"count"=>$count])->where(["id"=>$subOrderId]); | |||
return Util::returnArrSu(); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("更新酒店订单子表金额失败".$subOrderId); | |||
} | |||
} | |||
} |
@@ -0,0 +1,107 @@ | |||
<?php | |||
/** | |||
* Created by PhpStorm. | |||
* User: nizongfeng | |||
* Date: 2021/10/27 | |||
* Time: 13:36 | |||
*/ | |||
namespace app\admin\service; | |||
use app\admin\command\Util; | |||
use app\admin\model\CfItem; | |||
use app\admin\model\OrderHotel; | |||
use app\admin\model\OrderItem; | |||
use app\admin\model\Purchase; | |||
use think\Exception; | |||
class OrderHotelDao | |||
{ | |||
/** | |||
* 添加失败 | |||
* @param $param | |||
* @param $orderId | |||
* @return array|string | |||
*/ | |||
public function addInfo($param, $orderId) | |||
{ | |||
$itemInfo = $this->getItemInfo($param['item_id']); | |||
if (!$itemInfo['flag']){ | |||
return $itemInfo; | |||
} | |||
//设置入参 | |||
$data = [ | |||
"order_id" => $orderId, | |||
//附加项目 | |||
"item_id"=>$itemInfo['data']['id'], | |||
"item_type"=>$itemInfo['data']['item_type'], | |||
"item_name"=>$itemInfo['data']['item_name'], | |||
"item_memo"=>$itemInfo['data']['item_memo'], | |||
"item_unit"=>$itemInfo['data']['item_unit'], | |||
"country_name" => $itemInfo['data']['country_name'], | |||
"province_name" => $itemInfo['data']['province_name'], | |||
"city_name" => $itemInfo['data']['city_name'], | |||
"detail_address" => $itemInfo['data']['detail_address'], | |||
//其他 | |||
"check_in_date" => $param['check_in_date'], | |||
"confirm_status" => $param['confirm_status'], | |||
"confirm_no" => $param['confirm_no'], | |||
"customer_name" => $param['customer_name'], | |||
"customer_comments" => $param['customer_comments'], | |||
"trade_order_number" => $param['trade_order_number'], | |||
"res_person" => $param['res_person'], | |||
"res_person_id" => $param['res_person_id'] | |||
]; | |||
$orderHotelModel = new OrderHotel(); | |||
$id = $orderHotelModel->insertGetId($data); | |||
return Util::returnArrSu($id); | |||
} | |||
/** | |||
* 获取附加项目信息 | |||
* @param $id | |||
* @return array | |||
*/ | |||
public function getItemInfo($id) | |||
{ | |||
try { | |||
$model = new CfItem(); | |||
$result = $model->where(["id" => $id])->find(); | |||
if ($result == null) { | |||
return Util::returnArrEr("获取附加项目信息失败" . $id); | |||
} | |||
return Util::returnArrSu($result); | |||
} catch (Exception $e) { | |||
return Util::returnArrEr("获取附加项目信息失败" . $id); | |||
} | |||
} | |||
/** | |||
* 设置子订单金额 | |||
* @param int $subOrderId | |||
* @return array | |||
*/ | |||
public static function setSubOrderAmount( int $subOrderId) { | |||
try{ | |||
$purchaseModel = new Purchase(); | |||
$purchaseList = $purchaseModel->where(["order_detail_id"=>$subOrderId,"del_flag"=>0])->select(); | |||
$cost = 0; | |||
$amount = 0; | |||
$count = 0; | |||
foreach ($purchaseList as $purchase) { | |||
$cost += $purchase['total_cost']; | |||
$amount += $purchase['total_price']; | |||
$count += $purchase['count']; | |||
} | |||
//更新数据 | |||
$oderItem = new OrderItem(); | |||
$oderItem->update(["total_price"=>$amount,"total_cost"=>$cost,"count"=>$count])->where(["id"=>$subOrderId]); | |||
return Util::returnArrSu(); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("更新附加项目订单子表金额失败".$subOrderId); | |||
} | |||
} | |||
} |
@@ -0,0 +1,103 @@ | |||
<?php | |||
/** | |||
* Created by PhpStorm. | |||
* User: nizongfeng | |||
* Date: 2021/10/27 | |||
* Time: 11:26 | |||
*/ | |||
namespace app\admin\service; | |||
use app\admin\command\Util; | |||
use app\admin\model\OrderHotel; | |||
use app\admin\model\OrderItem; | |||
use app\admin\model\OrderMain; | |||
use think\Exception; | |||
class OrderMainDao | |||
{ | |||
/** | |||
* 添加订单信息 | |||
* @param $param | |||
* @return array | |||
*/ | |||
public function addMain ($param){ | |||
try{ | |||
$data = [ | |||
"commissioner_id"=>$param['commissioner_id'], | |||
"commissioner"=>$param["commissioner"], | |||
"channel_id"=>$param["channel_id"], | |||
"channel_name"=>$param["channel_name"], | |||
"channel_order_no"=>$param["channel_order_no"], | |||
"user_name"=>$param["user_name"], | |||
"user_phone"=>$param["user_phone"], | |||
"order_memo"=>$param["order_memo"] | |||
]; | |||
$orderMain = new OrderMain(); | |||
$id = $orderMain->insertGetId($data); | |||
if (!is_numeric($id)) { | |||
return Util::returnArrEr("新增失败"); | |||
} | |||
return Util::returnArrSu($id); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("新增主订单失败".$e->getMessage()); | |||
} | |||
} | |||
/** | |||
* 更新订单信息 | |||
* @param $param | |||
* @return array | |||
*/ | |||
public function edit($param) { | |||
try{ | |||
$data = [ | |||
"commissioner_id"=>$param['commissioner_id'], | |||
"commissioner"=>$param["commissioner"], | |||
"channel_id"=>$param["channel_id"], | |||
"channel_name"=>$param["channel_name"], | |||
"channel_order_no"=>$param["channel_order_no"], | |||
"user_name"=>$param["user_name"], | |||
"user_phone"=>$param["user_phone"], | |||
"order_memo"=>$param["order_memo"] | |||
]; | |||
$orderMain = new OrderMain(); | |||
$orderMain->save($data,['id'=>$param['id']]); | |||
return Util::returnArrSu(); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("更新主订单失败".$e->getMessage()); | |||
} | |||
} | |||
/** | |||
* 设置主订单金额 | |||
* @param int $orderId | |||
* @return array | |||
*/ | |||
public static function setOrderAmount(int $orderId){ | |||
try { | |||
$itemModel = new OrderItem(); | |||
$hotelModel = new OrderHotel(); | |||
$itemList = $itemModel->where(["order_id" => $orderId])->select(); | |||
$hotelList = $hotelModel->where(["order_id" => $orderId])->select(); | |||
$amount = 0; | |||
$cost = 0; | |||
foreach ($itemList as $item) { | |||
$amount += $item['total_price']; | |||
$cost += $item['total_cost']; | |||
} | |||
foreach ($hotelList as $hotel) { | |||
$amount += $hotel['total_price']; | |||
$cost += $hotel["total_cost"]; | |||
} | |||
//更新金额 | |||
OrderMain::update(["total_amount" => $amount, "cost_amount" => $cost])->where(["id" => $orderId]); | |||
return Util::returnArrSu(); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("更新主表订单金额失败".$orderId); | |||
} | |||
} | |||
} |
@@ -1,11 +1,13 @@ | |||
<?php | |||
namespace app\admin\service; | |||
use app\admin\command\Util; | |||
use app\admin\model\OrderHotel; | |||
use app\admin\model\OrderItem; | |||
use app\admin\model\OrderMain; | |||
use app\admin\model\Purchase; | |||
use app\admin\model\PurchasePrice; | |||
use think\Exception; | |||
/** | |||
* Created by PhpStorm. | |||
@@ -16,74 +18,35 @@ use app\admin\model\PurchasePrice; | |||
class OrderMainService | |||
{ | |||
/** | |||
* 设置主订单金额 | |||
* @param int $orderId | |||
* @throws | |||
*/ | |||
private static function setOrderAmount(int $orderId){ | |||
$itemModel = new OrderItem(); | |||
$hotelModel = new OrderHotel(); | |||
$itemList =$itemModel->where(["order_id"=>$orderId])->select()->toArray(); | |||
$hotelList = $hotelModel->where(["order_id"=>$orderId])->select()->toArray(); | |||
$amount = 0; | |||
$cost = 0; | |||
foreach ($itemList as $item) { | |||
$amount += $item['total_price']; | |||
$cost+= $item['total_cost']; | |||
} | |||
foreach ($hotelList as $hotel) { | |||
$amount += $hotel['total_price']; | |||
$cost += $hotel["total_cost"]; | |||
} | |||
//更新金额 | |||
OrderMain::update(["total_amount"=>$amount,"cost_amount"=>$cost])->where(["id"=>$orderId]); | |||
} | |||
/** | |||
* 设置子订单金额 | |||
* @param int $subOrderId | |||
* @param string $prodType | |||
* @throws \think\db\exception\DataNotFoundException | |||
* @throws \think\db\exception\ModelNotFoundException | |||
* @throws \think\exception\DbException | |||
*/ | |||
private static function setSubOrderAmount( int $subOrderId,string $prodType) { | |||
$purchaseModel = new Purchase(); | |||
$purchaseList = $purchaseModel->where(["order_detail_id"=>$subOrderId,"del_flag"=>0])->select()->toArray(); | |||
$cost = 0; | |||
$amount = 0; | |||
foreach ($purchaseList as $purchase) { | |||
$cost += $purchase['total_cost']; | |||
$amount += $purchase['total_price']; | |||
} | |||
if ($prodType == "hotel") { | |||
OrderHotel::update(["total_price"=>$amount,"total_cost"=>$cost])->where(["id"=>$subOrderId]); | |||
} else { | |||
OrderItem::update(["total_price"=>$amount,"total_cost"=>$cost])->where(["id"=>$subOrderId]); | |||
} | |||
} | |||
public function createOrder($param) { | |||
/** | |||
* todo 1.添加主订单 | |||
*/ | |||
/** | |||
* todo 2.添加子订单 | |||
*/ | |||
/** | |||
* todo 2.1添加子订单下的采购单 | |||
*/ | |||
/** | |||
* 设置采购单/子订单/主订单 金额 | |||
* @param Purchase $purchase | |||
* @throws \think\db\exception\DataNotFoundException | |||
* @throws \think\db\exception\ModelNotFoundException | |||
* @throws \think\exception\DbException | |||
*/ | |||
public function setPurchase(Purchase $purchase){ | |||
$purchasePrice = new PurchasePrice(); | |||
$purchasePriceList = $purchasePrice->where(["purchase_id"=>$purchase["id"],"del_flag"=>0])->select()->toArray(); | |||
$cost = 0; | |||
$amount = 0; | |||
foreach ($purchasePriceList as $price) { | |||
$cost += $price['cost'] * $price["cnt"]; | |||
$amount += $price['price'] * $price["cnt"]; | |||
} | |||
Purchase::update(["total_price"=>$amount,["total_cost"=>$cost]])->where(["id"=>$purchase['id']]); | |||
//更新子表 | |||
static::setSubOrderAmount($purchase['order_detail_id'], $purchase['prod_type']); | |||
//更新主表金额 | |||
static::setOrderAmount($purchase['order_id']); | |||
/** | |||
* todo 2.1.1添加采购单的每日价格 | |||
*/ | |||
/** | |||
* todo 2.1.2 计算更新 采购单总金额、成本、产品数量 | |||
*/ | |||
/** | |||
* todo 2.2 计算更新 子订单成本、金额、产品数量 | |||
*/ | |||
/** | |||
* todo 3 计算更新 主订单成本、金额、产品数量 | |||
*/ | |||
} | |||
} |
@@ -0,0 +1,104 @@ | |||
<?php | |||
/** | |||
* Created by PhpStorm. | |||
* User: nizongfeng | |||
* Date: 2021/10/27 | |||
* Time: 16:38 | |||
*/ | |||
namespace app\admin\service; | |||
use app\admin\command\Util; | |||
use app\admin\model\Purchase; | |||
use think\Exception; | |||
class PurchaseDao | |||
{ | |||
/** | |||
* 添加酒店项目采购单 | |||
* @param $param | |||
* @param $hotelOrder | |||
* @return array | |||
*/ | |||
public function addHotelPurchase($param,$hotelOrder):array { | |||
try { | |||
$data = [ | |||
"order_id" => $hotelOrder['order_id'], | |||
"prod_type" => 'hotel', | |||
"order_detail_id" => $hotelOrder['id'], | |||
"group_id" => $param['group_id'], | |||
"pro_name" => $hotelOrder['hotel_name'], | |||
"item_name" => $hotelOrder['room_name'], | |||
"item_unit" => $hotelOrder['plan_name'], | |||
"check_in_date" => $param['check_in_date'], | |||
"check_out_date" => $param['check_out_date'], | |||
"supplier_id" => $param['supplier_id'], | |||
"supplier_name" => $param['supplier_name'], | |||
"purchase_user_id" => $param['purchase_user_id'], | |||
"purchase_user" => $param['purchase_user'] | |||
]; | |||
$model = new Purchase(); | |||
$id = $model->insertGetId($data); | |||
return Util::returnArrSu($id); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("新增采购都失败".$e->getMessage()); | |||
} | |||
} | |||
/** | |||
* 添加附加项目采购单 | |||
* @param $param | |||
* @param $itemOrder | |||
* @return array | |||
*/ | |||
public function addItemInfo($param, $itemOrder):array { | |||
try { | |||
$data = [ | |||
"order_id" => $itemOrder['order_id'], | |||
"prod_type" => 'hotel', | |||
"order_detail_id" => $itemOrder['id'], | |||
"group_id" => $param['group_id'], | |||
"pro_name" => $itemOrder['hotel_name'], | |||
"item_name" => $itemOrder['item_name'], | |||
"item_unit" => $itemOrder['item_unit'], | |||
"check_in_date" => $param['check_in_date'], | |||
"check_out_date" => $param['check_out_date'], | |||
"supplier_id" => $param['supplier_id'], | |||
"supplier_name" => $param['supplier_name'], | |||
"purchase_user_id" => $param['purchase_user_id'], | |||
"purchase_user" => $param['purchase_user'] | |||
]; | |||
$model = new Purchase(); | |||
$id = $model->insertGetId($data); | |||
return Util::returnArrSu($id); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("新增采购都失败".$e->getMessage()); | |||
} | |||
} | |||
/** | |||
* 设置采购单 金额 | |||
* @param $purchaseId | |||
* @return array | |||
*/ | |||
public function setPurchase(int $purchaseId){ | |||
try{ | |||
$purchasePrice = new PurchasePrice(); | |||
$purchasePriceList = $purchasePrice->where(["purchase_id"=>$purchaseId,"del_flag"=>0])->select()->toArray(); | |||
$cost = 0; | |||
$amount = 0; | |||
$cnt = 0; | |||
foreach ($purchasePriceList as $price) { | |||
$cost += $price['cost'] * $price["cnt"]; | |||
$amount += $price['price'] * $price["cnt"]; | |||
$cnt += $price['cnt']; | |||
} | |||
Purchase::update(["total_price"=>$amount,"total_cost"=>$cost,"count"=>$cnt])->where(["id"=>$purchaseId]); | |||
return Util::returnArrSu(); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("更新采购单金额失败".$e->getMessage()); | |||
} | |||
} | |||
} |
@@ -0,0 +1,49 @@ | |||
<?php | |||
/** | |||
* Created by PhpStorm. | |||
* User: nizongfeng | |||
* Date: 2021/10/27 | |||
* Time: 19:19 | |||
*/ | |||
namespace app\admin\service; | |||
use app\admin\command\Util; | |||
use app\admin\model\PurchasePrice; | |||
use think\Exception; | |||
class PurchasePriceDao | |||
{ | |||
/** | |||
* 添加采购单每日价格 | |||
* @param $param | |||
* @param int $order_id | |||
* @param string $prod_type | |||
* @param int $order_detail_id | |||
* @param int $purchase_id | |||
* @return array | |||
*/ | |||
public function addList($param,int $order_id,string $prod_type,int $order_detail_id,int $purchase_id){ | |||
try { | |||
foreach ($param as $value) { | |||
$data = [ | |||
"order_id" => $order_id, | |||
"prod_type" => $prod_type, | |||
"order_detail_id" => $order_detail_id, | |||
"purchase_id" => $purchase_id, | |||
"run_date" => $value['run_date'], | |||
"count" => $value['count'], | |||
"price" => $value['price'], | |||
"cost" => $value['cost'] | |||
]; | |||
$model = new PurchasePrice(); | |||
$model->insertGetId($data); | |||
} | |||
return Util::returnArrSu(); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("添加采购单每日价格失败".$e->getMessage()); | |||
} | |||
} | |||
} |