|
- <?php
- /**
- * Created by PhpStorm.
- * User: nizongfeng
- * Date: 2021/10/27
- * Time: 19:19
- */
-
- namespace app\admin\dao;
-
-
- 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 saveList($param, int $order_id, string $prod_type, int $order_detail_id, int $purchase_id)
- {
- try {
- //删除记录
- $this->delete($purchase_id);
- //循环添加
- 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'],
- "del_flag" => 0
- ];
- $model = new PurchasePrice();
- if (empty($value['id'])) {
- $model->insertGetId($data);
- } else {
- $model->save($data, ["id" => $value['id']]);
- }
- }
- return Util::returnArrSu();
- } catch (Exception $e) {
- return Util::returnArrEr("添加/更新采购单每日价格失败:" . $e->getMessage());
- }
- }
-
- /**
- * 删除数据
- * @param $purchase_id
- */
- public function delete($purchase_id)
- {
- $model = new PurchasePrice();
- $model->save(["del_flag" => 1], ["purchase_id" => $purchase_id]);
- }
-
- /**
- * 删除数据
- * @param $purchase_id
- */
- public function deleteByOrderId($orderId)
- {
- $model = new PurchasePrice();
- $model->save(["del_flag" => 1], ["order_id" => $orderId]);
- }
-
- /**
- * 删除子订单对于的每日价格
- * @param $subOrderId
- */
- public function deleteBySubOrderId($subOrderId) {
- $model = new PurchasePrice();
- $model->save(["del_flag" => 1], ["order_detail_id" => $subOrderId]);
- }
-
- /**
- * 获取采购单金额
- * @param $orderId
- * @return array
- */
- public function getPurchasePriceListByOrderId($orderId) {
- $model = new PurchasePrice();
- try {
- $list = $model->where(["order_id" => $orderId, "del_flag" => 0])->select()->toArray();
- if (null == $list) {
- return Util::returnArrSu("", []);
- }
- return Util::returnArrSu("", $list);
- }catch (Exception $e) {
- return Util::returnArrEr("获取采购单金额异常".$e->getMessage());
- }
- }
- }
|