Consult.php 128 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\DataGroup as DataGroupModel;
  5. use app\admin\model\ProcessOrder;
  6. use think\App;
  7. use think\facade\Db;
  8. use think\facade\Validate;
  9. //竞价单(咨询单)
  10. class Consult extends Base
  11. {
  12. public $noble=[];
  13. public function __construct(App $app)
  14. {
  15. parent::__construct($app);
  16. $this->noble =\think\facade\Config::get("noble");
  17. }
  18. public function conlist(){
  19. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  20. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  21. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  22. $infoNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  23. if ($infoNo !== "") {
  24. $where[] = ['a.infoNo','like','%'.$infoNo.'%'];
  25. }
  26. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  27. if ($salesman !== "") {
  28. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  29. $where[]= ["b.salesman",'like',"%$salesman%"];
  30. }
  31. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  32. if ($cpName !== "") {
  33. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  34. $where[]= ["a.good_Name",'like',"%$cpName%"];
  35. }
  36. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  37. if ($khNo !== "") {
  38. // $where['khNo'] = $khNo;
  39. $where[]= ["b.khNo",'like',"%$khNo%"];
  40. }
  41. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  42. if ($companyNo !== "") {
  43. // $where['khNo'] = $khNo;
  44. $where[]= ["b.companyNo",'like',"%$companyNo%"];
  45. }
  46. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  47. if ($start !="") {
  48. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  49. $where[]= ["a.addtime",'>=',$start];
  50. }
  51. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  52. if($end !=""){
  53. $where[]= ["a.addtime",'<=',$end];
  54. }
  55. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  56. if ($status !== "") {
  57. $where[]= ["a.status",'=',$status];
  58. }
  59. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  60. if ($company_name !== "") $where[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)];
  61. // $role=$this->checkRole();
  62. // if(!empty($role['write'])){
  63. // $where[]=["b.createrid","in",$role['write']];
  64. // }
  65. // $role = $this->checkDataShare();
  66. // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["b.createrid", "in", $role[DataGroupModel::$type_全部]];
  67. $role = $this->checkDataShare();
  68. $hand = resign_hand_user($this->uid,0);
  69. if (!empty($role[DataGroupModel::$type_全部])) {
  70. $arr= array_unique(array_merge($hand,$role[DataGroupModel::$type_全部]));
  71. $where[] = ['b.createrid', 'in',$arr];
  72. }
  73. // if(!empty($role['platform']) ){
  74. // $where[]=["b.platform_code","in",$role['platform']];
  75. // }
  76. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  77. ->count();
  78. $total = ceil($count / $size);
  79. $page = $page >= $total ? $total : $page;
  80. $list = Db::name('consult_info')
  81. ->alias("a")
  82. ->leftJoin("consult_order b", "a.zxNo=b.zxNo")
  83. ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
  84. ->where($where)
  85. ->page($page, $size)
  86. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart,u.itemid")
  87. ->order("a.id desc")
  88. ->cursor();
  89. $data=[];
  90. foreach ($list as $value){
  91. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  92. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  93. true):[];
  94. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  95. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  96. $value['khname']="";
  97. if($value['khNo']!==""){
  98. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  99. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  100. }
  101. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  102. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  103. //是否具有编辑权限
  104. $value['is_allow_update'] = 0;
  105. if (in_array($this->roleid, [1, 33]) || in_array($value['createrid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  106. $data[]=$value;
  107. }
  108. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  109. }
  110. public function info(){
  111. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  112. if($id==""){
  113. return error_show(1002,"咨询单编号不能为空");
  114. }
  115. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  116. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  117. $fo['can']=$in;
  118. if(empty($fo)){
  119. return error_show(1002,"未找到咨询单编号");
  120. }else{
  121. return app_show(0,"获取成功",$fo);
  122. }
  123. }
  124. public function del(){
  125. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  126. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  127. if($de==false){
  128. return error_show(1002,'咨询单信息未找到');
  129. }
  130. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  131. if($dell){
  132. return error_show(0,"删除成功");
  133. }else
  134. return error_show(1002,"删除失败");
  135. }
  136. public function create(){
  137. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  138. if($is_project===""){
  139. return error_show(1002,"参数is_project不能为空");
  140. }
  141. if($is_project==1){
  142. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  143. if($projectNo===""){
  144. return error_show(1002,"参数projectNo不能为空");
  145. }
  146. }
  147. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  148. if($khNo===""){
  149. return error_show(1002,"参数khNo不能为空");
  150. }
  151. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  152. if($companyNo===""){
  153. return error_show(1002,"参数companyNo不能为空");
  154. }
  155. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  156. if($endtime===""){
  157. return error_show(1002,"参数endtime不能为空");
  158. }
  159. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  160. "";
  161. if($platform_code===""){
  162. return error_show(1002,"参数platform_code不能为空");
  163. }
  164. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  165. if($ladder==""){
  166. return error_show(1005,"参数ladder不能为空");
  167. }
  168. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  169. if($token==''){
  170. return error_show(105,"参数token不能为空");
  171. }
  172. $user =GetUserInfo($token);
  173. if(empty($user)||$user['code']!=0){
  174. return error_show(102,"用户数据不存在");
  175. }
  176. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  177. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  178. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  179. $zxNo=makeNo("ZX");
  180. Db::startTrans();
  181. try{
  182. $data=[
  183. "zxNo"=>$zxNo,
  184. "createrid"=>$createrid,
  185. "creater"=>$creater,
  186. "is_project"=>$is_project,
  187. "projectNo"=>isset($projectNo) ? $projectNo:"",
  188. "khNo"=>$khNo,
  189. "companyNo"=>$companyNo,
  190. "endtime"=>$endtime,
  191. "salesman"=>$creater,
  192. "platform_code"=>$platform_code,
  193. "saleid"=>$createrid,
  194. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  195. "status"=>0,
  196. "is_del"=>0,
  197. "addtime"=>date("Y-m-d H:i:s"),
  198. "updatetime"=>date("Y-m-d H:i:s"),
  199. ];
  200. $zx = Db::name("consult_order")->insert($data);
  201. if($zx){
  202. //判断是否是项目,且该项目是否存在台账记录中
  203. if($is_project==1) $stand_exists=Db::name('standing_book')->field('id')->where('projectNo',$projectNo)->find();
  204. foreach ($ladder as $value){
  205. $infoNo=makeNo("IF");
  206. $specinfo=[];
  207. if(isset($value['specinfo']) &&!empty($value['specinfo'])){
  208. foreach ($value["specinfo"] as $v){
  209. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  210. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  211. $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
  212. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
  213. $specinfo[]=$v;
  214. }
  215. }
  216. $info=[
  217. "infoNo"=>$infoNo,
  218. "zxNo"=>$zxNo,
  219. "spuCode"=>"",
  220. "good_name"=>$value['good_name'],
  221. "good_img"=>$value['good_img'],
  222. "cat_id"=>$value['cat_id'],
  223. "unit"=>$value['unit'],
  224. "brand_id"=>$value['brand_id'],
  225. "arrival_time"=>$value['arrival_time'],
  226. "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
  227. "cost_desc" => isset($value['cost_desc']) ? $value['cost_desc'] : '',
  228. "is_addrs"=>$value['is_addrs'],
  229. "is_custom"=>$value['is_custom'],
  230. "metal_id"=>$value['metal_id'],
  231. "config"=>isset($value['config'])?$value['config']:"",
  232. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  233. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  234. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  235. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  236. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  237. "budget_price"=>$value['budget_price'],
  238. "num"=>$value['num'],
  239. "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
  240. "use_desc"=>$value['use_desc'],
  241. "remark"=>$value['remark'],
  242. "status"=>1,
  243. "is_del"=>0,
  244. "addtime"=>date("Y-m-d H:i:s"),
  245. "updatetime"=>date("Y-m-d H:i:s"),
  246. 'enclosure_file'=>isset($value['enclosure_file'])?$value['enclosure_file']:'',
  247. ];
  248. $up = Db::name("consult_info")->insertGetId($info);
  249. if(!$up){
  250. Db::rollback();
  251. return error_show(1004,'添加失败');
  252. }else{
  253. //修改状态
  254. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  255. "order_code" => $infoNo,//咨询单详情编号
  256. "status" => 1,//这里的status是之前的值
  257. "action_remark" => '',//备注
  258. "action_type" => "create"//新建create,编辑edit,更改状态status
  259. ], "ZXD", 1, $info);
  260. //竞价单不走流程,不推待办已办
  261. // ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  262. // "order_type" => 'ZXD',
  263. // "order_code" => $infoNo,//咨询单详情编号
  264. // "order_id" => $up,
  265. // "order_status" => 1,
  266. // 'before_status'=>0
  267. // ]);
  268. //如果存在该项目编码,更新对应的第一个竞价单编码,其他竞价单编码新增(带着项目编码)
  269. if (isset($stand_exists)) {
  270. Db::name('standing_book')
  271. ->where('id', $stand_exists['id'])
  272. ->update([
  273. 'infoNo' => $infoNo,
  274. 'updatetime' => date('Y-m-d H:i:s')
  275. ]);
  276. unset($stand_exists);//后面的竞价单编码不用更新,都是新增
  277. } else {
  278. //添加台账信息
  279. Db::name('standing_book')
  280. ->insert([
  281. 'standBookNo' => makeNo("IO"),
  282. 'projectNo' => isset($projectNo) ? $projectNo : '',
  283. 'infoNo' => $infoNo,
  284. 'companyNo' => $companyNo,
  285. 'customer_code' => $khNo,
  286. 'addtime' => date('Y-m-d H:i:s'),
  287. 'updatetime' => date('Y-m-d H:i:s')
  288. ]);
  289. }
  290. }
  291. }
  292. Db::commit();
  293. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  294. }else{
  295. Db::rollback();
  296. return error_show(1004,"新建失败");
  297. }
  298. }catch (\Exception $e){
  299. Db::rollback();
  300. return error_show(1003,$e->getMessage());
  301. }
  302. }
  303. public function zxinfo(){
  304. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  305. if($infoNo==""){
  306. return error_show(1004,"参数infoNo不能为空");
  307. }
  308. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  309. if($zxinfo==false){
  310. return error_show(1004,"未找到信息数据");
  311. }
  312. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  313. if($zxorder==false){
  314. return error_show(1004,"未找到咨询信息数据");
  315. }
  316. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  317. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  318. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  319. $zxinfo['khname']="";
  320. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  321. $zxinfo['khNo']="";
  322. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  323. $zxinfo['brand']="";
  324. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  325. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  326. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  327. $zxinfo['company']="";
  328. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  329. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  330. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  331. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  332. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  333. $zxinfo['project_name']="";
  334. $zxinfo['budget_total']="";
  335. $zxinfo['departinfo']=[];
  336. $zxinfo['unit_name']="";
  337. $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
  338. $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
  339. if($zxorder['khNo']!==""){
  340. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  341. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  342. $zxinfo['khNo']= $zxorder['khNo'];
  343. }
  344. if($zxinfo['unit']!==""){
  345. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  346. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  347. }
  348. if($zxinfo['brand_id']!==""){
  349. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  350. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  351. }
  352. if($zxorder['companyNo']!==""){
  353. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  354. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  355. }
  356. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  357. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  358. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  359. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  360. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  361. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
  362. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  363. }
  364. if($zxorder['depart']>0){
  365. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  366. }
  367. if($zxorder['platform_code']>0){
  368. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  369. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  370. }
  371. return app_show(0,"获取成功",$zxinfo);
  372. }
  373. public function zxedit(){
  374. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  375. if($infoNo==""){
  376. return error_show(1004,"参数infoNo不能为空");
  377. }
  378. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  379. if($zxinfo==false){
  380. return error_show(1004,"未找到信息数据");
  381. }
  382. $enclosure_file =isset($this->post['enclosure_file'])&&$this->post['enclosure_file']!=""?trim($this->post['enclosure_file']):$zxinfo['enclosure_file'];
  383. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
  384. if($good_name==""){
  385. return error_show(1003,"参数good_name不能为空");
  386. }
  387. $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
  388. if($good_img==""){
  389. return error_show(1003,"参数good_img不能为空");
  390. }
  391. $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
  392. if($cat_id==""){
  393. return error_show(1003,"参数cat_id不能为空");
  394. }
  395. $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
  396. if($unit==""){
  397. return error_show(1003,"参数unit不能为空");
  398. }
  399. $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
  400. $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
  401. if($arrival_time==""){
  402. return error_show(1003,"参数arrival_time不能为空");
  403. }
  404. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  405. if($specin==""){
  406. return error_show(1003,"参数specinfo不能为空");
  407. }
  408. $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
  409. // if($cost_desc==""){
  410. // return error_show(1003,"参数cost_desc不能为空");
  411. // }
  412. $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  413. if($is_addrs===""){
  414. return error_show(1003,"参数is_addrs不能为空");
  415. }
  416. $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
  417. if($is_custom===""){
  418. return error_show(1003,"参数is_custom不能为空");
  419. }
  420. $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
  421. if($metal_id===""){
  422. return error_show(1003,"参数metal_id不能为空");
  423. }
  424. $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
  425. $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
  426. $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  427. $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  428. $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
  429. $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  430. $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
  431. $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
  432. if($num===""){
  433. return error_show(1003,"参数num不能为空");
  434. }
  435. if($budget_price===""){
  436. return error_show(1003,"参数budget_price不能为空");
  437. }
  438. $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
  439. $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
  440. if($use_desc==""){
  441. return error_show(1003,"参数use_desc不能为空");
  442. }
  443. $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
  444. if($remark==""){
  445. return error_show(1003,"参数remark不能为空");
  446. }
  447. $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
  448. if($endtime==""){
  449. return error_show(1003,"参数endtime不能为空");
  450. }
  451. if($metal_id!=0){
  452. if($config==""){
  453. return error_show(1003,"参数config不能为空");
  454. }
  455. if($other_config==""){
  456. return error_show(1003,"参数other_config不能为空");
  457. }
  458. if($specs_weight===""){
  459. return error_show(1003,"参数specs_weight不能为空");
  460. }
  461. if($gold_price===""){
  462. return error_show(1003,"参数gold_price不能为空");
  463. }
  464. }
  465. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  466. if($token==''){
  467. return error_show(102,"参数token不能为空");
  468. }
  469. $user =GetUserInfo($token);
  470. if(empty($user)||$user['code']!=0){
  471. return error_show(105,"用户数据不存在");
  472. }
  473. $specinfo=[];
  474. foreach ($specin as $v){
  475. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  476. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  477. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  478. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  479. $specinfo[]=$v;
  480. }
  481. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  482. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  483. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  484. Db::startTrans();
  485. try{
  486. $innew =makeNo("IF");
  487. $info=[
  488. "infoNo"=>$innew,
  489. "zxNo"=>$zxinfo['zxNo'],
  490. "spuCode"=>"",
  491. "good_name"=>$good_name,
  492. "good_img"=>$good_img,
  493. "cat_id"=>$cat_id,
  494. "unit"=>$unit,
  495. "brand_id"=>$brand_id,
  496. "arrival_time"=>$arrival_time,
  497. "specinfo"=>json_encode($specinfo),
  498. // "color"=>$color,
  499. // "material"=>$material,
  500. "cost_desc"=>$cost_desc,
  501. "is_addrs"=>$is_addrs,
  502. "is_custom"=>$is_custom,
  503. "metal_id"=>$metal_id,
  504. "config"=>$config,
  505. "other_config"=>$other_config,
  506. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  507. "gold_price"=>$gold_price===""? 0 : $gold_price,
  508. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  509. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  510. "budget_price"=>$budget_price,
  511. "num"=>$num,
  512. "pgNo"=>$pgNo,
  513. "use_desc"=>$use_desc,
  514. "remark"=>$remark,
  515. "bargain_num"=>$zxinfo['bargain_num']+1,
  516. "status"=>1,
  517. "is_del"=>0,
  518. "addtime"=>date("Y-m-d H:i:s"),
  519. "updatetime"=>date("Y-m-d H:i:s"),
  520. 'bargain_status'=>1,
  521. 'enclosure_file'=>$enclosure_file
  522. ];
  523. $up = Db::name("consult_info")->insert($info);
  524. if($up){
  525. //操作记录
  526. ActionLog::logAdd($this->post['token'], [
  527. "order_code" => $innew,//咨询单详情编号
  528. "status" => 1,//这里的status是之前的值
  529. "action_remark" => '',//备注
  530. "action_type" => "edit"//新建create,编辑edit,更改状态status
  531. ], "ZXD", 1, $this->post);
  532. // ProcessOrder::AddProcess($this->post['token'], [
  533. // "order_type" => 'ZXD',
  534. // "order_code" => $innew,//咨询单详情编号
  535. // "order_id" => 0,
  536. // "order_status" => 1
  537. // ]);
  538. if (!empty($bidlist)){
  539. foreach ($bidlist as $value){
  540. unset($value['id']);
  541. $value['infoNo']=$innew;
  542. $value['bidNo']=makeNo("BD");
  543. $value['spuCode']=makeNo("SKU");
  544. $value['status'] =0;
  545. $value['updatetime'] =date("Y-m-d H:i:s");
  546. $in = Db::name("consult_bids")->insert($value);
  547. if($in==false){
  548. Db::rollback();
  549. return error_show(1004,"反馈商品新建失败");
  550. }
  551. ActionLog::logAdd($this->post['token'], [
  552. "order_code" => $innew,//咨询单详情编号
  553. "status" => 1,//这里的status是之前的值
  554. "action_remark" => '',//备注
  555. "action_type" => "edit"//新建create,编辑edit,更改状态status
  556. ], "FKD", 1, $this->post);
  557. }
  558. }
  559. $zxinfo["bargain_status"] =1;
  560. $zxinfo["status"] =6;
  561. $zxinfo["bargain_code"] =$innew;
  562. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  563. $bar=Db::name("consult_info")->save($zxinfo);
  564. if($bar==false){
  565. Db::rollback();
  566. return error_show(1004,"反馈商品更新失败");
  567. }else{
  568. //修改状态,添加待办
  569. ActionLog::logAdd($this->post['token'], [
  570. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  571. "status" => $zxinfo['status'],//这里的status是之前的值
  572. "action_remark" => '',//备注
  573. "action_type" => "edit"//新建create,编辑edit,更改状态status
  574. ], "ZXD", $zxinfo['status'], $zxinfo);
  575. }
  576. //更新consule_order记录
  577. $op = Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,
  578. 'updatetime'=>date('Y-m-d H:i:s')]);
  579. if($op==false){
  580. Db::rollback();
  581. return error_show(1004,'咨询单结束时间更新失败');
  582. }
  583. //维护台账记录
  584. $insert_standing_book_data=[
  585. 'standBookNo'=>makeNo('IO'),
  586. 'infoNo'=>$innew,
  587. 'addtime' => date('Y-m-d H:i:s'),
  588. 'updatetime' => date('Y-m-d H:i:s')
  589. ];
  590. $temp_project = Db::name('consult_order')->field('id,projectNo,khNo,companyNo')->where(['zxNo'=>$zxinfo['zxNo'], 'is_del'=>0])->find();
  591. if(!empty($temp_project)){
  592. $insert_standing_book_data['projectNo']=$temp_project['projectNo'];
  593. $insert_standing_book_data['companyNo']=$temp_project['companyNo'];
  594. $insert_standing_book_data['customer_code']=$temp_project['khNo'];
  595. }
  596. Db::name('standing_book')->insert($insert_standing_book_data);
  597. Db::commit();
  598. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  599. }
  600. }catch (\Exception $e){
  601. Db::rollback();
  602. return error_show(1004,$e->getMessage());
  603. }
  604. }
  605. //** 发布竞标任务 */
  606. public function bargain(){
  607. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  608. if($infoNo==""){
  609. return error_show(1004,"参数infoNo不能为空");
  610. }
  611. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  612. if($zxinfo==false){
  613. return error_show(1004,"未找到信息数据");
  614. }
  615. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  616. if($status===""){
  617. return error_show(1004,"参数status不能为空");
  618. }
  619. // if($status==1&&$zxinfo['status']>1){
  620. // $zxinfo['bargain_num']=+1;
  621. // }
  622. $old_zxinfo_status = $zxinfo['status'];
  623. $zxinfo['status']=$status;
  624. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  625. $up = Db::name("consult_info")->save($zxinfo);
  626. if($up){
  627. //修改状态,添加待办
  628. ActionLog::logAdd($this->post['token'], [
  629. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  630. "status" => $old_zxinfo_status,//这里的status是之前的值
  631. "action_remark" => '',//备注
  632. "action_type" => "status"//新建create,编辑edit,更改状态status
  633. ], "ZXD", $zxinfo['status'], $zxinfo);
  634. return app_show(0,"状态更新成功");
  635. }else{
  636. return error_show(1003,"状态更新失败");
  637. }
  638. }
  639. //反馈商品添加
  640. public function feadback(){
  641. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  642. if($infoNo==""){
  643. return error_show(1002,"参数infoNo不能为空");
  644. }
  645. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  646. if($zxinfo==false){
  647. return error_show(1003,"未找到信息数据");
  648. }
  649. if($zxinfo['status']!=1){
  650. return error_show(1004,"任务未进行");
  651. }
  652. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  653. if($zx==false){
  654. return error_show(1003,"未找咨询信息数据");
  655. }
  656. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  657. if($pname==""){
  658. return error_show(1002,"参数pname不能为空");
  659. }
  660. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  661. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  662. if($cat_id==""){
  663. return error_show(1002,"参数cat_id不能为空");
  664. }
  665. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  666. if($specin==""){
  667. return error_show(1003,"参数specinfo不能为空");
  668. }
  669. $specinfo=[];
  670. foreach ($specin as $v){
  671. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  672. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  673. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  674. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  675. $specinfo[]=$v;
  676. }
  677. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  678. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  679. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  680. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  681. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  682. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day']) :"";
  683. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  684. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  685. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  686. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  687. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  688. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  689. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  690. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  691. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  692. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"0";
  693. $good_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  694. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  695. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"0";
  696. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  697. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval($this->post['pakge_fee']):"0";
  698. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"0";
  699. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  700. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  701. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  702. if($nake_fee==="" ){
  703. return error_show(1004,"参数nake_fee不能为空");
  704. }
  705. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  706. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  707. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  708. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  709. if($delivery_place==''){
  710. return error_show(1002,"参数delivery_place不能为空");
  711. }
  712. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  713. if($token==''){
  714. return error_show(1002,"参数token不能为空");
  715. }
  716. $user =GetUserInfo($token);
  717. if(empty($user)||$user['code']!=0){
  718. return error_show(1005,"用户数据不存在");
  719. }
  720. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  721. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  722. $bidNo=makeNo("BD");
  723. $spucode=makeNo("SKU");
  724. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  725. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  726. //部分参数的大小校验
  727. $vali = Validate::rule([
  728. 'expire_day|有效时长'=>'require|elt:214748364',
  729. 'delivery_day|物流时长'=>'require|elt:214748364',
  730. 'work_day|生产工期'=>'require|elt:214748364',
  731. 'weight|总重量'=>'require|max:10',
  732. ]);
  733. $temp = [
  734. 'expire_day'=>$expire_day,
  735. 'delivery_day'=>$delivery_day,
  736. 'work_day'=>$work_day,
  737. 'weight'=>$weight,
  738. ];
  739. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  740. $sale_cost_fee = $cost_fee;//销售工艺费默认取传值
  741. $cat_top_list = made($cat_id);
  742. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  743. if ($is_gold_price == 1 && $cat_top_id == 6) {
  744. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  745. ->find();
  746. //$total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  747. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  748. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $good_weight * $gold["price"] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  749. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  750. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  751. // $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  752. $saleprice = $total_fee/ (1 - $budget);
  753. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  754. $sale_cost_fee = ($saleprice - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) /$good_weight - $gold["price"];
  755. }else{
  756. if($nake_fee){
  757. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight +
  758. $pakge_fee + $mark_fee + $cert_fee +$nake_fee)/ (1 - $budget);
  759. $total_fee = $demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  760. }else{
  761. $saleprice = ($demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee) /
  762. (1 - $budget);
  763. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee;
  764. }
  765. }
  766. $supplier = Db::name('supplier')
  767. ->field('id,person,personid')
  768. ->where('code',$supplierNo)
  769. ->findOrEmpty();
  770. $data=[
  771. "bidNo"=>$bidNo,
  772. "infoNo"=>$infoNo,
  773. "zxNo"=>$zxinfo['zxNo'],
  774. "spuCode"=>$spucode,
  775. "good_name"=>$pname,
  776. "brand_id"=>$brandid,
  777. "cat_id"=>$cat_id,
  778. "specinfo"=>json_encode($specinfo),
  779. "unit_id"=>$unit_id,
  780. "cost_desc"=>$cost_desc,
  781. "work_day"=>$work_day,
  782. "delivery_day"=>$delivery_day,
  783. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  784. "expire_day"=>$expire_day,
  785. "origin_place"=>$origin_place,
  786. "supplierNo"=>$supplierNo,
  787. "pay_way"=>$pay_way,
  788. "tax"=>$tax,
  789. "send_way"=>$send_way,
  790. "metal_id"=>$metal_id,
  791. "is_gold_price"=>$is_gold_price,
  792. "config"=>$config,
  793. "other_config"=>$other_config,
  794. "weight"=>$weight,
  795. "good_weight"=>$good_weight,
  796. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  797. "is_diff"=>$is_diff,
  798. "demo_fee"=>$demo_fee,
  799. "delivery_fee"=>$delivery_fee,
  800. "open_fee"=>$open_fee,
  801. "pakge_fee"=>$pakge_fee,
  802. "nake_fee"=>$nake_fee,
  803. "mark_fee"=>$mark_fee,
  804. "cert_fee"=>$cert_fee,
  805. "cost_fee"=>$cost_fee,
  806. "total_fee"=>$total_fee,
  807. "supply_area"=>$supply_area,
  808. "remark"=>$remark,
  809. "sale_price"=>$saleprice,
  810. "sale_cost_fee"=>$sale_cost_fee,
  811. "origin_cost_fee"=>$sale_cost_fee,
  812. "origin_price"=>$saleprice,
  813. "createrid"=>$createrid,
  814. "creater"=>$creater,
  815. "status"=>$zxinfo['status']==1 ?1 :2,
  816. "is_del"=>0,
  817. "addtime"=>date("Y-m-d H:i:s"),
  818. "updatetime"=>date("Y-m-d H:i:s"),
  819. 'delivery_place'=>$delivery_place,//发货地
  820. 'cgder' => $supplier['person'] ?? '',
  821. 'cgderid' => $supplier['personid'] ?? 0,
  822. ];
  823. Db::startTrans();
  824. try{
  825. $insert= Db::name("consult_bids")->insert($data);
  826. if($insert){
  827. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  828. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  829. if($projectinfo==false){
  830. Db::rollback();
  831. return error_show(1006,"未找到项目信息");
  832. }
  833. $temp=[];
  834. $temp['spuCode']=$spucode;
  835. $temp['skuCode']="";
  836. $temp['pgNo']=$zxinfo['pgNo'];
  837. $temp['projectNo']=$zx['projectNo'];
  838. $temp['good_name']=$pname;
  839. $temp['good_type']=$projectinfo['good_type'];
  840. $temp['data_source']=2;
  841. $temp['cat_id']=$cat_id;
  842. $temp['budget_price']=$projectinfo['budget_price'];
  843. $temp['sale_price']=$saleprice;
  844. $temp['origin_price']=$total_fee;
  845. $temp['num']=$zxinfo['num'];
  846. $temp['status']=0;
  847. $temp['is_del']=0;
  848. $temp['creater']=$creater;
  849. $temp['createrid']=$createrid;
  850. $temp['addtime']=date("Y-m-d H:i:s");
  851. $temp['updatetime']=date("Y-m-d H:i:s");
  852. $nu = Db::name("project_feedback")->insert($temp);
  853. if($nu==false){
  854. Db::rollback();
  855. return error_show(1006,"项目反馈失败");
  856. }else{
  857. $old_projectinfo_status = $projectinfo['status'];
  858. $projectinfo['status']=2;
  859. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  860. $up = Db::name("project_info")->save($projectinfo);
  861. if($up){
  862. //修改状态,添加待办,只记录动作
  863. ActionLog::logAdd($this->post['token'], [
  864. "order_code" => $projectinfo['pgNo'],//编码
  865. "status" => $old_projectinfo_status,//这里的status是之前的值
  866. "action_remark" => '',//备注
  867. "action_type" => "status"//新建create,编辑edit,更改状态status
  868. ], "PRI", 2, $projectinfo);
  869. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  870. ->count();
  871. if($count==0){
  872. $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
  873. if($projetc!=false){
  874. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  875. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  876. if($proc==false){
  877. Db::rollback();
  878. return error_show(1006,"项目反馈失败");
  879. }else{
  880. //修改状态,添加待办
  881. ActionLog::logAdd($this->post['token'], [
  882. "order_code" => $projetc['projectNo'],//项目编码
  883. "status" => 1,//这里的status是之前的值
  884. "action_remark" => '',//备注
  885. "action_type" => "status"//新建create,编辑edit,更改状态status
  886. ], "PRO", 2, $projetc);
  887. ProcessOrder::AddProcess($this->post['token'], [
  888. "order_type" => 'PRO',
  889. "order_code" => $projetc['projectNo'],
  890. "order_id" => $projetc['id'],
  891. "order_status" => 2,"before_status"=>1
  892. ]);
  893. }
  894. }
  895. }
  896. }
  897. }
  898. }
  899. Db::commit();
  900. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  901. }else{
  902. Db::rollback();
  903. return error_show(1006,"反馈失败");
  904. }
  905. }catch (\Exception $e){
  906. Db::rollback();
  907. return error_show(1006,$e->getMessage());
  908. }
  909. }
  910. //反馈商品详情
  911. public function feadinfo(){
  912. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  913. if($bidNo==""){
  914. return error_show(1004,"参数bidNo不能为空");
  915. }
  916. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  917. if($info==false){
  918. return error_show(1004,"未找到商品数据");
  919. }
  920. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  921. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  922. $info['cat_info'] = made($info['cat_id'],[]);
  923. $info['noble_weight'] = $info['good_weight'];
  924. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  925. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  926. if($info['brand_id']!=0){
  927. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  928. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  929. }else{
  930. $info["brand_name"]="";
  931. $info["brand_id"]="";
  932. }
  933. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  934. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  935. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  936. $god=[
  937. "metal_id"=>$info['metal_id'],
  938. "weight"=>$info["good_weight"],
  939. "demo_fee"=>$info["demo_fee"],
  940. "delivery_fee"=>$info["delivery_fee"],
  941. "open_fee"=>$info["open_fee"],
  942. "packing_fee"=>$info["pakge_fee"],
  943. "mark_fee"=>$info["mark_fee"],
  944. "nake_fee"=>$info["nake_fee"],
  945. "cert_fee"=>$info["cert_fee"],
  946. "cost_fee"=>$info["cost_fee"],
  947. "num"=>$bidinfo["num"],
  948. ];
  949. if($info['is_gold_price']==1){
  950. $price = GoldPrice($god, $budget/100);
  951. $info['sale_price'] =round($price,2);
  952. }
  953. $info['specinfo'] = json_decode($info['specinfo'],true);
  954. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  955. if($info['delivery_place']!=""){
  956. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['delivery_place']);
  957. }
  958. $info['delivery_place_cn']=GetAddr(json_encode($place));
  959. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  960. if($info['origin_place']!=""){
  961. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['origin_place']);
  962. }
  963. $info['origin_place_cn']=GetAddr(json_encode($place));
  964. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  965. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  966. $info['bargain'] =$bargain;
  967. $info['good_img'] = explode(',',$info['good_img']);
  968. //添加商品创建人字段
  969. $good_info = Db::name('good_basic')
  970. ->field('id,createrid,creater')
  971. ->where('is_del',0)
  972. ->where('spuCode',$info['spuCode'])
  973. ->findOrEmpty();
  974. $info['good_createrid'] = $good_info['createrid']??0;
  975. $info['good_creater'] = $good_info['creater']??'';
  976. return app_show(0,"获取成功",$info);
  977. }
  978. //反馈商品编辑
  979. public function feededit(){
  980. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  981. if($bidNo==""){
  982. return error_show(1002,"参数bidNo不能为空");
  983. }
  984. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  985. if($bidinfo==false){
  986. return error_show(1003,"未找到信息数据");
  987. }
  988. if($bidinfo['status']>=5){
  989. return error_show(1004,"咨询单已确认无法修改");
  990. }
  991. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  992. if($zxinfo==false){
  993. return error_show(1003,"未找到信息数据");
  994. }
  995. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  996. if($zx==false){
  997. return error_show(1003,"未找咨询信息数据");
  998. }
  999. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  1000. if($pname==""){
  1001. return error_show(1002,"参数pname不能为空");
  1002. }
  1003. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  1004. // if($brandid==""){
  1005. // return error_show(1002,"参数brandid不能为空");
  1006. // }
  1007. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  1008. if($cat_id==""){
  1009. return error_show(1002,"参数cat_id不能为空");
  1010. }
  1011. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  1012. if($specin==""){
  1013. return error_show(1003,"参数specinfo不能为空");
  1014. }
  1015. $specinfo=[];
  1016. foreach ($specin as $v){
  1017. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  1018. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  1019. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  1020. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  1021. $specinfo[]=$v;
  1022. }
  1023. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  1024. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  1025. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  1026. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  1027. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  1028. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  1029. :"";
  1030. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  1031. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  1032. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  1033. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  1034. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"0";
  1035. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  1036. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  1037. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  1038. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  1039. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"0";
  1040. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!=""? floatval($this->post['noble_weight']):"0";
  1041. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"0";
  1042. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"0";
  1043. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"0";
  1044. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"0";
  1045. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):0;
  1046. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"0";
  1047. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"0";
  1048. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"0";
  1049. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  1050. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  1051. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  1052. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  1053. if($delivery_place==''){
  1054. return error_show(1002,"参数delivery_place不能为空");
  1055. }
  1056. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  1057. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1058. $sale_cost_fee = $bidinfo['sale_cost_fee'];
  1059. $cat_top_list = made($cat_id);
  1060. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  1061. if ($is_gold_price == 1 && $cat_top_id == 6) {
  1062. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  1063. ->find();
  1064. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1065. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $noble_weight * $gold["price"] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  1066. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1067. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1068. $saleprice = $total_fee / (1 - $budget);
  1069. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1070. $sale_cost_fee = ( $saleprice- ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $noble_weight - $gold["price"];
  1071. }else{
  1072. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee*$noble_weight + $pakge_fee +
  1073. $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  1074. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee/$zxinfo['num'] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee+$cert_fee +$nake_fee;
  1075. }
  1076. Db::startTrans();
  1077. try{
  1078. $data=[
  1079. "good_name"=>$pname,
  1080. "brand_id"=>$brandid,
  1081. "cat_id"=>$cat_id,
  1082. "specinfo"=>json_encode($specinfo),
  1083. // "material"=>$material,
  1084. "unit_id"=>$unit_id,
  1085. "cost_desc"=>$cost_desc,
  1086. "work_day"=>$work_day,
  1087. "delivery_day"=>$delivery_day,
  1088. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  1089. "expire_day"=>$expire_day,
  1090. "origin_place"=>$origin_place,
  1091. "supplierNo"=>$supplierNo,
  1092. "pay_way"=>$pay_way,
  1093. "tax"=>$tax,
  1094. "send_way"=>$send_way,
  1095. "metal_id"=>$metal_id,
  1096. "is_gold_price"=>$is_gold_price,
  1097. "config"=>$config,
  1098. "other_config"=>$other_config,
  1099. "weight"=>$weight,
  1100. "good_weight"=>$noble_weight,
  1101. "is_diff"=>$is_diff,
  1102. "demo_fee"=>$demo_fee,
  1103. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  1104. "delivery_fee"=>$delivery_fee,
  1105. "open_fee"=>$open_fee,
  1106. "pakge_fee"=>$pakge_fee,
  1107. "nake_fee"=>$nake_fee,
  1108. "mark_fee"=>$mark_fee,
  1109. "cert_fee"=>$cert_fee,
  1110. "cost_fee"=>$cost_fee,
  1111. "sale_cost_fee"=>$sale_cost_fee,
  1112. "origin_cost_fee"=>$sale_cost_fee,
  1113. "total_fee"=>$total_fee,
  1114. "sale_price"=>$saleprice,
  1115. "origin_price"=>$saleprice,
  1116. "supply_area"=>$supply_area,
  1117. "remark"=>$remark,
  1118. "status"=>0,
  1119. "updatetime"=>date("Y-m-d H:i:s"),
  1120. 'delivery_place' => $delivery_place
  1121. ];
  1122. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  1123. if($insert){
  1124. if($zxinfo['bargain_status']==1){
  1125. $zxinfo['bargain_status']=0;
  1126. $infoip =Db::name("consult_info")->save($zxinfo);
  1127. if($infoip==false){
  1128. Db::rollback();
  1129. return error_show(1006,"咨询信息状态更新失败");
  1130. }
  1131. }
  1132. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  1133. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  1134. if($projectinfo==false){
  1135. Db::rollback();
  1136. return error_show(1006,"未找到项目信息");
  1137. }
  1138. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  1139. if($feed!=false) {
  1140. $feed['good_name']=$pname;
  1141. $feed['good_type']=$projectinfo['good_type'];
  1142. $feed['cat_id']=$cat_id;
  1143. $feed['sale_price']=$saleprice;
  1144. $feed['origin_price']=$total_fee;
  1145. $feed['updatetime']=date("Y-m-d H:i:s");
  1146. $temp['updatetime']=date("Y-m-d H:i:s");
  1147. $nu=Db::name("project_feedback")->save($feed);
  1148. if ($nu == false) {
  1149. Db::rollback();
  1150. return error_show(1006 , "项目反馈失败");
  1151. } else {
  1152. $old_projectinfo_status=$projectinfo['status'];
  1153. $projectinfo['status']=2;
  1154. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  1155. $up=Db::name("project_info")->save($projectinfo);
  1156. if ($up) {
  1157. //修改状态,添加待办,只记录动作
  1158. ActionLog::logAdd($this->post['token'] , [
  1159. "order_code"=>$projectinfo['pgNo'] ,//编码
  1160. "status"=>$old_projectinfo_status ,//这里的status是之前的值
  1161. "action_remark"=>'' ,//备注
  1162. "action_type"=>"status"//新建create,编辑edit,更改状态status
  1163. ] , "PRI" , 2 , $projectinfo
  1164. );
  1165. $count=Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->count();
  1166. if ($count == 0) {
  1167. //先查询是否存在status==1的项目,有的话再更新,否则跳过
  1168. $project_id=Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->value('id' , 0);
  1169. if ($project_id) {
  1170. $proc=Db::name("project")->where(["id"=>$project_id])->update(["status"=>2 , "updatetime"=>date("Y-m-d H:i:s")]);
  1171. if ($proc == false) {
  1172. Db::rollback();
  1173. return error_show(1006 , "项目反馈失败");
  1174. } else {
  1175. //修改状态,添加待办
  1176. ActionLog::logAdd($this->post['token'] , [
  1177. "order_code"=>$projectinfo['projectNo'] ,//项目编码
  1178. "status"=>1 ,//这里的status是之前的值
  1179. "action_remark"=>'' ,//备注
  1180. "action_type"=>"status"//新建create,编辑edit,更改状态status
  1181. ] , "PRO" , 2 , $this->post
  1182. );
  1183. ProcessOrder::AddProcess($this->post['token'] , [
  1184. "order_type"=>'PRO' ,
  1185. "order_code"=>$projectinfo['projectNo'] ,
  1186. "order_id"=>$project_id ,
  1187. "order_status"=>2 , "before_status"=>1
  1188. ]
  1189. );
  1190. }
  1191. }
  1192. }
  1193. }
  1194. }
  1195. }
  1196. }
  1197. Db::commit();
  1198. return app_show(0,"编辑成功");
  1199. }else{
  1200. Db::rollback();
  1201. return error_show(1004,"编辑失败");
  1202. }
  1203. }catch (\Exception $e){
  1204. Db::rollback();
  1205. return error_show(1004,$e->getMessage());
  1206. }
  1207. }
  1208. //生成议价单
  1209. public function bargain_add(){
  1210. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1211. if($bidNo===""){
  1212. return error_show(1004,"参数bidNo不能为空");
  1213. }
  1214. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1215. if($info==false){
  1216. return error_show(1004,"未找到商品数据");
  1217. }
  1218. $consult =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1219. if($consult==false){
  1220. return error_show(1004,"未找到咨询数据");
  1221. }
  1222. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  1223. if($bargain_price===""){
  1224. return error_show(1004,"参数bargain_price不能为空");
  1225. }
  1226. $cost_price = isset($this->post['cost_price'])&& $this->post['cost_price']!=""?floatval($this->post['cost_price']):"";
  1227. if($info['is_gold_price']==1){
  1228. if($cost_price==""){
  1229. return error_show(1004,"参数cost_price不能为空");
  1230. }
  1231. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  1232. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1233. $gold = Db::name("gold_price1")->where(["type"=>$info['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1234. ->find();
  1235. $bargain_price = ($info['demo_fee']/$consult['num']+$info['delivery_fee']+$info['open_fee']/$consult['num']+$info['good_weight'] * $gold["price"] + $cost_price *$info['good_weight']+$info['pakge_fee']+$info['mark_fee'] +$info['cert_fee'] +$info['nake_fee']) / (1 - $budget);
  1236. }
  1237. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1238. // if($bargain_reason===""){
  1239. // return error_show(1004,"参数bargain_reason不能为空");
  1240. // }
  1241. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1242. if($infos==false){
  1243. return error_show(1004,"未找到商品数据");
  1244. }
  1245. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1246. return error_show(1004,"咨询单招标未结束或已确认商品");
  1247. }
  1248. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1249. if($token==''){
  1250. return error_show(105,"参数token不能为空");
  1251. }
  1252. $user =GetUserInfo($token);
  1253. if(empty($user)||$user['code']!=0){
  1254. return error_show(1002,"用户数据不存在");
  1255. }
  1256. //新增两个字段
  1257. //议价备注
  1258. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1259. //议价原因id
  1260. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1261. if ($result_info_id != '') {
  1262. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1263. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1264. }
  1265. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1266. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1267. $bargainNo =makeNo("BA");
  1268. Db::startTrans();//::todo 金价 毛利计算
  1269. try{
  1270. $data=[
  1271. "bidsNo"=>$bidNo,
  1272. "infoNo"=>$info['infoNo'],
  1273. "zxNo"=>$info['zxNo'],
  1274. "bargainNo"=>$bargainNo,
  1275. "bargain_type"=>1,
  1276. "bargain_reason"=>$bargain_reason,
  1277. "sale_price"=>$info['sale_price'],
  1278. "cost_before_price"=>$info['sale_cost_fee'],
  1279. "cost_after_price"=>$cost_price,
  1280. "before_rate"=>round(($info['origin_price']-$info['total_fee'])/$info['origin_price'],2),
  1281. "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
  1282. "after_price"=>$bargain_price,
  1283. "exam_info"=>"",
  1284. "status"=>0,
  1285. "is_del"=>0,
  1286. "creater"=>$creater,
  1287. "createrid"=>$createrid,
  1288. "addtime"=>date("Y-m-d H:i:s"),
  1289. "updatetime"=>date("Y-m-d H:i:s"),
  1290. 'bargain_remark'=>$bargain_remark,
  1291. 'result_info_id'=>$result_info_id,
  1292. ];
  1293. $int = Db::name("bargain_order")->insertGetId($data);
  1294. if($int){
  1295. //修改状态,添加待办
  1296. ActionLog::logAdd($this->post['token'], [
  1297. "order_code" => $bargainNo,//咨询单详情编号
  1298. "status" => 0,//这里的status是之前的值
  1299. "action_remark" => '',//备注
  1300. "action_type" => "status"//新建create,编辑edit,更改状态status
  1301. ], "YJD", $data['status'], $data);
  1302. ProcessOrder::AddProcess($this->post['token'], [
  1303. "order_type" => 'YJD',
  1304. "order_code" => $bargainNo,
  1305. "order_id" => $int,
  1306. "order_status" =>0,
  1307. "before_status"=>0,
  1308. 'holder_id'=>$data['createrid']
  1309. ]);
  1310. $odlstatus=$info['status'];
  1311. $info['status']=3;
  1312. $info['updatetime']=date("Y-m-d H:i:s");
  1313. $up =Db::name("consult_bids")->save($info);
  1314. if($up){
  1315. //修改状态,添加待办
  1316. ActionLog::logAdd($this->post['token'], [
  1317. "order_code" => $bidNo,//咨询单详情编号
  1318. "status" => $odlstatus,//这里的status是之前的值
  1319. "action_remark" => '',//备注
  1320. "action_type" => "status"//新建create,编辑edit,更改状态status
  1321. ], "FKD", $info['status'], $info);
  1322. $old_infos_status = $infos['status'];
  1323. $infos['status']=3;
  1324. $infos['updatetime']=date("Y-m-d H:i:s");
  1325. $ups =Db::name("consult_info")->save($infos);
  1326. if($ups){
  1327. //修改状态,添加待办
  1328. ActionLog::logAdd($this->post['token'], [
  1329. "order_code" => $infos['infoNo'],//咨询单详情编号
  1330. "status" => $old_infos_status,//这里的status是之前的值
  1331. "action_remark" => '',//备注
  1332. "action_type" => "status"//新建create,编辑edit,更改状态status
  1333. ], "ZXD", $infos['status'], $infos);
  1334. //维护台账信息
  1335. Db::name('standing_book')->where('infoNo', $info['infoNo'])->update(['bargainNo' => $bargainNo,'updatetime' => date('Y-m-d H:i:s')]);
  1336. Db::commit();
  1337. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1338. }
  1339. }
  1340. }
  1341. Db::rollback();
  1342. return error_show(1004,"议价单新建失败");
  1343. }catch (\Exception $e){
  1344. Db::rollback();
  1345. return error_show(1004,$e->getMessage());
  1346. }
  1347. }
  1348. //选择商品
  1349. public function bids_check(){
  1350. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1351. if($bidNo===""){
  1352. return error_show(1004,"参数bidNo不能为空");
  1353. }
  1354. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1355. if($info==false){
  1356. return error_show(1004,"未找到商品数据");
  1357. }
  1358. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1359. if($infos==false){
  1360. return error_show(1004,"未找到商品数据");
  1361. }
  1362. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1363. return error_show(1004,"咨询单招标未结束或已确认商品");
  1364. }
  1365. Db::startTrans();
  1366. try {
  1367. $oldstattus=$info['status'];
  1368. $info['status']=6;
  1369. $info['updatetime']=date("Y-m-d H:i:s");
  1370. $bids = Db::name("consult_bids")->save($info);
  1371. if($bids){
  1372. //修改状态,添加待办
  1373. ActionLog::logAdd($this->post['token'], [
  1374. "order_code" =>$bidNo,//咨询单详情编号
  1375. "status" => $oldstattus,//这里的status是之前的值
  1376. "action_remark" => '',//备注
  1377. "action_type" => "status"//新建create,编辑edit,更改状态status
  1378. ], "FKD", $info['status'], $info);
  1379. $old_infos_status = $infos['status'];
  1380. $infos['status']=4;
  1381. $infos['updatetime']=date("Y-m-d H:i:s");
  1382. $se = Db::name("consult_info")->save($infos);
  1383. if($se){
  1384. //修改状态,添加待办
  1385. ActionLog::logAdd($this->post['token'], [
  1386. "order_code" => $infos['infoNo'],//咨询单详情编号
  1387. "status" => $old_infos_status,//这里的status是之前的值
  1388. "action_remark" => '',//备注
  1389. "action_type" => "status"//新建create,编辑edit,更改状态status
  1390. ], "ZXD", $infos['status'], $infos);
  1391. Db::name("bargain_order")->where(["bidsNo"=>$bidNo,"is_del"=>0,"status"=>[0,2,4,5,7]])
  1392. ->update(['status'=>12,"remark"=>'已选择商品,取消议价',"updatetime"=>date("Y-m-d H:i:s")]);
  1393. Db::commit();
  1394. return app_show(0,"商品确定成功");
  1395. }
  1396. }
  1397. Db::rollback();
  1398. return error_show(1004,"商品确认失败");
  1399. }catch (\Exception $e){
  1400. Db::rollback();
  1401. return error_show(1004,$e->getMessage());
  1402. }
  1403. }
  1404. //议价审核
  1405. /**
  1406. * status:
  1407. * 0待审核 1业务主管审核通过 2 业务税率未通过 3 业务驳回 4 专员通过 5 专员驳回 6 财务通过 7 财务税率未通过 8财务驳回 9 boss通过 10 boss 税率越线通过 11 驳回
  1408. */
  1409. public function bargain_status(){
  1410. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1411. if($bargainNo===""){
  1412. return error_show(1004,"参数bargainNo不能为空");
  1413. }
  1414. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1415. if($info==false){
  1416. return error_show(1004,"未找到议价数据");
  1417. }
  1418. if($info['status']==12){
  1419. return error_show(1004,"议价单已取消");
  1420. }
  1421. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1422. if($bids==false){
  1423. return error_show(1004,"未找到商品数据");
  1424. }
  1425. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1426. if($coninfo==false){
  1427. return error_show(1004,"未找到咨询单数据");
  1428. }
  1429. if($bids['status']==6){
  1430. return error_show(1004,"咨询已选择商品");
  1431. }
  1432. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1433. if($status===''){
  1434. return error_show(1005,"参数status不能为空");
  1435. }
  1436. $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
  1437. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1438. $rate = isset($catinfo['rate']) ? $catinfo['rate']/100:0; //业务主管利率
  1439. $money_rate = isset($catinfo['money_rate']) ? $catinfo['money_rate']/100:0;//财务主管利率
  1440. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1441. if($bids['is_gold_price']==1){
  1442. $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1443. ->find();
  1444. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1445. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1446. $total_fe= $bids['demo_fee'] / $coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] / $coninfo['num'] +
  1447. $bids['good_weight']*$gold["price"] +$bids['cost_fee']*$bids['good_weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee'];
  1448. $saleprice =$total_fe / (1 - $budget);
  1449. $rate_price = $total_fe / (1 - $rate);
  1450. $money_price =$total_fe / (1 - $money_rate);
  1451. $lower_price =$total_fe / (1 - $lower_rate);
  1452. }else{
  1453. $total_fe= $bids['demo_fee']/$coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] /
  1454. $coninfo['num']+$bids['cost_fee']*$bids['good_weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'];
  1455. if($bids['nake_fee']!=0){
  1456. $saleprice = ($total_fe)/ (1 - $budget);
  1457. $rate_price = ($total_fe)/ (1 - $rate);
  1458. $money_price =($total_fe)/ (1 - $money_rate);
  1459. $lower_price = ($total_fe) / (1 - $lower_rate);
  1460. }else{
  1461. $saleprice = $total_fe / (1 - $budget);
  1462. $rate_price =$total_fe/ (1 - $rate);
  1463. $money_price =$total_fe / (1 - $money_rate);
  1464. $lower_price = $total_fe/ (1 - $lower_rate);
  1465. }
  1466. }
  1467. $ra_status = $info['status'];
  1468. if($status==1){
  1469. if($info['status']==0){
  1470. if($info['after_price']<$rate_price){
  1471. $info['status']=2;
  1472. }else{
  1473. $info['status']=1;
  1474. }
  1475. }elseif($info['status']==2){
  1476. $info['status']=4;
  1477. }elseif($info['status']==4||$info['status']==5){
  1478. if($info['after_price']<$money_price){
  1479. $info['status']=7;
  1480. }else{
  1481. $info['status']=6;
  1482. }
  1483. }elseif($info['status']==7){
  1484. $info['lower_price'] =$lower_price;
  1485. if($info['after_price']<$lower_price){
  1486. $info['status']=10;
  1487. }else{
  1488. $info['status']=9;
  1489. }
  1490. }
  1491. }else{
  1492. if($info['status']==0){
  1493. $info['status']=3;
  1494. }elseif($info['status']==2){
  1495. $info['status']=4;
  1496. }elseif($info['status']==4||$info['status']==5){
  1497. $info['status']=8;
  1498. }elseif($info['status']==7){
  1499. $info['lower_price'] =$lower_price;
  1500. $info['status']=11;
  1501. }
  1502. }
  1503. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1504. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1505. if($token==''){
  1506. return error_show(105,"参数token不能为空");
  1507. }
  1508. $user =GetUserInfo($token);
  1509. if(empty($user)||$user['code']!=0){
  1510. return error_show(1002,"用户数据不存在");
  1511. }
  1512. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1513. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1514. Db::startTrans();
  1515. try{
  1516. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1517. $examinfo[]=["status"=>$status,"info_status"=>$ra_status,"remark"=>$remark,"createrid"=>$createrid,
  1518. "creater"=>$creater];
  1519. // $info['status'] =$status;
  1520. $info['remark'] =$remark;
  1521. $info['exam_info']=json_encode($examinfo) ;
  1522. $info['updatetime'] =date("Y-m-d H:i:s");
  1523. $up =Db::name("bargain_order")->save($info);
  1524. if($up){
  1525. //修改状态,添加待办
  1526. ActionLog::logAdd($this->post['token'], [
  1527. "order_code" => $bargainNo,//咨询单详情编号
  1528. "status" =>$ra_status,//这里的status是之前的值
  1529. "action_remark" => '',//备注
  1530. "action_type" => "status"//新建create,编辑edit,更改状态status
  1531. ], "YJD", $info['status'], $info);
  1532. $process=["order_code"=>$bargainNo,"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'YJD',"before_status"=>$ra_status,'holder_id'=>$info['createrid']];
  1533. ProcessOrder::AddProcess($token,$process);
  1534. if($info['status']==1||$info['status']==3||$info['status']==8||$info['status']==6||$info['status']==9||$info['status']==10||$info['status']==11){
  1535. $bidstatus=$bids['status'];
  1536. $bids['status']=5;
  1537. if($info['status']==1||$info['status']==6||$info['status']==9||$info['status']==10){
  1538. $bids['sale_price']=$info['after_price'];
  1539. if($bids['is_gold_price']==1){
  1540. // $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1541. // ->find();
  1542. // $bids['sale_price']= ($bids['open_fee'] / $coninfo['num'] + $bids['weight'] * $gold["price"] + $info['cost_after_price'] *$bids['weight'] +
  1543. // $bids['pakge_fee'] + $bids['mark_fee'] +$bids['cert_fee'] +$bids['nake_fee']) /(1 - $budget);
  1544. $bids['sale_cost_fee'] = $info['cost_after_price'];
  1545. $bids['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1546. }
  1547. }
  1548. $bids['updatetime']=date("Y-m-d H:i:s");
  1549. $up =Db::name("consult_bids")->save($bids);
  1550. if($up==false){
  1551. Db::rollback();
  1552. return error_show(1004,"数据更新失败");
  1553. }
  1554. ActionLog::logAdd($this->post['token'], [
  1555. "order_code" => $info["bidsNo"],//咨询单详情编号
  1556. "status" => $bidstatus,//这里的status是之前的值
  1557. "action_remark" => '',//备注
  1558. "action_type" => "status"//新建create,编辑edit,更改状态status
  1559. ], "FKD", $bids['status'], $bids);
  1560. }
  1561. Db::commit();
  1562. return app_show(0,"更新成功");
  1563. }
  1564. }catch (\Exception $e){
  1565. Db::rollback();
  1566. return error_show(1004,$e->getMessage());
  1567. }
  1568. }
  1569. public function bargain_info(){
  1570. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1571. if($bargainNo===""){
  1572. return error_show(1004,"参数bargainNo不能为空");
  1573. }
  1574. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1575. if($info==false){
  1576. return error_show(1004,"未找到议价数据");
  1577. }
  1578. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1579. if($bidinfos==false){
  1580. return error_show(1004,"未找到商品数据");
  1581. }
  1582. $consultinfos =Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])->find();
  1583. if($consultinfos==false){
  1584. return error_show(1004,"未找到咨询商品数据");
  1585. }
  1586. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1587. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1588. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1589. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1590. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1591. $info['before_rate'] =round($info['before_rate']*100,2);
  1592. $info['sale_price'] =round($bidinfos['origin_price'],2);
  1593. $info['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  1594. $info['after_rate'] = round($info['after_rate']*100,2);
  1595. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_decode($info['exam_info'],true):"";
  1596. if($bidinfos['brand_id']!=0){
  1597. $info['brand_id'] = $bidinfos['brand_id'];
  1598. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1599. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1600. }else{
  1601. $info["brand_name"]="";
  1602. $info["brand_id"]="";
  1603. }
  1604. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1605. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1606. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1607. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1608. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1609. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1610. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1611. $info['budget'] =$budget;
  1612. $info['rate_status'] =0; //利率状态 0 业务主管利率无法通过 1 财务主管利率无法通过 2 boos利率无法通过 3 完全通过
  1613. if($info['after_rate']>=$catinfo['rate']){
  1614. //业务主管利率
  1615. $info['rate_status'] =1;
  1616. }
  1617. elseif ($info['after_rate']>=$catinfo['money_rate']){
  1618. //财务主管利率
  1619. $info['rate_status'] =2;
  1620. }
  1621. elseif ($info['after_rate']>=$catinfo['lower_rate']){
  1622. //boss利率
  1623. $info['rate_status'] =3;
  1624. }
  1625. $god=[
  1626. "metal_id"=>$bidinfos['metal_id'],
  1627. "weight"=>$bidinfos["good_weight"],
  1628. "demo_fee"=>$bidinfos["demo_fee"],
  1629. "delivery_fee"=>$bidinfos["delivery_fee"],
  1630. "open_fee"=>$bidinfos["open_fee"],
  1631. "packing_fee"=>$bidinfos["pakge_fee"],
  1632. "mark_fee"=>$bidinfos["mark_fee"],
  1633. "nake_fee"=>$bidinfos["nake_fee"],
  1634. "cert_fee"=>$bidinfos["cert_fee"],
  1635. "cost_fee"=>$bidinfos["cost_fee"],
  1636. "num"=>$bidinfoe["num"],
  1637. ];
  1638. $info['gold_price']=0;
  1639. $info['noble_weight']=$bidinfos['good_weight'];
  1640. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1641. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1642. ->find();
  1643. $info['gold_price'] =$gold['price'];
  1644. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num'] + $bidinfos['good_weight']* $gold["price"] +$bidinfos['cost_fee']*$bidinfos['good_weight'] + $bidinfos['pakge_fee'] +$bidinfos['mark_fee'] + $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1645. }else{
  1646. if($bidinfos['nake_fee']!=0){
  1647. $lower_price =($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1648. }else{
  1649. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'])/ (1 - $lower_rate);
  1650. }
  1651. }
  1652. $info['cost_desc'] =$bidinfos['cost_desc'];
  1653. $info['work_day'] =$bidinfos['work_day'];
  1654. $info['delivery_day'] =$bidinfos['delivery_day'];
  1655. $info['expire_day'] =$bidinfos['expire_day'];
  1656. $info['origin_place'] =$bidinfos['origin_place'];
  1657. $info['origin_addr'] ="";
  1658. if($bidinfos['origin_place']!=''){
  1659. $code = explode(",",$bidinfos['origin_place']);
  1660. $temp=[];
  1661. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1662. $temp['city_code']=isset($code[1])?$code[1]:"";
  1663. $temp['area_code']=isset($code[2])?$code[2]:"";
  1664. $addr= GetAddr(json_encode($temp));
  1665. $info['origin_addr'] = $addr;
  1666. }
  1667. $info['supplierNo'] =$bidinfos['supplierNo'];
  1668. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1669. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1670. $info['pay_way'] =$bidinfos['pay_way'];
  1671. $info['tax'] =$bidinfos['tax'];
  1672. $info['send_way'] =$bidinfos['send_way'];
  1673. $info['metal_id'] =$bidinfos['metal_id'];
  1674. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1675. $info['config'] =$bidinfos['config'];
  1676. $info['other_config'] =$bidinfos['other_config'];
  1677. $info['weight'] =$bidinfos['weight'];
  1678. $info['good_weight'] =$bidinfos['good_weight'];
  1679. $info['is_diff'] =$bidinfos['is_diff'];
  1680. $info['demo_fee'] =$bidinfos['demo_fee'];
  1681. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1682. $info['open_fee'] =$bidinfos['open_fee'];
  1683. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1684. $info['nake_fee'] =$bidinfos['nake_fee'];
  1685. $info['mark_fee'] =$bidinfos['mark_fee'];
  1686. $info['cert_fee'] =$bidinfos['cert_fee'];
  1687. $info['cost_fee'] =$bidinfos['cost_fee'];
  1688. $info['total_fee'] =$bidinfos['total_fee'];
  1689. $info['supply_area'] =$bidinfos['supply_area'];
  1690. $info['remark'] =$bidinfos['remark'];
  1691. $info['is_addrs'] =$consultinfos['is_addrs'];
  1692. $info['is_custom'] =$consultinfos['is_custom'];
  1693. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1694. // $info['sale_price'] =round($bidinfos['sale_price'],2);//议价前价格
  1695. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1696. if($info['status']==7){
  1697. $info['lower_price'] =round($lower_price,2);
  1698. }
  1699. //获取议价原因
  1700. if ($info['result_info_id'] != 0) {
  1701. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1702. } else {
  1703. $info['result_info'] = '';
  1704. }
  1705. return app_show(0,"获取成功",$info);
  1706. }
  1707. public function bidlist(){
  1708. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1709. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1710. $where=[['is_del',"=",0]];
  1711. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1712. if ($zxNo !== "") {
  1713. $where[] = ['zxNo','like','%'.$zxNo.'%'];
  1714. }
  1715. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1716. if ($infoNo !== "") {
  1717. $where[] = ['infoNo','like','%'.$infoNo.'%'];
  1718. }
  1719. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1720. if ($bidNo !== "") {
  1721. $where[] = ['bidNo','like','%'.$bidNo.'%'];
  1722. }
  1723. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1724. if ($pgNo !== "") {
  1725. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1726. $where[] = ['infoNo','in',$bidinfo];
  1727. }
  1728. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1729. if ($bargain_status !== "") {
  1730. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1731. $where[] = ['infoNo','in',$bidinfo];
  1732. }
  1733. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1734. if ($projectNo !== "") {
  1735. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1736. ("zxNo");
  1737. $where[] = ['zxNo','in',$zxlist];
  1738. }
  1739. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1740. if($is_own==1){
  1741. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1742. if($token==""){
  1743. return error_show(101,'token不能为空');
  1744. }
  1745. $apply_id =GetUserInfo($token);
  1746. if(empty($apply_id)||$apply_id['code']!=0){
  1747. return error_show(1002,"申请人数据不存在");
  1748. }
  1749. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1750. $where[]=['createrid',"=",$rm];
  1751. }
  1752. $count = Db::name('consult_bids')->where($where)->count();
  1753. $total = ceil($count / $size);
  1754. $page = $page >= $total ? $total : $page;
  1755. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
  1756. $data=[];
  1757. foreach ($list as $value){
  1758. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1759. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1760. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1761. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1762. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1763. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1764. if($value['brand_id']!=0){
  1765. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1766. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1767. }else{
  1768. $value["brand_name"]="";
  1769. $value["brand_id"]="";
  1770. }
  1771. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1772. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1773. $god=[
  1774. "metal_id"=>$value['metal_id'],
  1775. "weight"=>$value["good_weight"],
  1776. "demo_fee"=>$value["demo_fee"],
  1777. "delivery_fee"=>$value["delivery_fee"],
  1778. "open_fee"=>$value["open_fee"],
  1779. "packing_fee"=>$value["pakge_fee"],
  1780. "mark_fee"=>$value["mark_fee"],
  1781. "nake_fee"=>$value["nake_fee"],
  1782. "cert_fee"=>$value["cert_fee"],
  1783. // "cost_fee"=>$value["cost_fee"],
  1784. "cost_fee"=>$value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_cost_fee"]: $value["cost_fee"],
  1785. //暂时注掉,搞不清楚原因@吴广广
  1786. "num"=>$bidinfo["num"],
  1787. ];
  1788. $top_cat = made($value['cat_id']);
  1789. $top_cat_id = isset($top_cat[0]['id'])?$top_cat[0]['id']:0;
  1790. if($value['is_gold_price']==1 && $top_cat_id==6 ){
  1791. $price = GoldPrice($god, $budget/100);
  1792. $value['sale_price'] = round($price,2);
  1793. $value['origin_price'] = $value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_price"]:
  1794. $value["origin_price"];
  1795. }
  1796. $value['cost_fee'] =$value['origin_cost_fee'];
  1797. $value['specinfo'] = json_decode($value['specinfo'],true);
  1798. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1799. $value['bargain_status']=$bidinfo['bargain_status'];
  1800. //reject驳回原因,status==5表示驳回
  1801. $value['reject']=[];
  1802. if ($value['status'] >=5) {
  1803. $value['reject'] = Db::name('bargain_order')
  1804. ->field('id,remark,status')
  1805. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  1806. ->whereIn('status', [3,8,11])->order("id desc")
  1807. ->find();
  1808. }
  1809. //产地
  1810. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1811. if($value['delivery_place']!=""){
  1812. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['delivery_place']);
  1813. }
  1814. $value['delivery_place_cn']=GetAddr(json_encode($place));
  1815. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1816. if($value['origin_place']!=""){
  1817. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['origin_place']);
  1818. }
  1819. $value['origin_addr']=GetAddr(json_encode($place));
  1820. // if($value['origin_place']!=''){
  1821. // $code = explode(",",$value['origin_place']);
  1822. // $temp=[];
  1823. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  1824. // $temp['city_code']=isset($code[1])?$code[1]:"";
  1825. // $temp['area_code']=isset($code[2])?$code[2]:"";
  1826. // $addr= GetAddr(json_encode($temp));
  1827. // $value['origin_addr'] = $addr;
  1828. // }
  1829. $good_info = Db::name('good_basic')
  1830. ->field('id,createrid,creater')
  1831. ->where('is_del',0)
  1832. ->where('spuCode',$value['spuCode'])
  1833. ->findOrEmpty();
  1834. $value['good_createrid']=$good_info['createrid']??$value['createrid'];
  1835. $value['good_creater']=$good_info['creater']??$value['creater'];
  1836. $data[] = $value;
  1837. }
  1838. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1839. }
  1840. public function feedlist(){
  1841. $where=[['is_del',"=",0]];
  1842. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1843. if ($zxNo !== "") {
  1844. $where[] = ['zxNo','=',$zxNo];
  1845. }
  1846. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1847. if ($infoNo !== "") {
  1848. $where[] = ['infoNo','=',$infoNo];
  1849. }
  1850. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1851. if ($bidNo !== "") {
  1852. $where[] = ['bidNo','=',$bidNo];
  1853. }
  1854. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1855. if ($projectNo !== "") {
  1856. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1857. ("zxNo");
  1858. $where[] = ['zxNo','in',$zxlist];
  1859. }
  1860. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1861. if($token==''){
  1862. return error_show(102,"参数token不能为空");
  1863. }
  1864. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1865. if($is_own==1){
  1866. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1867. if($token==""){
  1868. return error_show(101,'token不能为空');
  1869. }
  1870. $apply_id =GetUserInfo($token);
  1871. if(empty($apply_id)||$apply_id['code']!=0){
  1872. return error_show(1002,"申请人数据不存在");
  1873. }
  1874. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1875. $where[]=['createrid',"=",$rm];
  1876. }
  1877. $list =Db::name('consult_bids')->where($where)->select();
  1878. $data=[];
  1879. foreach ($list as $value){
  1880. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1881. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1882. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1883. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1884. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1885. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1886. if($value['brand_id']!=0){
  1887. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1888. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1889. }else{
  1890. $value["brand_name"]="";
  1891. $value["brand_id"]="";
  1892. }
  1893. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1894. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1895. $god=[
  1896. "metal_id"=>$value['metal_id'],
  1897. "weight"=>$value["good_weight"],
  1898. "demo_fee"=>$value["demo_fee"],
  1899. "delivery_fee"=>$value["delivery_fee"],
  1900. "open_fee"=>$value["open_fee"],
  1901. "packing_fee"=>$value["pakge_fee"],
  1902. "mark_fee"=>$value["mark_fee"],
  1903. "nake_fee"=>$value["nake_fee"],
  1904. "cert_fee"=>$value["cert_fee"],
  1905. "cost_fee"=>$value["cost_fee"],
  1906. "num"=>$bidinfo["num"],
  1907. ];
  1908. if ($value['is_gold_price'] == 1 ) {
  1909. $gold = Db::name("gold_price1")->where(["type"=>$value['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1910. ->find();
  1911. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1912. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1913. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num'] +$value["good_weight"] *$gold["price"] +
  1914. $value["cost_fee"] * $value["good_weight"] + $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) / (1 - $budget);
  1915. // //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1916. // $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  1917. }else{
  1918. if($value["nake_fee"]){
  1919. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"])/ (1 - $budget);
  1920. }else{
  1921. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) /
  1922. (1 - $budget);
  1923. }
  1924. }
  1925. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1926. $value['specinfo'] = json_decode($value['specinfo'],true);
  1927. $value['bargain_status']=$bidinfo['bargain_status'];
  1928. $data[]=$value;
  1929. }
  1930. return app_show(0,"获取成功",$data);
  1931. }
  1932. public function bragain_list(){
  1933. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1934. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1935. $where=[['bo.is_del',"=",0]];
  1936. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1937. if($bidsNo!=""){
  1938. $where[]=["bo.bidsNo","like","%$bidsNo%"];
  1939. }
  1940. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1941. if ($zxNo !== "") {
  1942. $where[] = ['bo.zxNo','like',"%$zxNo%"];
  1943. }
  1944. $bargainNo = isset($this->post['bargainNo']) && $this->post['bargainNo'] !== "" ? trim($this->post['bargainNo']) : "";
  1945. if ($bargainNo !== "") {
  1946. $where[] = ['bo.bargainNo','like',"%$bargainNo%"];
  1947. }
  1948. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1949. if ($status!== "") {
  1950. $where[] = ['bo.status','=',$status];
  1951. }
  1952. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1953. if ($infoNo !== "") {
  1954. $where[] = ['bo.infoNo','like',"%$infoNo%"];
  1955. }
  1956. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1957. if ($projectNo !== "") {
  1958. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column("zxNo");
  1959. $where[] = ['bo.zxNo','in',$zxlist];
  1960. }
  1961. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1962. if ($pgNo !== "") {
  1963. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1964. $where[] = ['bo.infoNo','in',$bidinfo];
  1965. }
  1966. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  1967. $end= isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  1968. if($start!=""){
  1969. $where[]=["bo.addtime",">=",date("Y-m-d H:i:s",strtotime($start))];
  1970. }
  1971. if($end!=""){
  1972. $where[]=["bo.addtime","<=",date("Y-m-d H:i:s",strtotime($end))];
  1973. }
  1974. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  1975. if ($company_name !== "") $where[] = ["bo.createrid", 'in', get_company_item_user_by_name($company_name)];
  1976. // $role=$this->checkRole();
  1977. // if(!empty($role['write'])){
  1978. // $where[]=["bo.createrid","in",$role['write']];
  1979. // }
  1980. // $role = $this->checkDataShare();
  1981. // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ['bo.createrid', 'in', $role[DataGroupModel::$type_全部]];
  1982. $role = $this->checkDataShare();
  1983. $hand = resign_hand_user($this->uid,0);
  1984. if (!empty($role[DataGroupModel::$type_全部])) {
  1985. $arr= array_unique(array_merge($hand,$role[DataGroupModel::$type_全部]));
  1986. $where[] = ['bo.createrid', 'in',$arr];
  1987. }
  1988. $count=Db::name("bargain_order")
  1989. ->alias('bo')
  1990. ->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")
  1991. ->where($where)
  1992. ->count();
  1993. $total = ceil($count / $size);
  1994. $page = $page >= $total ? $total : $page;
  1995. $list = Db::name('bargain_order')
  1996. ->alias('bo')
  1997. ->field('bo.*,u.itemid')
  1998. ->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")
  1999. ->where($where)
  2000. ->page($page, $size)
  2001. ->order('bo.addtime', 'desc')
  2002. ->cursor();
  2003. $data=[];
  2004. foreach ($list as $value){
  2005. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  2006. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  2007. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  2008. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  2009. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  2010. if($bidinfos['brand_id']!=0){
  2011. $value['brand_id'] = $bidinfos['brand_id'];
  2012. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  2013. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  2014. }else{
  2015. $value["brand_name"]="";
  2016. $value["brand_id"]="";
  2017. }
  2018. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  2019. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  2020. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  2021. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  2022. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  2023. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  2024. $value['budget'] =$budget;
  2025. $god=[
  2026. "metal_id"=>$bidinfos['metal_id'],
  2027. "weight"=>$bidinfos["good_weight"],
  2028. "demo_fee"=>$bidinfos["demo_fee"],
  2029. "delivery_fee"=>$bidinfos["delivery_fee"],
  2030. "open_fee"=>$bidinfos["open_fee"],
  2031. "packing_fee"=>$bidinfos["pakge_fee"],
  2032. "mark_fee"=>$bidinfos["mark_fee"],
  2033. "nake_fee"=>$bidinfos["nake_fee"],
  2034. "cert_fee"=>$bidinfos["cert_fee"],
  2035. "cost_fee"=>$bidinfos["cost_fee"],
  2036. "num"=>$bidinfoe["num"],
  2037. ];
  2038. // if($bidinfos['is_gold_price']==1){
  2039. // $price = GoldPrice($god, $budget/100);
  2040. // }else{
  2041. // $price = GoodPrice($god, $budget/100);
  2042. // }
  2043. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  2044. $value['sale_price'] =round($bidinfos['origin_price'],2);
  2045. $value['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  2046. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  2047. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  2048. //是否具有编辑权限
  2049. $value['is_allow_update'] = 0;
  2050. if (in_array($this->roleid, [1, 33]) || in_array($value['createrid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  2051. $data[]=$value;
  2052. }
  2053. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  2054. }
  2055. public function crontablist(){
  2056. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  2057. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  2058. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  2059. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  2060. if ($zxNo !== "") {
  2061. $where[] = ['a.zxNo','=',$zxNo];
  2062. }
  2063. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  2064. if ($salesman !== "") {
  2065. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  2066. $where[]= ["b.salesman",'like',"%$salesman%"];
  2067. }
  2068. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  2069. if ($cpName !== "") {
  2070. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  2071. $where[]= ["a.good_Name",'like',"%$cpName%"];
  2072. }
  2073. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  2074. if ($khNo !== "") {
  2075. // $where['khNo'] = $khNo;
  2076. $where[]= ["b.khNo",'like',"%$khNo%"];
  2077. }
  2078. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  2079. if ($start !="") {
  2080. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  2081. $where[]= ["a.addtime",'>=',$start];
  2082. }
  2083. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  2084. if($end !=""){
  2085. $where[]= ["a.addtime",'<=',$end];
  2086. }
  2087. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  2088. if ($status !== "") {
  2089. $where[]= ["a.status",'=',$status];
  2090. }
  2091. // $role=$this->checkRole();
  2092. // if(!empty($role['platform']) ){
  2093. // $where[]=["b.platform_code","in",$role['platform']];
  2094. // }
  2095. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  2096. ->count();
  2097. $total = ceil($count / $size);
  2098. $page = $page >= $total ? $total : $page;
  2099. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  2100. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->select();
  2101. $data=[];
  2102. foreach ($list as $value){
  2103. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  2104. $cat =Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  2105. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  2106. $value['original_price']=sprintf("%.2f",$value['budget_price']* (1 -$budget/100));
  2107. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  2108. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  2109. $value['khname']="";
  2110. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  2111. true):[];
  2112. if($value['khNo']!==""){
  2113. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  2114. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  2115. }
  2116. $consult =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"createrid"=>$this->uid,"is_del"=>0])
  2117. ->find();
  2118. $consults =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"is_del"=>0])->find();
  2119. $value['is_feed'] =$consult==false?0:1;
  2120. $value['is_all_feed'] =$consults==false?0:1;
  2121. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  2122. $data[]=$value;
  2123. }
  2124. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  2125. }
  2126. //复制上面的bidlist方法,只更改排序方式
  2127. public function bidlistCopy()
  2128. {
  2129. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  2130. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  2131. $where = [['cb.is_del', "=", 0],['c.status','<>',6]];//不要'取消转单'状态下的数据
  2132. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  2133. if ($zxNo !== "") $where[] = ['cb.zxNo', 'like', '%' . $zxNo . '%'];
  2134. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  2135. if ($infoNo !== "") $where[] = ['cb.infoNo', 'like', '%' . $infoNo . '%'];
  2136. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  2137. if ($bidNo !== "") $where[] = ['cb.bidNo', 'like', '%' . $bidNo . '%'];
  2138. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  2139. if ($pgNo !== "") {
  2140. $bidinfo = Db::name("consult_info")->where([["pgNo", "=", $pgNo], ["is_del", "=", 0]])->column("infoNo");
  2141. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2142. }
  2143. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  2144. if ($bargain_status !== "") {
  2145. $bidinfo = Db::name("consult_info")->where([["bargain_status", "=", $bargain_status], ["is_del", "=", 0]])->column("infoNo");
  2146. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2147. }
  2148. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  2149. if ($projectNo !== "") {
  2150. $zxlist = Db::name("consult_order")->where(["projectNo" => $projectNo, "is_del" => 0, "is_project" => 1])->column("zxNo");
  2151. $where[] = ['cb.zxNo', 'in', $zxlist];
  2152. }
  2153. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  2154. if ($is_own == 1) {
  2155. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  2156. if ($token == "") return error_show(101, 'token不能为空');
  2157. $apply_id = GetUserInfo($token);
  2158. if (empty($apply_id) || $apply_id['code'] != 0) return error_show(1002, "申请人数据不存在");
  2159. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2160. $where[] = ['cb.createrid', "=", $rm];
  2161. }
  2162. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  2163. if ($company_name !== "") $where[] = ["cb.createrid", 'in', get_company_item_user_by_name($company_name)];
  2164. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
  2165. if ($good_name !== "") $where[] = ["cb.good_name", 'like', '%' . $good_name . '%'];
  2166. $supplierName = isset($this->post['supplierName']) && $this->post['supplierName'] !== "" ? trim($this->post['supplierName']) : "";
  2167. if ($supplierName !== "") $where[] = ["s.name", 'like', '%' . $supplierName . '%'];
  2168. $count = Db::name('consult_bids')
  2169. ->alias('cb')
  2170. ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
  2171. ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
  2172. ->leftJoin('supplier s', 's.code=cb.supplierNo')
  2173. ->where($where)
  2174. ->count();
  2175. $total = ceil($count / $size);
  2176. $page = $page >= $total ? $total : $page;
  2177. $list = Db::name('consult_bids')
  2178. ->alias('cb')
  2179. ->field('cb.*,u.itemid,s.name supplierName')
  2180. ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
  2181. ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
  2182. ->leftJoin('supplier s', 's.code=cb.supplierNo')
  2183. ->where($where)
  2184. ->page($page, $size)
  2185. ->order('cb.addtime', 'desc')
  2186. ->cursor();
  2187. $data = [];
  2188. foreach ($list as $value) {
  2189. $catinfo = Db::name("cat")->where(["id" => $value['cat_id']])->find();
  2190. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  2191. $unit = Db::name("unit")->where(["id" => $value['unit_id']])->find();
  2192. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  2193. // $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
  2194. // $value['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  2195. if ($value['brand_id'] != 0) {
  2196. $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
  2197. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  2198. } else {
  2199. $value["brand_name"] = "";
  2200. $value["brand_id"] = "";
  2201. }
  2202. $bidinfo = Db::name("consult_info")->where(["infoNo" => $value["infoNo"]])->find();
  2203. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] : 0;
  2204. $god = [
  2205. "metal_id" => $value['metal_id'],
  2206. "weight" => $value["good_weight"],
  2207. "demo_fee" => $value["demo_fee"],
  2208. "delivery_fee" => $value["delivery_fee"],
  2209. "open_fee" => $value["open_fee"],
  2210. "packing_fee" => $value["pakge_fee"],
  2211. "mark_fee" => $value["mark_fee"],
  2212. "nake_fee" => $value["nake_fee"],
  2213. "cert_fee" => $value["cert_fee"],
  2214. "cost_fee" => $value["sale_cost_fee"]!=$value["origin_cost_fee"] ? $value["sale_cost_fee"] : $value["cost_fee"],
  2215. "num" => $bidinfo["num"],
  2216. ];
  2217. if ($value['is_gold_price'] == 1) {
  2218. $price = GoldPrice($god, $budget / 100);
  2219. $value['sale_price'] = round($price, 2);
  2220. }
  2221. $value['cost_fee'] = $value['origin_cost_fee'];
  2222. $value['specinfo'] = json_decode($value['specinfo'], true);
  2223. $value['metal_name'] = isset($value['metal_id']) && $value['metal_id'] != 0 ? $this->noble[$value['metal_id']] : "";
  2224. $value['bargain_status'] = $bidinfo['bargain_status'];
  2225. //reject驳回原因,status==5表示驳回
  2226. $value['reject'] = [];
  2227. if ($value['status'] >= 5) {
  2228. $value['reject'] = Db::name('bargain_order')
  2229. ->field('id,remark,status')
  2230. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  2231. ->whereIn('status', [3, 8, 11])->order("id desc")
  2232. ->find();
  2233. }
  2234. //产地
  2235. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2236. if ($value['delivery_place'] != "") {
  2237. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['delivery_place']);
  2238. }
  2239. $value['delivery_place_cn'] = GetAddr(json_encode($place));
  2240. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2241. if ($value['origin_place'] != "") {
  2242. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['origin_place']);
  2243. }
  2244. $value['origin_addr'] = GetAddr(json_encode($place));
  2245. // if($value['origin_place']!=''){
  2246. // $code = explode(",",$value['origin_place']);
  2247. // $temp=[];
  2248. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  2249. // $temp['city_code']=isset($code[1])?$code[1]:"";
  2250. // $temp['area_code']=isset($code[2])?$code[2]:"";
  2251. // $addr= GetAddr(json_encode($temp));
  2252. // $value['origin_addr'] = $addr;
  2253. // }
  2254. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  2255. $data[] = $value;
  2256. }
  2257. return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
  2258. }
  2259. }